Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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