-
-
Notifications
You must be signed in to change notification settings - Fork 549
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
fix(ast/estree): Better align program span start #10134
fix(ast/estree): Better align program span start #10134
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
CodSpeed Instrumentation Performance ReportMerging #10134 will not alter performanceComparing Summary
|
120c924
to
608ffde
Compare
Hmm. This is really odd! I've delved into it a bit more... Further odditiesAcorn includes comments in the Espree and TS-ESLint also exclude whitespace (line breaks or spaces) from Babel also behaves the same as Acorn (span of the But... Espree also does not include any trailing comments or whitespace at end of the file in Espree is the default parser for ESLint, so TS-ESLint should be aiming to be compatible with it. The fact that TS-ESLint behaves differently for trailing comments/whitespace I think should be considered a bug in TS-ESLint. But... should Espree and TS-ESLint be including comments/whitespace in Comments: Whitespace: What to do?We should raise an issue on TS-ESLint to point out the discrepancy between it and Espree. Personally, I'd like to see To fix our tests in meantime, I think doing what you've done in this PR is probably the best way forward. However, you could also take into account directives. That might pass a few more tests. if let Some(first_directive) = self.directives.first() {
self.span.start = first_directive.span.start;
} else if let Some(first_stmt) = self.body.first() {
self.span.start = first_stmt.span.start;
} As you say, there's likely something else going on the conformance runner, but it'll be easier to figure that out once directives are handled like TS-ESLint does. |
Also, please add a comment where you change the start span as to why this is necessary, and a link to this PR (or one of the TS-ESLint AST explorer links above). |
608ffde
to
74ea52a
Compare
Thanks @overlookmotel for looking into this! Yes odd indeed. I have implemented your suggestions and hopefully my amendment to the comment gives sufficient rationale for the change. |
74ea52a
to
84ca9e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. No new failing tests now!
84ca9e9
to
0b38c8c
Compare
#10134 fixed the start span of `Program` in TS AST to align with TS-ESLint. Change the method this is achieved by - use a custom converter instead of mutating the AST in `to_estree_ts_json` and `to_pretty_estree_ts_json`. This method is more convoluted, but I think it's preferable if serialization does not have side effect of mutating the AST.
I've opened an issue about TS-ESLint's non-alignment with Espree: typescript-eslint/typescript-eslint#11026 |
This PR adjusts the start span of the program node to the first token of the first statement in order to align with TS-EStree serialisation. Previously the program start span was always
0
.The diff removes many mismatches but also adds around 35 new ones. Seem to be mostly related to strict mode directives.
For the mismatches that are added to the snapshot, I wonder if they just happened to not be mismatches because of the fact our Program spans used to always be 0 and the conformance tester incorrectly expected it to also be 0. TS-eslint seems to ignore comments when calculating the Program start span whereas our conformance snapshot cases don't ignore them.
The below code serialises to TS-ESTree with a program start span of
16
(see playground).However our conformance tester works such that we expect start span to be
0
which doesn't line up with the playground example linked. So I think its actually our conformance test parser thats set up wrong for the ~35 mismatches that this PR adds to the snapshot.