Skip to content

Commit

Permalink
[eslint-parser] Represent static using a Keyword token (#13751)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Sep 13, 2021
1 parent 9780c56 commit 8af57db
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion eslint/babel-eslint-parser/src/convert/convertTokens.cjs
Expand Up @@ -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 ||
Expand Down
25 changes: 25 additions & 0 deletions eslint/babel-eslint-parser/test/index.js
Expand Up @@ -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, {
Expand Down

0 comments on commit 8af57db

Please sign in to comment.