Add record and tuple tokens to eslint parser (#13477)
This commit is contained in:
parent
6beccb34cb
commit
d74838609e
@ -135,6 +135,12 @@ function convertToken(token, source, tl) {
|
|||||||
label === tl.doubleColon ||
|
label === tl.doubleColon ||
|
||||||
label === tl.hash ||
|
label === tl.hash ||
|
||||||
label === tl.questionDot ||
|
label === tl.questionDot ||
|
||||||
|
label === tl.braceHashL ||
|
||||||
|
label === tl.braceBarL ||
|
||||||
|
label === tl.braceBarR ||
|
||||||
|
label === tl.bracketHashL ||
|
||||||
|
label === tl.bracketBarL ||
|
||||||
|
label === tl.bracketBarR ||
|
||||||
type.isAssign
|
type.isAssign
|
||||||
) {
|
) {
|
||||||
token.type = "Punctuator";
|
token.type = "Punctuator";
|
||||||
|
|||||||
@ -332,6 +332,54 @@ describe("Babel and Espree", () => {
|
|||||||
expect(babylonAST.tokens[1].type).toEqual("Punctuator");
|
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) {
|
if (process.env.BABEL_8_BREAKING) {
|
||||||
it("hash (token)", () => {
|
it("hash (token)", () => {
|
||||||
const code = "class A { #x }";
|
const code = "class A { #x }";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user