diff --git a/eslint/babel-eslint-parser/src/convert/convertTokens.cjs b/eslint/babel-eslint-parser/src/convert/convertTokens.cjs index 0e871e0c519d..c1c40e68b313 100644 --- a/eslint/babel-eslint-parser/src/convert/convertTokens.cjs +++ b/eslint/babel-eslint-parser/src/convert/convertTokens.cjs @@ -95,7 +95,11 @@ function convertToken(token, source, tl) { token.range = [token.start, token.end]; if (label === tl.name) { - token.type = "Identifier"; + if (token.value === "static") { + token.type = "Keyword"; + } else { + token.type = "Identifier"; + } } else if ( label === tl.semi || label === tl.comma || diff --git a/eslint/babel-eslint-parser/test/index.js b/eslint/babel-eslint-parser/test/index.js index 093fbc65aefc..8461dfec1e6f 100644 --- a/eslint/babel-eslint-parser/test/index.js +++ b/eslint/babel-eslint-parser/test/index.js @@ -405,6 +405,31 @@ describe("Babel and Espree", () => { }); } + it("static (token)", () => { + const code = ` + import { static as foo } from "foo"; + + class A { + static m() {} + static() {} + } + `; + + parseAndAssertSame(code); + + const babylonAST = parseForESLint(code, { + eslintVisitorKeys: true, + eslintScopeManager: true, + babelOptions: BABEL_OPTIONS, + }).ast; + + const staticKw = { type: "Keyword", value: "static" }; + + expect(babylonAST.tokens[2]).toMatchObject(staticKw); + expect(babylonAST.tokens[12]).toMatchObject(staticKw); + expect(babylonAST.tokens[18]).toMatchObject(staticKw); + }); + it("parse to PropertyDeclaration when `classFeatures: true`", () => { const code = "class A { #x }"; const babylonAST = parseForESLint(code, {