[react-compiler] Fix GeneratedSource Symbol leaking into output Babel AST loc#36477
Open
MD-Mushfiqur123 wants to merge 1 commit into
Open
[react-compiler] Fix GeneratedSource Symbol leaking into output Babel AST loc#36477MD-Mushfiqur123 wants to merge 1 commit into
MD-Mushfiqur123 wants to merge 1 commit into
Conversation
babel-plugin-react-compiler uses a Symbol() sentinel (GeneratedSource) for synthesized nodes without source locations. In codegenPlace(), the sentinel was being directly assigned to the output Babel AST node's loc field via an unchecked cast. This violates Babel's Node.loc contract (SourceLocation | null) and causes v8.serialize() to throw when downstream tools try to serialize the compiled AST across worker/process boundaries. The fix adds a guard to only set loc when it is not GeneratedSource, matching the existing pattern used by withLoc() and createCallExpression() in the same file.
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
\�abel-plugin-react-compiler\ uses a \Symbol()\ sentinel (\GeneratedSource) for synthesized AST nodes that lack source locations. In \codegenPlace(), this sentinel was being directly assigned to the output Babel AST node's \loc\ field via an unchecked cast (\identifier.loc = place.loc as any).
This violates Babel's \Node.loc\ type contract (\SourceLocation | null) and causes \�8.serialize()\ to throw \Symbol() could not be cloned\ when downstream tools (Metro, Expo, jest-worker, etc.) try to serialize the compiled AST across process/worker boundaries.
Root Cause
In \codegenPlace(), \convertIdentifier()\ correctly skips setting \loc\ when the value is \GeneratedSource\ (via the \withLoc\ wrapper). However, the next line unconditionally overwrites \identifier.loc\ with \place.loc:
\\ ypescript
// Before (broken):
const identifier = convertIdentifier(place.identifier);
identifier.loc = place.loc as any; // leaks Symbol() into output AST
return identifier;
\\
Fix
Added the same guard pattern used by \withLoc()\ and \createCallExpression()\ in the same file:
\\ ypescript
// After (fixed):
const identifier = convertIdentifier(place.identifier);
if (place.loc != null && place.loc !== GeneratedSource) {
identifier.loc = place.loc as any;
}
return identifier;
\\
Test Plan