SIGN IN SIGN UP
facebook / react UNCLAIMED

The library for web and native user interfaces.

0 0 0 JavaScript

[compiler] Fix VariableDeclarator source location (#35129)

### 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 https://github.com/facebook/react/pull/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](https://github.com/facebook/react/pull/35129/commits/f4e4dc0f44a9ef453392ed63e02254f9acc947ec)
has the core change and the update to the missing source locations test
expectation, and the [second
commit](https://github.com/facebook/react/pull/35129/commits/cd4d9e944c5d93bc5125b365764d3039860db33d)
has the rest of the snapshot updates.

### How
- Add location for variable declarators in ast codegen.
- We don't actually have the location preserved in HIR, since when we
lower the declarations we pass through the location for the
VariableDeclaration. Since VariableDeclarator is just a container for
each of the assignments, the start of the `id` and end of the `init` can
be used to accurately reconstruct it when generating the AST.
- Add source locations for object/array patterns for destructuring
assignment source location support
N
Nathan committed
d3eb566291ee5507b3912fe3c0cd6886167fe398
Parent: 37bcdcd
Committed by GitHub <[email protected]> on 12/11/2025, 7:35:03 PM