1
1
import isExportsOrModuleAssignment from '../utils/isExportsOrModuleAssignment.js' ;
2
2
import resolveExportDeclaration from '../utils/resolveExportDeclaration.js' ;
3
3
import resolveToValue from '../utils/resolveToValue.js' ;
4
- import resolveHOC from '../utils/resolveHOC.js' ;
5
4
import type { NodePath } from '@babel/traverse' ;
6
5
import { visitors } from '@babel/traverse' ;
7
6
import { shallowIgnoreVisitors } from '../utils/traverse.js' ;
@@ -12,9 +11,7 @@ import type {
12
11
} from '@babel/types' ;
13
12
import type FileState from '../FileState.js' ;
14
13
import type { ComponentNodePath , ResolverClass } from './index.js' ;
15
- import resolveComponentDefinition , {
16
- isComponentDefinition ,
17
- } from '../utils/resolveComponentDefinition.js' ;
14
+ import findComponentDefinition from '../utils/findComponentDefinition.js' ;
18
15
import { ERROR_CODES , ReactDocgenError } from '../error.js' ;
19
16
20
17
interface TraverseState {
@@ -26,24 +23,16 @@ function exportDeclaration(
26
23
path : NodePath < ExportDefaultDeclaration | ExportNamedDeclaration > ,
27
24
state : TraverseState ,
28
25
) : 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 ) ;
32
28
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 ) ;
35
33
}
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
- }
42
34
43
- const resolved = resolveComponentDefinition ( definition ) ;
44
-
45
- if ( resolved ) {
46
- state . foundDefinitions . add ( resolved ) ;
35
+ state . foundDefinitions . add ( definition ) ;
47
36
}
48
37
} ) ;
49
38
@@ -61,22 +50,15 @@ function assignmentExpressionVisitor(
61
50
}
62
51
// Resolve the value of the right hand side. It should resolve to a call
63
52
// expression, something like React.createClass
64
- let resolvedPath = resolveToValue ( path . get ( 'right' ) ) ;
53
+ const resolvedPath = resolveToValue ( path . get ( 'right' ) ) ;
54
+ const definition = findComponentDefinition ( resolvedPath ) ;
65
55
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 ) ;
70
60
}
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 ) ;
78
61
79
- if ( definition ) {
80
62
state . foundDefinitions . add ( definition ) ;
81
63
}
82
64
0 commit comments