11import isExportsOrModuleAssignment from '../utils/isExportsOrModuleAssignment.js' ;
22import resolveExportDeclaration from '../utils/resolveExportDeclaration.js' ;
33import resolveToValue from '../utils/resolveToValue.js' ;
4- import resolveHOC from '../utils/resolveHOC.js' ;
54import type { NodePath } from '@babel/traverse' ;
65import { visitors } from '@babel/traverse' ;
76import { shallowIgnoreVisitors } from '../utils/traverse.js' ;
@@ -12,9 +11,7 @@ import type {
1211} from '@babel/types' ;
1312import type FileState from '../FileState.js' ;
1413import type { ComponentNodePath , ResolverClass } from './index.js' ;
15- import resolveComponentDefinition , {
16- isComponentDefinition ,
17- } from '../utils/resolveComponentDefinition.js' ;
14+ import findComponentDefinition from '../utils/findComponentDefinition.js' ;
1815import { ERROR_CODES , ReactDocgenError } from '../error.js' ;
1916
2017interface TraverseState {
@@ -26,24 +23,16 @@ function exportDeclaration(
2623 path : NodePath < ExportDefaultDeclaration | ExportNamedDeclaration > ,
2724 state : TraverseState ,
2825) : void {
29- resolveExportDeclaration ( path ) . forEach ( definition => {
30- if ( ! isComponentDefinition ( definition ) ) {
31- definition = resolveToValue ( resolveHOC ( definition ) ) ;
26+ resolveExportDeclaration ( path ) . forEach ( exportedPath => {
27+ const definition = findComponentDefinition ( exportedPath ) ;
3228
33- if ( ! isComponentDefinition ( definition ) ) {
34- return ;
29+ if ( definition ) {
30+ if ( state . limit > 0 && state . foundDefinitions . size > 0 ) {
31+ // If a file exports multiple components, ... complain!
32+ throw new ReactDocgenError ( ERROR_CODES . MULTIPLE_DEFINITIONS ) ;
3533 }
36- }
37-
38- if ( state . limit > 0 && state . foundDefinitions . size > 0 ) {
39- // If a file exports multiple components, ... complain!
40- throw new ReactDocgenError ( ERROR_CODES . MULTIPLE_DEFINITIONS ) ;
41- }
4234
43- const resolved = resolveComponentDefinition ( definition ) ;
44-
45- if ( resolved ) {
46- state . foundDefinitions . add ( resolved ) ;
35+ state . foundDefinitions . add ( definition ) ;
4736 }
4837 } ) ;
4938
@@ -61,22 +50,15 @@ function assignmentExpressionVisitor(
6150 }
6251 // Resolve the value of the right hand side. It should resolve to a call
6352 // expression, something like React.createClass
64- let resolvedPath = resolveToValue ( path . get ( 'right' ) ) ;
53+ const resolvedPath = resolveToValue ( path . get ( 'right' ) ) ;
54+ const definition = findComponentDefinition ( resolvedPath ) ;
6555
66- if ( ! isComponentDefinition ( resolvedPath ) ) {
67- resolvedPath = resolveToValue ( resolveHOC ( resolvedPath ) ) ;
68- if ( ! isComponentDefinition ( resolvedPath ) ) {
69- return path . skip ( ) ;
56+ if ( definition ) {
57+ if ( state . limit > 0 && state . foundDefinitions . size > 0 ) {
58+ // If a file exports multiple components, ... complain!
59+ throw new ReactDocgenError ( ERROR_CODES . MULTIPLE_DEFINITIONS ) ;
7060 }
71- }
72- if ( state . limit > 0 && state . foundDefinitions . size > 0 ) {
73- // If a file exports multiple components, ... complain!
74- throw new ReactDocgenError ( ERROR_CODES . MULTIPLE_DEFINITIONS ) ;
75- }
76-
77- const definition = resolveComponentDefinition ( resolvedPath ) ;
7861
79- if ( definition ) {
8062 state . foundDefinitions . add ( definition ) ;
8163 }
8264
0 commit comments