From 99968db2b1485e8ab580523b6d228eccee048cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Fri, 15 Jun 2018 15:42:05 +0100 Subject: [PATCH] Fix token types for experimental operators (babel/babel-eslint#632) * Added failing tests * Recognized nullish coalescing, optional chaining and pipeline operators as Punctuator tokens --- .../lib/babylon-to-espree/toToken.js | 3 ++ .../babel-eslint-parser/test/babel-eslint.js | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/eslint/babel-eslint-parser/lib/babylon-to-espree/toToken.js b/eslint/babel-eslint-parser/lib/babylon-to-espree/toToken.js index 082aef3e32..44c73529a1 100644 --- a/eslint/babel-eslint-parser/lib/babylon-to-espree/toToken.js +++ b/eslint/babel-eslint-parser/lib/babylon-to-espree/toToken.js @@ -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 || diff --git a/eslint/babel-eslint-parser/test/babel-eslint.js b/eslint/babel-eslint-parser/test/babel-eslint.js index c066ed2809..b0a2cd10f2 100644 --- a/eslint/babel-eslint-parser/test/babel-eslint.js +++ b/eslint/babel-eslint-parser/test/babel-eslint.js @@ -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"); });