typescript-eslint: [2.5.0-2.6.0] Parsing error: Cannot read property 'parent' of null

Repro: https://github.com/le0nik/typescript-eslint-parsing-repro.

There is a problem with @typescript-eslint/parser when eslint is executed in IDE/Editor(not in CLI) when you create a new file and add an import/export with curly braces anywhere in it. It triggers the following error: Parsing error: Cannot read property 'parent' of null .

Stack trace:

TypeError: Cannot read property 'parent' of null
    at Object.convertComments (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/typescript-estree/dist/convert-comments.js:115:31)
    at Object.astConverter (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/typescript-estree/dist/ast-converter.js:36:46)
    at Object.parseAndGenerateServices (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/typescript-estree/dist/parser.js:295:49)
    at Object.parseForESLint (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/@typescript-eslint/parser/dist/parser.js:55:51)
    at parse (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:643:22)
    at Linter._verifyWithoutProcessors (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1093:33)
    at Linter._verifyWithConfigArray (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1236:21)
    at Linter.verify (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1191:25)
    at Linter.verifyAndFix (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/linter/linter.js:1381:29)
    at verifyText (/Volumes/Workspace/typescript-eslint-parsing-repro/node_modules/eslint/lib/cli-engine/cli-engine.js:231:48)

Affected versions of @typescript-eslint/parser: 2.5.0-2.6.0

Some examples:

import { namedExport } from './util'; // error!!!

const a = {}; // no error, `{}` not in `import/export`

export const foo1 = () => 'foo'; // no error
export const foo2 = () => {}; // error!!!
export const foo3 = () => ({ a: 'b' }); // error!!!
export const foo4 = () => ([ // error!!!
  { a: 'b' }, 
])
export default { c: 'd' }; // error!!!

So in summary:

  • error is only present in IDE, not in CLI
  • error is only present in newly created files, not in files that already existed when project was opened in IDE(or when IDE was launched)
  • error is only present when you add curly braces inside import/export

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 15
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Hmm… If it’s that particular error, it’s existed for a while, it’s dodgy types. I’ve had a WIP PR to fix that particular dodgy type before, but it was for an unrelated error.

I’ll put up a new PR to fix that.

Thanks for helping debug this!!!

#1120 should have fixed the comment parsing code, which I believe was the root cause of this issue.

We have an automated release that runs every monday morning and publishes whatever is in master, so that PR will be pushed out as part of the release today (should be 2.6.1, because there were only fix commits since hte last release).

@bradzacher I don’t know if this is related, but I don’t feel I have enough to make an issue out of it:

I’ve got a weird somewhat related interminte bug that seems to be related to 2.5.0 as well in IntelliJ, reported here.

Heres a recording:

http://recordit.co/8Ku8tC2Kkk

This goes away if I don’t use 2.5.0, but my brains too fried by some recent long work weeks to do my typical deep dive in trying to nail down a reproduction.

I’ve passed this issue on to a member of the WebStorm team, who might have a better shot at reproducing, but also feel free to @ me w/ instructions on how I could get more info for you 😃

I’m on Windows 10.