File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -25,18 +25,24 @@ module.exports = function(context) {
25
25
return context . options [ 0 ] && context . options [ 0 ] . extensions || DEFAULTS . extensions ;
26
26
}
27
27
28
+ var invalidExtension ;
29
+ var invalidNode ;
30
+
28
31
// --------------------------------------------------------------------------
29
32
// Public
30
33
// --------------------------------------------------------------------------
31
34
32
35
return {
33
-
34
36
JSXElement : function ( node ) {
35
37
var filename = context . getFilename ( ) ;
36
38
if ( filename === '<text>' ) {
37
39
return ;
38
40
}
39
41
42
+ if ( invalidNode ) {
43
+ return ;
44
+ }
45
+
40
46
var allowedExtensions = getExtensionsConfig ( ) ;
41
47
var isAllowedExtension = allowedExtensions . some ( function ( extension ) {
42
48
return filename . slice ( - extension . length ) === extension ;
@@ -46,11 +52,18 @@ module.exports = function(context) {
46
52
return ;
47
53
}
48
54
49
- var extension = path . extname ( filename ) ;
55
+ invalidNode = node ;
56
+ invalidExtension = path . extname ( filename ) ;
57
+ } ,
58
+
59
+ 'Program:exit' : function ( ) {
60
+ if ( ! invalidNode ) {
61
+ return ;
62
+ }
50
63
51
64
context . report ( {
52
- node : node ,
53
- message : 'JSX not allowed in files with extension \'' + extension + '\''
65
+ node : invalidNode ,
66
+ message : 'JSX not allowed in files with extension \'' + invalidExtension + '\''
54
67
} ) ;
55
68
}
56
69
} ;
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ var parserOptions = {
22
22
// Code Snippets
23
23
// ------------------------------------------------------------------------------
24
24
25
- var withJSX = 'module.exports = function MyComponent() { return <div / >; }' ;
25
+ var withJSX = 'module.exports = function MyComponent() { return <div>\n<div />\n</div >; }' ;
26
26
var withoutJSX = 'module.exports = {}' ;
27
27
28
28
// ------------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments