Skip to content

Commit

Permalink
Add record and tuple tokens to eslint parser (#13477)
Browse files Browse the repository at this point in the history
  • Loading branch information
plourenco committed Jun 17, 2021
1 parent 6beccb3 commit d748386
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
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

0 comments on commit d748386

Please sign in to comment.