-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: Parser: End range of Program
differs from Espree
#11026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It sounds to me like espree is wrong here? |
That is my feeling too. I'll raise an issue on Espree and see what they say. However, at present |
Here is another case: with // single comment In espree: |
This is a great example! The fact that it's not clear what the "right" answer is suggests there's a problem with the mental model. I'd have expected Note: Esprima (which Espree aims to follow) is also Have opened an issue in Espree's repo: eslint/js#648 |
IMO comments are part of the What you guys are probably finding as you work on alignment is that when you look at ranges and tokens things get very messy. The main problem with the ESTree spec is that it solely specifies AST shape and nothing more. So ranges, locs, tokens are all left as an exercise for the parser to guess at. |
Yes, that's exactly what we're finding! Here's another one - the ranges of const template = `abc${x}def${x}ghi`;
// Acorn: ^^^ ^^^ ^^^
// TS-ESLint: ^^^^^^ ^^^^^^ ^^^^^ In my view, Acorn's behavior is correct here. But TS-ESLint's behavior matches Espree, which matches Esprima. The broader question is: Do you feel that TS-ESLint's priority should be to align with Espree? Or, if you feel Espree's behavior is incorrect (as you do with the range of |
I think it's already discussed in espree eslint/js#488 |
When `Program` contains no statements or directives, `Program`'s span start is equal to it's span end in TS-ESLine. At least for now - see typescript-eslint/typescript-eslint#11026.
Before You File a Bug Report Please Confirm You Have Done The Following...
Relevant Package
parser
Playground Link
https://typescript-eslint.io/play/#ts=5.7.2&showAST=es&fileType=.tsx&code=PTAEDMHtIKBgPOJQCMCGAnGQ&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
The end location of
Program
differs between@typescript-eslint/parser
and Espree.Both TS-ESLint and Espree set the start location of
Program
as the first token, excluding whitespace and comments.Espree sets the end location as the last token, also excluding whitespace and comments. However,
@typescript-eslint/parser
does not match that behavior - end location ofProgram
is the end of the file.I assume that
@typescript-eslint/parser
is aiming to align with Espree, and therefore this difference is unintentional.Acorn does not exclude whitespace/comments from either start or end location. It's unfortunate the the 2 most-used ESTree-compatible parsers do not match each others' behavior, and personally I prefer the Acorn way - I think it's surprising that you can have comments which have locations outside the
Program
which contains them. But I imagine quite possible that neither Acorn nor Espree may want to make a breaking change.Examples:
Actual Result
See above.
Additional Info
No response
Versions
@typescript-eslint/parser
8.29.0
The text was updated successfully, but these errors were encountered: