Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
Fix token types for experimental operators (#632)
Browse files Browse the repository at this point in the history
* Added failing tests

* Recognized nullish coalescing, optional chaining and pipeline operators as Punctuator tokens
  • Loading branch information
rubennorte authored and hzoo committed Jun 15, 2018
1 parent e802577 commit 74a3207
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/babylon-to-espree/toToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ module.exports = function(token, tt, source) {
type === tt.bracketR ||
type === tt.ellipsis ||
type === tt.arrow ||
type === tt.pipeline ||
type === tt.star ||
type === tt.incDec ||
type === tt.colon ||
type === tt.question ||
type === tt.questionDot ||
type === tt.template ||
type === tt.backQuote ||
type === tt.dollarBraceL ||
type === tt.at ||
type === tt.logicalOR ||
type === tt.logicalAND ||
type === tt.nullishCoalescing ||
type === tt.bitwiseOR ||
type === tt.bitwiseXOR ||
type === tt.bitwiseAND ||
Expand Down
30 changes: 30 additions & 0 deletions test/babel-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,36 @@ describe("babylon-to-espree", () => {
parseAndAssertSame("export { foo as bar };");
});

// Espree doesn't support the optional chaining operator yet
it("optional chaining operator (token)", () => {
const code = "foo?.bar";
var babylonAST = babelEslint.parseForESLint(code, {
eslintVisitorKeys: true,
eslintScopeManager: true,
}).ast;
assert.strictEqual(babylonAST.tokens[1].type, "Punctuator");
});

// Espree doesn't support the nullish coalescing operator yet
it("nullish coalescing operator (token)", () => {
const code = "foo ?? bar";
var babylonAST = babelEslint.parseForESLint(code, {
eslintVisitorKeys: true,
eslintScopeManager: true,
}).ast;
assert.strictEqual(babylonAST.tokens[1].type, "Punctuator");
});

// Espree doesn't support the pipeline operator yet
it("pipeline operator (token)", () => {
const code = "foo |> bar";
var babylonAST = babelEslint.parseForESLint(code, {
eslintVisitorKeys: true,
eslintScopeManager: true,
}).ast;
assert.strictEqual(babylonAST.tokens[1].type, "Punctuator");
});

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

0 comments on commit 74a3207

Please sign in to comment.