Skip to content

Commit

Permalink
Convert new tokens in @babel/eslint-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jan 26, 2022
1 parent f607804 commit 91cb4b2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions eslint/babel-eslint-parser/src/convert/convertTokens.cjs
Expand Up @@ -140,6 +140,8 @@ function convertToken(token, source, tl) {
label === tl.bracketHashL ||
label === tl.bracketBarL ||
label === tl.bracketBarR ||
label === tl.doubleCaret ||
label === tl.doubleAt ||
type.isAssign
) {
token.type = "Punctuator";
Expand Down
25 changes: 25 additions & 0 deletions eslint/babel-eslint-parser/test/index.js
Expand Up @@ -691,6 +691,31 @@ describe("Babel and Espree", () => {
expect(babylonAST.tokens[16]).toMatchObject(topicToken);
});

it.each(["^", "%", "^^", "@@"])("pipeline %s topic token", tok => {
const code = `
x |> ${tok}
y |> ${tok}[0]
`;

const babylonAST = parseForESLint(code, {
eslintVisitorKeys: true,
eslintScopeManager: true,
babelOptions: {
filename: "test.js",
parserOpts: {
plugins: [
["pipelineOperator", { proposal: "hack", topicToken: tok }],
],
tokens: true,
},
},
}).ast;

const topicToken = { type: "Punctuator", value: tok };
expect(babylonAST.tokens[2]).toMatchObject(topicToken);
expect(babylonAST.tokens[5]).toMatchObject(topicToken);
});

it("empty program with line comment", () => {
parseAndAssertSame("// single comment");
});
Expand Down

0 comments on commit 91cb4b2

Please sign in to comment.