Babel-eslint: Babylon bug in the experimental nullish coalescing op parsing.

Created on 6 Nov 2017  路  3Comments  路  Source: babel/babel-eslint

Original issue submitted by @FyiurAmron in https://github.com/babel/babel/issues/6750

Nullish is treated like a logical expression (which it IMVHO ain't), crashing the eslint parser while linting (and probably causing screwups in other contexts).

Input Code

var a = b ?? c;

Babel/Babylon Configuration (.babelrc, package.json, cli command)

I used Babylon (edge) via babel-eslint (edge) to lint the code with ?? in it.

Expected Behavior

Nullish is essentially a binary expression, not a logical one. Neither of the operands has to be logical for it to work properly. Strictly speaking, boolean value of 1st operand is mostly not important (w.r.t. most of the falsey states), and is completely ignored for the 2nd.

Current Behavior

Nullish is treated like a logical expression, crashing the parser while linting (and probably causing screwups in other contexts).

Module build failed: Error: unreachable
    at CodePathState.popChoiceContext (/path/node_modules/eslint/lib/code-path-analysis/code-path-state.js:444:23)
    at processCodePathToExit (/path/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:434:19)
    at CodePathAnalyzer.leaveNode (/path/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:623:9)
    at CodePathAnalyzer.overrideLeaveNode (/path/node_modules/eslint-plugin-node/lib/rules/process-exit-as-throw.js:127:27)
    at Traverser.leave (/path/node_modules/eslint/lib/linter.js:958:32)
    at Traverser.__execute (/path/node_modules/estraverse/estraverse.js:397:31)
    at Traverser.traverse (/path/node_modules/estraverse/estraverse.js:491:28)
    at Traverser.traverse (/path/node_modules/eslint/lib/util/traverser.js:31:22)
    at Linter._verifyWithoutProcessors (/path/node_modules/eslint/lib/linter.js:952:19)
    at preprocess.map.textBlock (/path/node_modules/eslint/lib/linter.js:993:35)
    at Array.map (native)
    at Linter.verify (/path/node_modules/eslint/lib/linter.js:992:42)
    at localVerify (/path/node_modules/eslint-plugin-html/src/index.js:107:14)
    at Linter.eslint.verify (/path/node_modules/eslint-plugin-html/src/index.js:147:18)
    at Linter.verifyAndFix (/path/node_modules/eslint/lib/linter.js:1074:29)
    at processText (/path/node_modules/eslint/lib/cli-engine.js:175:32)

Possible Solution

replace the condition in https://github.com/babel/babel/blob/master/packages/babylon/src/parser/expression.js#L317 to be more sane vs nullish, i.e.

        this.finishNode(
          node,
          op === tt.logicalOR ||
          op === tt.logicalAND // || // cut here...
          // op === tt.nullishCoalescing // ... and here
            ? "LogicalExpression"
            : "BinaryExpression",
        );

doing so fixed the problem completely for me.

Context

babel-eslint, eslint

Your Environment

| software | version(s)
| ---------------- | -------
| Babel |
| Babylon | edge
| node |
| npm |
| Operating System |

Most helpful comment

had the same problem when used wrong coalescing operator ?? instead of ||

All 3 comments

This is happening to me, babel-eslint 8.2.3. Nullish coalescing operator crashes eslint when babel-eslint is the parser

@hzoo What does it mean to reference #523?

had the same problem when used wrong coalescing operator ?? instead of ||

Was this page helpful?
0 / 5 - 0 ratings