[compiler] fix: use null instead of GeneratedSource Symbol for synthesized Babel AST node loc#36330
Open
sleitor wants to merge 1 commit intofacebook:mainfrom
Open
[compiler] fix: use null instead of GeneratedSource Symbol for synthesized Babel AST node loc#36330sleitor wants to merge 1 commit intofacebook:mainfrom
sleitor wants to merge 1 commit intofacebook:mainfrom
Conversation
…sized Babel AST node loc
When codegenPlace() produced an identifier for a Place whose loc was
GeneratedSource (the internal Symbol sentinel for "no source location"),
it directly assigned that Symbol to identifier.loc via:
identifier.loc = place.loc as any;
Babel's Node.loc contract requires SourceLocation | null. A Symbol value
violates the contract and causes v8.serialize / jest-worker IPC failures
with "Symbol() could not be cloned" when the compiled AST is passed
across worker boundaries.
All other assignment sites in CodegenReactiveFunction.ts already guard
against GeneratedSource (via the withLoc() helper or explicit checks),
but this one site was unguarded.
Fix: replace the raw assignment with a guarded form that uses null for
synthesized nodes:
identifier.loc = place.loc !== GeneratedSource
? (place.loc as t.SourceLocation)
: null;
Adds a compiler fixture that exercises the triggering pattern (useMemo +
early return + destructuring hoisted across memo scopes).
Fixes facebook#36327
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #36327
babel-plugin-react-compileruses an internal sentinelconst GeneratedSource = Symbol()to represent "no source location" in its HIR. However, one code path incodegenPlace()was directly assigning this Symbol to the.locfield of a synthesized BabelIdentifiernode:Babel's
Node.loccontract requiresSourceLocation | null— aSymbolvalue violates the contract. When the compiled AST is later passed across worker boundaries (jest-worker, Node IPC viaprocess.send, or anyv8.serializepath), Node throws:All other sites in
CodegenReactiveFunction.tsthat write to Babel node.localready guard againstGeneratedSource(via thewithLoc()helper or explicitloc != GeneratedSourcechecks). This one site was the only unguarded escape point.Fix: replace the bare assignment with a guarded form:
How did you test this change?
bug-generated-source-symbol-in-babel-loc) that exercises the triggering pattern:useMemo+ earlyreturn null+ destructuring whose bindings are hoisted across memo scopes, producing synthesized temporaries (_t) withGeneratedSourcelocs. The fixture compiles successfully and the generated identifier nodes now haveloc: nullinstead ofloc: Symbol().yarn workspace babel-plugin-react-compiler lint— no errors.node packages/snap/dist/runner.js) — 1720 Tests, 1720 Passed, 0 Failed.yarn workspace babel-plugin-react-compiler jest— 15 test suites, 43 tests, all passed.