If I use ?? anywhere in a file, babel-eslint gives an obscure "unreachable" error and stops working. Removing the Nullish Coalescing from the file brings it back to life.
Using babel-eslint 8.2.3
Same for me
code
const object = {
foo: null,
};
console.log('----------', object.foo ?? 'default');
deps
"devDependencies": {
"@babel/cli": "^7.0.0-beta.46",
"@babel/core": "^7.0.0-beta.46",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0-beta.46",
"babel-eslint": "^8.2.3",
"eslint": "^4.19.1"
}
.babelrc
{
"plugins": ["@babel/plugin-proposal-nullish-coalescing-operator"]
}
.eslintrc
{
"parser": "babel-eslint",
"root": true,
"plugins": [],
"rules": {
"comma-dangle": 2
}
}
I am seeing the same problem. The problem is not linked to VScode, it also happens when running the linter in the command line:
$ eslint --ext .js,.vue src
unreachable
Error: unreachable
at CodePathState.popChoiceContext (…/node_modules/eslint/lib/code-path-analysis/code-path-state.js:444:23)
at processCodePathToExit (…/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:434:19)
at CodePathAnalyzer.leaveNode (…/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:627:9)
at CodePathAnalyzer.overrideLeaveNode (…/node_modules/eslint-plugin-node/lib/rules/process-exit-as-throw.js:130:27)
at Traverser.leave [as _leave] (…/node_modules/eslint/lib/linter.js:868:28)
at Traverser._traverse (…/node_modules/eslint/lib/util/traverser.js:155:18)
at Traverser._traverse (…/node_modules/eslint/lib/util/traverser.js:147:30)
at Traverser._traverse (…/node_modules/eslint/lib/util/traverser.js:144:34)
at Traverser._traverse (…/node_modules/eslint/lib/util/traverser.js:147:30)
at Traverser._traverse (…/node_modules/eslint/lib/util/traverser.js:147:30)
error Command failed with exit code 1.
BTW, if I modify this line:
node_modules/eslint/lib/code-path-analysis/code-path-state.js:444:23: switch (context.kind) {
case "&&":
case "||":
to:
switch (context.kind) {
case "&&":
case "||":
case "??":
then it works.
As a temporary fix, I created a fork with this change and a couple of others to support the nullish-coalescing-operator:
https://github.com/lehni/eslint-nullish-coalescing
https://github.com/lehni/eslint-nullish-coalescing/commit/ab24b4ba4a7daee71ae7bffc2be7f66355803caf
It's available on NPM as eslint-nullish-coalescing:
https://www.npmjs.com/package/eslint-nullish-coalescing
To prevent peerDependency error messages and make it work with VSCode, it's best to install it as an alias to the normal eslint:
yarn add --dev eslint@npm:eslint-nullish-coalescing
Another update:
The VSCode JS grammar package (ms-vscode.typescript-javascript-grammar) struggles with these operators, but both joshpeng.sublime-babel-vscode and ms-vscode.js-atom-grammar appear to work well with it. So a temporary fix is to install one of these packages in VSCode.
@lehni can you please open a pull request from your fork to eslint repo?
@Hypnosphi I didn't do that so far because I was under the impression that this is just a quick fix, not the proper way to go about it... What do you think?
I think the eslint maintainers know better =) And the best way to ask is to send a PR which they will review
What's keeping me from doing so is all the requirements for a PR, see: https://raw.githubusercontent.com/eslint/eslint/master/.github/PULL_REQUEST_TEMPLATE.md
I simply don't have the time for it.
But here's the branch that could be used as a base:
https://github.com/lehni/eslint-nullish-coalescing/tree/nullish-coalescing
The actual changes are tiny:
https://github.com/lehni/eslint-nullish-coalescing/commit/345033232f9f6940c055ef561009c7d1716d3a09
Also, my changes are against the v4.19.1 version, not against master, which is heading towards v5 as we speak.
@lehni Can you please at least sign their CLA so that your changes could be used in my PR?
@Hypnosphi done! thanks for taking your time to do this.
for anyone else running into this issue, I was running an older version of eslint (4.19.1). upgrading to the latest version 6.1.0 unblocked me
Should this issue be closed then?
Is anyone else still having this issue? I've upgraded to 6.1.0 and also tried the latest of 6.4.0. Both get the same 'unreachable' error.
[Error - 9:57:20 am] ESLint stack trace:
[Error - 9:57:20 am] Error: unreachable
at CodePathState.popChoiceContext (./node_modules/eslint/lib/code-path-analysis/code-path-state.js:444:23)
I'm having slightly different issue with the same exact problem. I'm running eslint v6.5.1 and when ?? is used in a file vscode extension reports a crash with different error:
[Error - 6:58:03 PM] TypeError: Cannot read property 'range' of null
@lerayne this looks like an error related to optional chaining operator which I was getting before installing the @babel/plugin-proposal-optional-chaining package. Are you using that package?
Most helpful comment
I'm having slightly different issue with the same exact problem. I'm running eslint v
6.5.1and when??is used in a file vscode extension reports a crash with different error: