[eslint-parser] Represent static using a Keyword token (#13751)
This commit is contained in:
parent
9780c5667f
commit
8af57dbfb7
@ -95,7 +95,11 @@ function convertToken(token, source, tl) {
|
|||||||
token.range = [token.start, token.end];
|
token.range = [token.start, token.end];
|
||||||
|
|
||||||
if (label === tl.name) {
|
if (label === tl.name) {
|
||||||
|
if (token.value === "static") {
|
||||||
|
token.type = "Keyword";
|
||||||
|
} else {
|
||||||
token.type = "Identifier";
|
token.type = "Identifier";
|
||||||
|
}
|
||||||
} else if (
|
} else if (
|
||||||
label === tl.semi ||
|
label === tl.semi ||
|
||||||
label === tl.comma ||
|
label === tl.comma ||
|
||||||
|
|||||||
@ -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`", () => {
|
it("parse to PropertyDeclaration when `classFeatures: true`", () => {
|
||||||
const code = "class A { #x }";
|
const code = "class A { #x }";
|
||||||
const babylonAST = parseForESLint(code, {
|
const babylonAST = parseForESLint(code, {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user