[eslint-parser] Represent static using a Keyword token (#13751)

This commit is contained in:
Nicolò Ribaudo 2021-09-13 16:35:32 +02:00 committed by GitHub
parent 9780c5667f
commit 8af57dbfb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -95,7 +95,11 @@ function convertToken(token, source, tl) {
token.range = [token.start, token.end];
if (label === tl.name) {
if (token.value === "static") {
token.type = "Keyword";
} else {
token.type = "Identifier";
}
} else if (
label === tl.semi ||
label === tl.comma ||

View File

@ -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, {