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

Babylon bug in the experimental nullish coalescing op parsing. #536

Closed
babel-bot opened this issue Nov 6, 2017 · 3 comments
Closed

Babylon bug in the experimental nullish coalescing op parsing. #536

babel-bot opened this issue Nov 6, 2017 · 3 comments

Comments

@babel-bot
Copy link

Original issue submitted by @FyiurAmron in babel/babel#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
@hzoo
Copy link
Member

hzoo commented Jan 8, 2018

#523

@hzoo hzoo closed this as completed Jan 8, 2018
@babakness
Copy link

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?

@samurex
Copy link

samurex commented Jun 5, 2018

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants