-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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(parser): offset internal index locations by startIndex #16936
fix(parser): offset internal index locations by startIndex #16936
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58269 |
63c4dd3
to
b0825c4
Compare
Don't worry, this seems to be just a bug with the new option rather than a regression? |
@liuxingbaoyu the regression is that this happens even if you pass This is because |
Thanks for noticing the regression and quickly opening a PR :) |
@nicolo-ribaudo I'm happy to help, although this is a bit like the "spider man points at self" meme 😆. One thing to note is that Marko is built on the babel compiler (and uses the All that is to say I need to do something on the Marko side quickly and I'm thinking the simplest thing is to avoid using Do you think this PR is something that could land quickly? I understand if not given lack of tests and such. Sorry to bug you all! |
@liuxingbaoyu I did try to look for all references to In the case of the screenshot it is a non issue since |
b0825c4
to
2c30427
Compare
…y startIndex when reading source code
2c30427
to
e8d74ca
Compare
return; | ||
} | ||
} | ||
|
||
const difference = new Difference( |
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.
Thanks @liuxingbaoyu for working on this test!
Below in the file, when we are fuzzing and using random line/col/index, test.original
will be false and thus the if (!test.original) return
will suppress any error. Should we replace it with
if (!test.original) {
const err = new Error();
err.message = `Test Failed: ${testLocation}\nFixtureError.fromDifference: ${
FixtureError.fromDifference(difference, actual).message
}`;
throw err;
}
import { parse } from "../lib/index.js"; | ||
import { fileURLToPath } from "url"; | ||
|
||
runFixtureTests( |
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.
And no need for this file, we can just use the TEST_FUZZ=true
env var we already have to test these cases.
I think once @liuxingbaoyu's tests are working, if they are passing this PR is good to land. |
Co-authored-by: Nicolò Ribaudo <[email protected]>
curPosition: () => Position; | ||
curPosition: State["curPosition"]; | ||
sourceToOffsetPos: State["sourceToOffsetPos"]; | ||
offsetToSourcePos: State["offsetToSourcePos"]; |
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.
The lookaheadState
should be kept minimal for performance. I guess we didn't call sourceToOffsetPos
or offsetToSourcePos
on a lookahead state, if that is true, then we don't have to include them in the lookahead state.
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.
@JLHwung fyi without this the tests are failing and so it seems necessary with the changes in the PR
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.
Can we move those functions from State to the parser itself maybe?
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.
If we inline sourceToOffsetPos
in curPosition
, the test passes.
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.
I pushed a commit to move them.
actual.ast && | ||
expected.ast && | ||
!actual.ast.errors && | ||
!options.plugins?.includes("estree") && |
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.
This ?. is causing the Node.js 12 failure.
You all are awesome btw ❤️ |
Waiting for a ✔️ by @liuxingbaoyu (or even better, @JLHwung since @liuxingbaoyu wrote half of the code) and then I can release :) |
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 work, thank you.
Releasing now (https://github.com/babel/babel/actions/runs/11526141307) |
#16849 introduced a regression (SORRY!)
The regression is that after the change all
index
properties in node correctly reflect the offset, however many places in the parser use node indexes interchangeably with the current parser index.I have tried to painstakingly review every piece of code in the parser which is directly or indirectly comparing source indexes to an offset index and vice versa and update those locations to map the index accordingly.
The original downstream issue I noticed from this was that the
raw
property on some ast nodes was incorrect since it was slicing the input string based on the node indexes (which are now offset based on startIndex/startColumn).Fixes #1, Fixes #2
Note this probably needs more tests... But I don't have the bandwidth right now.
It may make sense to revert #16849 (although that's somewhat trading one bug for another 😢)