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) {
2525 return context . options [ 0 ] && context . options [ 0 ] . extensions || DEFAULTS . extensions ;
2626 }
2727
28+ var invalidExtension ;
29+ var invalidNode ;
30+
2831 // --------------------------------------------------------------------------
2932 // Public
3033 // --------------------------------------------------------------------------
3134
3235 return {
33-
3436 JSXElement : function ( node ) {
3537 var filename = context . getFilename ( ) ;
3638 if ( filename === '<text>' ) {
3739 return ;
3840 }
3941
42+ if ( invalidNode ) {
43+ return ;
44+ }
45+
4046 var allowedExtensions = getExtensionsConfig ( ) ;
4147 var isAllowedExtension = allowedExtensions . some ( function ( extension ) {
4248 return filename . slice ( - extension . length ) === extension ;
@@ -46,11 +52,18 @@ module.exports = function(context) {
4652 return ;
4753 }
4854
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+ }
5063
5164 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 + '\''
5467 } ) ;
5568 }
5669 } ;
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ var parserOptions = {
2222// Code Snippets
2323// ------------------------------------------------------------------------------
2424
25- var withJSX = 'module.exports = function MyComponent() { return <div / >; }' ;
25+ var withJSX = 'module.exports = function MyComponent() { return <div>\n<div />\n</div >; }' ;
2626var withoutJSX = 'module.exports = {}' ;
2727
2828// ------------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments