File tree 4 files changed +65
-1
lines changed
fixtures/ignore-jsx-expression-blocks 4 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -79,9 +79,15 @@ export default ({ types: t }: { types: BabelTypes }): Visitor => ({
79
79
}
80
80
81
81
const variable = path . find ( ( node : NodePath ) : NodePath =>
82
- node . isVariableDeclarator ( ) || node . isExportDefaultDeclaration ( ) ,
82
+ node . isVariableDeclarator ( ) || node . isExportDefaultDeclaration ( ) ||
83
+ node . isJSXExpressionContainer ( ) ,
83
84
)
84
85
86
+ // Ignore JSX elements inside JSX expression blocks
87
+ if ( t . isJSXExpressionContainer ( variable ) ) {
88
+ return
89
+ }
90
+
85
91
// Ignore the `if` since I can't come up with a test case to satisfy it.
86
92
/* istanbul ignore if */
87
93
if ( ! variable ) {
Original file line number Diff line number Diff line change @@ -139,6 +139,43 @@ exports.default = Hello;
139
139
Hello .displayName = \' Hello\' ;"
140
140
` ;
141
141
142
+ exports[` ignores jsx expression blocks 1 ` ] = `
143
+ " 'use strict';
144
+
145
+ Object .defineProperty (exports , " __esModule" , {
146
+ value: true
147
+ });
148
+
149
+ var _react = require (' react' );
150
+
151
+ var _react2 = _interopRequireDefault (_react );
152
+
153
+ function _interopRequireDefault(obj ) { return obj && obj .__esModule ? obj : { default : obj }; }
154
+
155
+ var HelloWorld = function HelloWorld() {
156
+ var content = _react2 .default .createElement (
157
+ ' div' ,
158
+ null ,
159
+ [1 , 2 , 3 ].map (function (n ) {
160
+ return _react2 .default .createElement (
161
+ ' h1' ,
162
+ null ,
163
+ n
164
+ );
165
+ })
166
+ );
167
+
168
+ return _react2 .default .createElement (
169
+ ' div' ,
170
+ null ,
171
+ content
172
+ );
173
+ };
174
+
175
+ HelloWorld .displayName = ' HelloWorld' ;
176
+ exports .default = HelloWorld ;"
177
+ `;
178
+
142
179
exports [` ignores when displayName is already set on default export function 1` ] = `
143
180
"\' use strict\' ;
144
181
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+
3
+ const HelloWorld = ( ) => {
4
+ const content = (
5
+ < div >
6
+ {
7
+ [ 1 , 2 , 3 ] . map ( ( n ) => { return < h1 > { n } </ h1 > } )
8
+ }
9
+ </ div >
10
+ )
11
+
12
+ return < div > { content } </ div >
13
+ }
14
+
15
+ export default HelloWorld
Original file line number Diff line number Diff line change @@ -156,3 +156,9 @@ test(
156
156
snapshotMacro ,
157
157
'named-export-block' ,
158
158
)
159
+
160
+ test (
161
+ 'ignores jsx expression blocks' ,
162
+ snapshotMacro ,
163
+ 'ignore-jsx-expression-blocks' ,
164
+ )
You can’t perform that action at this time.
0 commit comments