-
Notifications
You must be signed in to change notification settings - Fork 49.9k
[compiler] Fix VariableDeclarator source location #35129
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
base: main
Are you sure you want to change the base?
[compiler] Fix VariableDeclarator source location #35129
Conversation
3de492d to
cd4d9e9
Compare
josephsavona
left a comment
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.
Awesome! One question to see if we can get even more coverage for variable declarations w/o an initial value - see comment - otherwise this looks good to go.
Re the whitespace changes in fixtures: we've seen this pretty consistently as we change source locations. The source location info influences whether Babel's code generator adds a newline or not, and prettier preserves single empty lines between blocks of code. It's fine!
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts
Outdated
Show resolved
Hide resolved
I'm glad you asked.... I ran into some stuff looking through this. These declarations are also missing source locations for the VariableDeclarations. I wasn't tracking that before, but if we're wanting to have as much completeness as possible (rather than just surgically fixing things I care about the most for to fix my issues) we might want to address this. Basically, the declarations hoisted to reactive scopes don't have anywhere for us to track these locations. We only track the location for the identifier. I can fix this by having |
|
Hmm let me look into how onerous that would be |
|
I have a commit where I gave it a go. I can push it to another branch when I'm at my laptop for you to have a gander. |
|
Sounds good! |
069738d to
14ea8dd
Compare
|
@josephsavona see fc833f6 for the changes to the pipeline to address the VariableDeclaration location preservation. note: the changes to -- separately, I pushed a few commits to this PR just adding the change you had requested (had to rebase as well), along with a number of changes to the test fixture + validator, including checking source location for VariableDeclaration & Identifier nodes so that we don't accidentally regress those as we implement other fixes. I think there's a couple of cases where you could accidentally clobber something else trying to find an appropriate place to pass something through, so thought it was worthwhile to add. And I think a more full picture can help guide more "correct" decisions. If you'd like to see it all in action, I can add the commit to this branch (or on a separate tmp branch) with the pipeline changes from the commit I linked above, and in the test fixture we would expect to see the new VariableDeclaration errors removed without any other regressions |
What
Fixes source locations for VariableDeclarator in the generated AST. Fixes a number of the errors in the snapshot I added yesterday in the source loc validator PR #35109
I'm not entirely sure why, but a side effect of the fix has resulted in a ton of snaps needing updating, with some empty lines no longer present in the generated output. I broke the change up into 2 separate commits. The first commit has the core change and the update to the missing source locations test expectation, and the second commit has the rest of the snapshot updates.
How
idand end of theinitcan be used to accurately reconstruct it when generating the AST.