File tree Expand file tree Collapse file tree 2 files changed +32
-31
lines changed Expand file tree Collapse file tree 2 files changed +32
-31
lines changed Original file line number Diff line number Diff line change 5
5
'use strict' ;
6
6
7
7
const pragmaUtil = require ( '../util/pragma' ) ;
8
+ const jsxUtil = require ( '../util/jsx' ) ;
8
9
const docsUrl = require ( '../util/docsUrl' ) ;
9
10
10
11
@@ -28,36 +29,6 @@ module.exports = {
28
29
const reactPragma = pragmaUtil . getFromContext ( context ) ;
29
30
const fragmentPragma = pragmaUtil . getFragmentFromContext ( context ) ;
30
31
31
- /**
32
- * Test whether a JSXElement is a fragment
33
- * @param {JSXElement } node
34
- * @returns {boolean }
35
- */
36
- function isFragment ( node ) {
37
- const name = node . openingElement . name ;
38
-
39
- // <Fragment>
40
- if (
41
- name . type === 'JSXIdentifier' &&
42
- name . name === fragmentPragma
43
- ) {
44
- return true ;
45
- }
46
-
47
- // <React.Fragment>
48
- if (
49
- name . type === 'JSXMemberExpression' &&
50
- name . object . type === 'JSXIdentifier' &&
51
- name . object . name === reactPragma &&
52
- name . property . type === 'JSXIdentifier' &&
53
- name . property . name === fragmentPragma
54
- ) {
55
- return true ;
56
- }
57
-
58
- return false ;
59
- }
60
-
61
32
/**
62
33
* Test whether a node is an padding spaces trimmed by react runtime.
63
34
* @param {ASTNode } node
@@ -158,7 +129,7 @@ module.exports = {
158
129
159
130
return {
160
131
JSXElement ( node ) {
161
- if ( isFragment ( node ) ) {
132
+ if ( jsxUtil . isFragment ( node , reactPragma , fragmentPragma ) ) {
162
133
checkNode ( node ) ;
163
134
}
164
135
} ,
Original file line number Diff line number Diff line change @@ -26,6 +26,35 @@ function isDOMComponent(node) {
26
26
return COMPAT_TAG_REGEX . test ( name ) ;
27
27
}
28
28
29
+ /**
30
+ * Test whether a JSXElement is a fragment
31
+ * @param {JSXElement } node
32
+ * @param {string } reactPragma
33
+ * @param {string } fragmentPragma
34
+ * @returns {boolean }
35
+ */
36
+ function isFragment ( node , reactPragma , fragmentPragma ) {
37
+ const name = node . openingElement . name ;
38
+
39
+ // <Fragment>
40
+ if ( name . type === 'JSXIdentifier' && name . name === fragmentPragma ) {
41
+ return true ;
42
+ }
43
+
44
+ // <React.Fragment>
45
+ if (
46
+ name . type === 'JSXMemberExpression' &&
47
+ name . object . type === 'JSXIdentifier' &&
48
+ name . object . name === reactPragma &&
49
+ name . property . type === 'JSXIdentifier' &&
50
+ name . property . name === fragmentPragma
51
+ ) {
52
+ return true ;
53
+ }
54
+
55
+ return false ;
56
+ }
57
+
29
58
/**
30
59
* Checks if a node represents a JSX element or fragment.
31
60
* @param {object } node - node to check.
@@ -37,5 +66,6 @@ function isJSX(node) {
37
66
38
67
module . exports = {
39
68
isDOMComponent,
69
+ isFragment,
40
70
isJSX
41
71
} ;
You can’t perform that action at this time.
0 commit comments