Skip to content

[react-compiler] Fix GeneratedSource Symbol leaking into output Babel AST loc#36477

Open
MD-Mushfiqur123 wants to merge 1 commit into
facebook:mainfrom
MD-Mushfiqur123:fix/symbol-loc-leak-in-codegen
Open

[react-compiler] Fix GeneratedSource Symbol leaking into output Babel AST loc#36477
MD-Mushfiqur123 wants to merge 1 commit into
facebook:mainfrom
MD-Mushfiqur123:fix/symbol-loc-leak-in-codegen

Conversation

@MD-Mushfiqur123
Copy link
Copy Markdown

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

  • Mirrors the identical guard used in \withLoc()\ (line 1687) and \createCallExpression()\ (line 1801) in the same file
  • The issue provides a minimal standalone repro that can be verified after building

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.
@meta-cla meta-cla Bot added the CLA Signed label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant