From 5779ffd01b6925f56778601ff54df4f39289d1c7 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 22 Mar 2018 15:52:40 +0000 Subject: Add assertion to notify any developer trying to render a package with files containing multiple classes --- packages/react-docs/src/utils/typedoc_utils.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'packages/react-docs') diff --git a/packages/react-docs/src/utils/typedoc_utils.ts b/packages/react-docs/src/utils/typedoc_utils.ts index 87b9e44ba..fff27a834 100644 --- a/packages/react-docs/src/utils/typedoc_utils.ts +++ b/packages/react-docs/src/utils/typedoc_utils.ts @@ -85,6 +85,16 @@ export const typeDocUtils = { let entities; let packageComment = ''; // HACK: We assume 1 exported class per file + const numClassChildren = _.reduce( + packageDefinitionWithMergedChildren.children, + (sum: number, child: TypeDocNode) => { + const nextSum = child.kindString === KindString.Class ? sum + 1 : sum; + return nextSum; + }, + ); + if (numClassChildren > 1) { + throw new Error('`react-docs` only supports projects with 1 exported class per file'); + } const isClassExport = packageDefinitionWithMergedChildren.children[0].kindString === KindString.Class; if (isClassExport) { entities = packageDefinitionWithMergedChildren.children[0].children; -- cgit v1.2.3