diff --git a/core/rehype-docz/src/index.ts b/core/rehype-docz/src/index.ts index 5f4e7916a..ce57e5db8 100644 --- a/core/rehype-docz/src/index.ts +++ b/core/rehype-docz/src/index.ts @@ -3,6 +3,7 @@ import nodeToString from 'hast-util-to-string' import { format } from 'docz-utils/lib/format' import { componentName, sanitizeCode, removeTags } from 'docz-utils/lib/jsx' import { getImportsVariables } from 'docz-utils/lib/imports' +import { getExportsVariables } from 'docz-utils/lib/exports' const isPlayground = (name: string) => { return name === 'Playground' @@ -34,7 +35,13 @@ export interface PluginOpts { export default () => (tree: any) => { const importNodes = tree.children.filter((n: any) => n.type === 'import') - const scopes: string[] = flatten(importNodes.map(getImportsVariables)) + const exportNodes = tree.children.filter((n: any) => n.type === 'export') + const importedScopes = flatten(importNodes.map(getImportsVariables)) + const exportedScopes = flatten(exportNodes.map(getExportsVariables)) + // filter added to avoid throwing if an unexpected type is exported + const scopes: string[] = [...importedScopes, ...exportedScopes].filter( + Boolean + ) const nodes = tree.children .filter((node: any) => node.type === 'jsx') .map(addComponentsProps(scopes))