Add record and tuple tokens to eslint parser (#13477)

This commit is contained in:
Pedro Lourenço 2021-06-17 15:29:32 +01:00 committed by GitHub
parent 6beccb34cb
commit d74838609e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 0 deletions

View File

@ -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";

View File

@ -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 }";