Fix token types for experimental operators (babel/babel-eslint#632)

* Added failing tests

* Recognized nullish coalescing, optional chaining and pipeline operators as Punctuator tokens
This commit is contained in:
Rubén Norte 2018-06-15 15:42:05 +01:00
parent 3477626973
commit 99968db2b1
2 changed files with 33 additions and 0 deletions

View File

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

View File

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