@@ -9,8 +9,33 @@ const NODE_MODULES = '../../node_modules';
99
1010const parsers = {
1111 BABEL_ESLINT : path . join ( __dirname , NODE_MODULES , 'babel-eslint' ) ,
12+ '@BABEL_ESLINT' : path . join ( __dirname , NODE_MODULES , '@babel/eslint-parser' ) ,
1213 TYPESCRIPT_ESLINT : path . join ( __dirname , NODE_MODULES , 'typescript-eslint-parser' ) ,
1314 '@TYPESCRIPT_ESLINT' : path . join ( __dirname , NODE_MODULES , '@typescript-eslint/parser' ) ,
15+ babelParserOptions : function parserOptions ( test , features ) {
16+ return Object . assign ( { } , test . parserOptions , {
17+ requireConfigFile : false ,
18+ babelOptions : {
19+ presets : [
20+ '@babel/preset-react' ,
21+ ] ,
22+ plugins : [
23+ '@babel/plugin-syntax-do-expressions' ,
24+ '@babel/plugin-syntax-function-bind' ,
25+ [ '@babel/plugin-syntax-decorators' , { legacy : true } ] ,
26+ ] ,
27+ } ,
28+ ecmaFeatures : Object . assign (
29+ { } ,
30+ test . parserOptions && test . parserOptions . ecmaFeatures ,
31+ {
32+ jsx : true ,
33+ modules : true ,
34+ legacyDecorators : features . has ( 'decorators' ) ,
35+ }
36+ ) ,
37+ } ) ;
38+ } ,
1439 all : function all ( tests ) {
1540 const t = flatMap ( tests , ( test ) => {
1641 if ( typeof test === 'string' ) {
@@ -25,7 +50,7 @@ const parsers = {
2550 const es = test . parserOptions && test . parserOptions . ecmaVersion ;
2651
2752 function addComment ( testObject , parser ) {
28- const extraComment = `\n// features: [${ Array . from ( features ) . join ( ',' ) } ], parser: ${ parser } ` ;
53+ const extraComment = `\n// features: [${ Array . from ( features ) . join ( ',' ) } ], parser: ${ parser } , parserOptions: ${ testObject . parserOptions } ` ;
2954 return Object . assign (
3055 { } ,
3156 testObject ,
@@ -46,9 +71,16 @@ const parsers = {
4671 || ( features . has ( 'fragment' ) && semver . satisfies ( version , '< 5' ) ) ;
4772
4873 const skipBabel = features . has ( 'no-babel' ) ;
49- const skipTS = semver . satisfies ( version , '< 5' )
74+ const skipOldBabel = skipBabel || semver . satisfies ( version , '>= 8' ) ;
75+ const skipNewBabel = skipBabel
76+ || features . has ( 'no-babel-new' )
77+ || ! semver . satisfies ( version , '^7.5.0' ) // require('@babel/eslint-parser/package.json').peerDependencies.eslint
5078 || features . has ( 'flow' )
79+ || features . has ( 'types' )
80+ || features . has ( 'ts' ) ;
81+ const skipTS = semver . satisfies ( version , '< 5' )
5182 || features . has ( 'no-ts' )
83+ || features . has ( 'flow' )
5284 || features . has ( 'jsx namespace' )
5385 || features . has ( 'bind operator' )
5486 || features . has ( 'do expressions' ) ;
@@ -57,7 +89,11 @@ const parsers = {
5789
5890 return [ ] . concat (
5991 skipBase ? [ ] : addComment ( test , 'default' ) ,
60- skipBabel ? [ ] : addComment ( Object . assign ( { } , test , { parser : parsers . BABEL_ESLINT } ) , 'babel-eslint' ) ,
92+ skipOldBabel ? [ ] : addComment ( Object . assign ( { } , test , { parser : parsers . BABEL_ESLINT } ) , 'babel-eslint' ) ,
93+ skipNewBabel ? [ ] : addComment ( Object . assign ( { } , test , {
94+ parser : parsers [ '@BABEL_ESLINT' ] ,
95+ parserOptions : parsers . babelParserOptions ( test , features ) ,
96+ } ) , '@babel/eslint-parser' ) ,
6197 tsOld ? addComment ( Object . assign ( { } , test , { parser : parsers . TYPESCRIPT_ESLINT } ) , 'typescript-eslint' ) : [ ] ,
6298 tsNew ? addComment ( Object . assign ( { } , test , { parser : parsers [ '@TYPESCRIPT_ESLINT' ] } ) , '@typescript/eslint' ) : [ ]
6399 ) ;
0 commit comments