Skip to content

Commit

Permalink
convert tt.privateName to PrivateIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 4, 2021
1 parent 97e08dc commit 1f65f5e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 2 additions & 0 deletions eslint/babel-eslint-parser/src/convert/convertTokens.js
Expand Up @@ -173,6 +173,8 @@ function convertToken(token, source) {
} else if (type === tt.bigint) {
token.type = "Numeric";
token.value = `${token.value}n`;
} else if (type === tt.privateName) {
token.type = "PrivateIdentifier";
}
if (typeof token.type !== "string") {
// Acorn does not have rightAssociative
Expand Down
35 changes: 24 additions & 11 deletions eslint/babel-eslint-parser/test/index.js
Expand Up @@ -320,17 +320,30 @@ describe("Babel and Espree", () => {
expect(babylonAST.tokens[1].type).toEqual("Punctuator");
});

// Espree doesn't support private fields yet
it("hash (token)", () => {
const code = "class A { #x }";
const babylonAST = parseForESLint(code, {
eslintVisitorKeys: true,
eslintScopeManager: true,
babelOptions: BABEL_OPTIONS,
}).ast;
expect(babylonAST.tokens[3].type).toEqual("Punctuator");
expect(babylonAST.tokens[3].value).toEqual("#");
});
if (process.env.BABEL_8_BREAKING) {
it("hash (token)", () => {
const code = "class A { #x }";
const babylonAST = parseForESLint(code, {
eslintVisitorKeys: true,
eslintScopeManager: true,
babelOptions: BABEL_OPTIONS,
}).ast;
expect(babylonAST.tokens[3].type).toEqual("PrivateIdentifier");
expect(babylonAST.tokens[3].value).toEqual("x");
});
} else {
// Espree doesn't support private fields yet
it("hash (token)", () => {
const code = "class A { #x }";
const babylonAST = parseForESLint(code, {
eslintVisitorKeys: true,
eslintScopeManager: true,
babelOptions: BABEL_OPTIONS,
}).ast;
expect(babylonAST.tokens[3].type).toEqual("Punctuator");
expect(babylonAST.tokens[3].value).toEqual("#");
});
}

it("parse to PropertyDeclaration when `classFeatures: true`", () => {
const code = "class A { #x }";
Expand Down

0 comments on commit 1f65f5e

Please sign in to comment.