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

Add record and tuple tokens to eslint parser #13477

Merged
merged 2 commits into from Jun 17, 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: 6 additions & 0 deletions eslint/babel-eslint-parser/src/convert/convertTokens.cjs
Expand Up @@ -135,6 +135,12 @@ function convertToken(token, source, tl) {
label === tl.doubleColon ||
label === tl.hash ||
label === tl.questionDot ||
label === tl.braceHashL ||
label === tl.braceBarL ||
label === tl.braceBarR ||
label === tl.bracketHashL ||
label === tl.bracketBarL ||
label === tl.bracketBarR ||
type.isAssign
) {
token.type = "Punctuator";
Expand Down
48 changes: 48 additions & 0 deletions eslint/babel-eslint-parser/test/index.js
Expand Up @@ -332,6 +332,54 @@ describe("Babel and Espree", () => {
expect(babylonAST.tokens[1].type).toEqual("Punctuator");
});

it("brace and bracket hash operator (token)", () => {
const code = "#[]; #{}";
const babylonAST = parseForESLint(code, {
eslintVisitorKeys: true,
eslintScopeManager: true,
babelOptions: {
filename: "test.js",
parserOpts: {
plugins: [["recordAndTuple", { syntaxType: "hash" }]],
tokens: true,
},
},
}).ast;
expect(babylonAST.tokens[0]).toEqual(
expect.objectContaining({ type: "Punctuator", value: "#[" }),
);
expect(babylonAST.tokens[3]).toEqual(
expect.objectContaining({ type: "Punctuator", value: "#{" }),
);
});

it("brace and bracket bar operator (token)", () => {
const code = "{||}; [||]";
const babylonAST = parseForESLint(code, {
eslintVisitorKeys: true,
eslintScopeManager: true,
babelOptions: {
filename: "test.js",
parserOpts: {
plugins: [["recordAndTuple", { syntaxType: "bar" }]],
tokens: true,
},
},
}).ast;
expect(babylonAST.tokens[0]).toEqual(
expect.objectContaining({ type: "Punctuator", value: "{|" }),
);
expect(babylonAST.tokens[1]).toEqual(
expect.objectContaining({ type: "Punctuator", value: "|}" }),
);
expect(babylonAST.tokens[3]).toEqual(
expect.objectContaining({ type: "Punctuator", value: "[|" }),
);
expect(babylonAST.tokens[4]).toEqual(
expect.objectContaining({ type: "Punctuator", value: "|]" }),
);
});

if (process.env.BABEL_8_BREAKING) {
it("hash (token)", () => {
const code = "class A { #x }";
Expand Down