@@ -18,12 +18,13 @@ function parseForESLint(code, options) {
1818
1919const ESLINT_VERSION = ESLint . version ;
2020const isESLint7 = ESLINT_VERSION . startsWith ( "7." ) ;
21+ const isESLint8 = ESLINT_VERSION . startsWith ( "8." ) ;
2122const { __dirname : dirname , require } = commonJS ( import . meta. url ) ;
2223
2324// @babel /eslint-parser 8 will drop ESLint 7 support
2425
2526const itESLint7 = isESLint7 && ! process . env . BABEL_8_BREAKING ? it : itDummy ;
26- const itESLint8 = isESLint7 ? itDummy : it ;
27+ const itESLintGte8 = isESLint7 ? itDummy : it ;
2728
2829const BABEL_OPTIONS = {
2930 configFile : path . resolve (
@@ -38,11 +39,14 @@ const PROPS_TO_REMOVE = [
3839 { key : "typeArguments" , type : null } ,
3940 { key : "filename" , type : null } ,
4041 { key : "identifierName" , type : null } ,
41- // espree doesn't support these yet
42+ // For legacy estree AST
43+ { key : "attributes" , type : "ImportExpression" } ,
44+ ] ;
45+ const PROPS_TO_REMOVE_ESLINT_LT_9 = [
46+ // old espree doesn't support these
4247 { key : "attributes" , type : "ImportDeclaration" } ,
4348 { key : "attributes" , type : "ExportNamedDeclaration" } ,
4449 { key : "attributes" , type : "ExportAllDeclaration" } ,
45- { key : "attributes" , type : "ImportExpression" } ,
4650 { key : "options" , type : "ImportExpression" } ,
4751] ;
4852
@@ -108,11 +112,32 @@ describe("Babel and Espree", () => {
108112 ecmaFeatures : babelEcmaFeatures ,
109113 } ) . ast ;
110114
111- deeplyRemoveProperties ( babelAST , PROPS_TO_REMOVE ) ;
112- deeplyRemoveProperties ( espreeAST , [ "offset" ] ) ;
115+ deeplyRemoveProperties ( babelAST , [
116+ ...PROPS_TO_REMOVE ,
117+ ...PROPS_TO_REMOVE_ESLINT_LT_9 ,
118+ ] ) ;
113119 expect ( babelAST ) . toEqual ( espreeAST ) ;
114- } else {
120+ } else if ( isESLint8 ) {
115121 // ESLint 8
122+ const espreeAST = espree . parse ( code , {
123+ ...espreeOptions ,
124+ ecmaVersion : 2024 ,
125+ } ) ;
126+
127+ const babelAST = parseForESLint ( code , {
128+ eslintVisitorKeys : true ,
129+ eslintScopeManager : true ,
130+ babelOptions : BABEL_OPTIONS ,
131+ ecmaFeatures : babelEcmaFeatures ,
132+ } ) . ast ;
133+
134+ deeplyRemoveProperties ( babelAST , [
135+ ...PROPS_TO_REMOVE ,
136+ ...PROPS_TO_REMOVE_ESLINT_LT_9 ,
137+ ] ) ;
138+ expect ( babelAST ) . toEqual ( espreeAST ) ;
139+ } else {
140+ // ESLint 9
116141 const espreeAST = espree . parse ( code , {
117142 ...espreeOptions ,
118143 ecmaVersion : "latest" ,
@@ -126,7 +151,6 @@ describe("Babel and Espree", () => {
126151 } ) . ast ;
127152
128153 deeplyRemoveProperties ( babelAST , PROPS_TO_REMOVE ) ;
129- deeplyRemoveProperties ( espreeAST , [ "offset" ] ) ;
130154 expect ( babelAST ) . toEqual ( espreeAST ) ;
131155 }
132156 }
@@ -453,7 +477,7 @@ describe("Babel and Espree", () => {
453477 expect ( babylonAST . tokens [ 3 ] . value ) . toEqual ( "#" ) ;
454478 } ) ;
455479
456- itESLint8 ( "private identifier (token) - ESLint 8" , ( ) => {
480+ itESLintGte8 ( "private identifier (token) - ESLint 8" , ( ) => {
457481 const code = "class A { #x }" ;
458482 const babylonAST = parseForESLint ( code , {
459483 eslintVisitorKeys : true ,
@@ -506,7 +530,7 @@ describe("Babel and Espree", () => {
506530 expect ( classDeclaration . body . body [ 0 ] . type ) . toEqual ( "PropertyDefinition" ) ;
507531 } ) ;
508532
509- itESLint8 ( "class fields with ESLint 8" , ( ) => {
533+ itESLintGte8 ( "class fields with ESLint 8" , ( ) => {
510534 parseAndAssertSame (
511535 `
512536 class A {
@@ -550,7 +574,7 @@ describe("Babel and Espree", () => {
550574 ) . toMatchObject ( staticKw ) ;
551575 } ) ;
552576
553- itESLint8 ( "static (token) - ESLint 8" , ( ) => {
577+ itESLintGte8 ( "static (token) - ESLint 8" , ( ) => {
554578 const code = `
555579 class A {
556580 static m() {}
@@ -607,7 +631,7 @@ describe("Babel and Espree", () => {
607631 expect ( babylonAST . tokens [ 17 ] ) . toMatchObject ( topicToken ) ;
608632 } ) ;
609633
610- itESLint8 ( "pipeline # topic token - ESLint 8" , ( ) => {
634+ itESLintGte8 ( "pipeline # topic token - ESLint 8" , ( ) => {
611635 const code = `
612636 x |> #
613637 y |> #[0]
0 commit comments