Closed UncleYee closed 5 years ago
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 typescript-estree
should throw a syntax error for this?
@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:
VariableDeclaration
which node.declarations.length
is 0
. (E.g. const;
, var;
)VariableDeclaration
which node.kind
is "const"
and has a member node.declarations[i].init == null
. (E.g. const A;
, the const declaration without that initializer is a syntax error in JS. But TS allows declare const A;
and something like...)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 program.getSyntacticDiagnostics(file);
to get parse errors.
@andy-ms Thanks so much for getting back to me, interestingly that doesn't flag anything for the above case.
getSemanticDiagnostics
does, however, return it as an issue.
program.getSyntacticDiagnostics(file); -> []
program.getSemanticDiagnostics(file); ->
Variable declaration list cannot be empty.
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.0What code were you trying to parse?
What did you expect to happen? no error
What happened? After entering const
eslint issue #11023