-
-
Notifications
You must be signed in to change notification settings - Fork 75
got "TypeError: Cannot read property 'loc' of undefined" after entering 'const' in typescript file in vscode #531
Comments
Hi, thanks for the issue. Sorry to keep passing the buck, but this is actually an issue in https://github.com/JamesHenry/typescript-estree. Do you mind making an issue there, with the expected behavior being that |
@kaicataldo The thing is, typescript-estree is powered by parsing using the TypeScript compiler and then transforming the AST before returning the result. This means ultimately, that the parsing infrastructure is dictated by how the TypeScript compiler behaves. TypeScript is incredibly forgiving during the parsing phase, because a lot of its value comes from its language service architecture which gives feedback on the code, e.g. in your editor. Here you can see the parsing behaviour directly, it has no problem producing an AST for this source: https://astexplorer.net/#/gist/1ceed74d9bdbf7aa7e4c8df7acc53a35/b7879412d61d6280fd76a9c78dd0d62b5368373a Short of performing a second parse step on top of the TypeScript compiler, I'm not sure what we can do about these kinds of situations... Definitely open to suggestions! |
@Andy-MS sorry to ping you here on a repo you haven't worked on, but would you mind giving your thoughts on this? There is no way to get the parser within the tsc to be more strict about syntax errors, right? |
I think we can verify JS syntax errors on around parser.js#L26 and throw it. I see some situations:
There may be others, but I'm not sure. |
Or back to eslint then fix rules to allow those. Because those are syntax error, but, but ESTree spec doesn't forbit those. |
You can use |
@Andy-MS Thanks so much for getting back to me, interestingly that doesn't flag anything for the above case.
program.getSyntacticDiagnostics(file); -> [] program.getSemanticDiagnostics(file); ->
Should I open an issue on the TypeScript repo, I think it should be flagged as a syntax error? |
You could open an issue, though this is hard to change because grammar and semantic checking are coupled currently. |
What version of TypeScript are you using?
v2.9.1
What version of
typescript-eslint-parser
are you using?v16.0.0
What code were you trying to parse?
What did you expect to happen?
no error
What happened?
After entering const
eslint issue #11023
The text was updated successfully, but these errors were encountered: