File tree Expand file tree Collapse file tree 1 file changed +22
-10
lines changed Expand file tree Collapse file tree 1 file changed +22
-10
lines changed Original file line number Diff line number Diff line change
1
+ function isJSXElementOrReactCreateElement ( node ) {
2
+ if ( node . type === 'JSXElement' ) {
3
+ return true ;
4
+ }
5
+ if ( node . callee && node . callee . object && node . callee . object . name === 'React' && node . callee . property && node . callee . property . name === 'createElement' ) {
6
+ return true ;
7
+ }
8
+
9
+ if ( node . callee && node . callee . name === 'createElement' ) {
10
+ return true ;
11
+ }
12
+ return false ;
13
+ }
14
+
1
15
function isReturningJSXElement ( path ) {
2
16
/**
3
17
* Early exit for ArrowFunctionExpressions, there is no ReturnStatement node.
4
18
*/
5
- if ( path . node . init && path . node . init . body && path . node . init . body . type === 'JSXElement' ) {
19
+ if ( path . node . init && path . node . init . body && isJSXElementOrReactCreateElement ( path . node . init . body ) ) {
6
20
return true ;
7
21
}
8
22
@@ -17,16 +31,14 @@ function isReturningJSXElement(path) {
17
31
18
32
const argument = path2 . get ( 'argument' ) ;
19
33
20
- if ( argument . node . type === 'JSXElement' ) {
34
+ if ( isJSXElementOrReactCreateElement ( argument . node ) ) {
21
35
visited = true ;
22
- } else if ( argument . node . type === 'CallExpression' ) {
23
-
24
- const { node } = argument . get ( 'callee' ) ;
25
- if ( node . name === 'createElement' || node . object . name === 'React' && node . property . name === 'createElement' ) {
26
- visited = true ;
27
- }
36
+ return ;
37
+ }
28
38
29
- const binding = path . scope . getBinding ( node . name ) ;
39
+ if ( argument . node . type === 'CallExpression' ) {
40
+ const name = argument . get ( 'callee' ) . node . name ;
41
+ const binding = path . scope . getBinding ( name ) ;
30
42
31
43
if ( ! binding ) {
32
44
return ;
@@ -36,7 +48,7 @@ function isReturningJSXElement(path) {
36
48
visited = true ;
37
49
}
38
50
}
39
- }
51
+ } ,
40
52
} ) ;
41
53
42
54
return visited ;
You can’t perform that action at this time.
0 commit comments