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