Skip to content

Commit 74a3207

Browse files
rubennortehzoo
authored andcommitted
Fix token types for experimental operators (babel#632)
* Added failing tests * Recognized nullish coalescing, optional chaining and pipeline operators as Punctuator tokens
1 parent e802577 commit 74a3207

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/babylon-to-espree/toToken.js

+3
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ module.exports = function(token, tt, source) {
1919
type === tt.bracketR ||
2020
type === tt.ellipsis ||
2121
type === tt.arrow ||
22+
type === tt.pipeline ||
2223
type === tt.star ||
2324
type === tt.incDec ||
2425
type === tt.colon ||
2526
type === tt.question ||
27+
type === tt.questionDot ||
2628
type === tt.template ||
2729
type === tt.backQuote ||
2830
type === tt.dollarBraceL ||
2931
type === tt.at ||
3032
type === tt.logicalOR ||
3133
type === tt.logicalAND ||
34+
type === tt.nullishCoalescing ||
3235
type === tt.bitwiseOR ||
3336
type === tt.bitwiseXOR ||
3437
type === tt.bitwiseAND ||

test/babel-eslint.js

+30
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,36 @@ describe("babylon-to-espree", () => {
256256
parseAndAssertSame("export { foo as bar };");
257257
});
258258

259+
// Espree doesn't support the optional chaining operator yet
260+
it("optional chaining operator (token)", () => {
261+
const code = "foo?.bar";
262+
var babylonAST = babelEslint.parseForESLint(code, {
263+
eslintVisitorKeys: true,
264+
eslintScopeManager: true,
265+
}).ast;
266+
assert.strictEqual(babylonAST.tokens[1].type, "Punctuator");
267+
});
268+
269+
// Espree doesn't support the nullish coalescing operator yet
270+
it("nullish coalescing operator (token)", () => {
271+
const code = "foo ?? bar";
272+
var babylonAST = babelEslint.parseForESLint(code, {
273+
eslintVisitorKeys: true,
274+
eslintScopeManager: true,
275+
}).ast;
276+
assert.strictEqual(babylonAST.tokens[1].type, "Punctuator");
277+
});
278+
279+
// Espree doesn't support the pipeline operator yet
280+
it("pipeline operator (token)", () => {
281+
const code = "foo |> bar";
282+
var babylonAST = babelEslint.parseForESLint(code, {
283+
eslintVisitorKeys: true,
284+
eslintScopeManager: true,
285+
}).ast;
286+
assert.strictEqual(babylonAST.tokens[1].type, "Punctuator");
287+
});
288+
259289
it.skip("empty program with line comment", () => {
260290
parseAndAssertSame("// single comment");
261291
});

0 commit comments

Comments
 (0)