Skip to content

Commit 543eb09

Browse files
authored
[compiler] Wrap inline jsx transform codegen in conditional (#31267)
JSX inlining is a prod-only optimization. We want to enforce this while maintaining the same compiler output in DEV and PROD. Here we add a conditional to the transform that only replaces JSX with object literals outside of DEV. Then a later build step can handle DCE based on the value of `__DEV__`
1 parent 4d577fd commit 543eb09

File tree

6 files changed

+694
-229
lines changed

6 files changed

+694
-229
lines changed

compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const ReactElementSymbolSchema = z.object({
5555
z.literal('react.element'),
5656
z.literal('react.transitional.element'),
5757
]),
58+
globalDevVar: z.string(),
5859
});
5960

6061
export const ExternalFunctionSchema = z.object({

compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,17 @@ export function makeTemporaryIdentifier(
12431243
};
12441244
}
12451245

1246+
export function forkTemporaryIdentifier(
1247+
id: IdentifierId,
1248+
source: Identifier,
1249+
): Identifier {
1250+
return {
1251+
...source,
1252+
mutableRange: {start: makeInstructionId(0), end: makeInstructionId(0)},
1253+
id,
1254+
};
1255+
}
1256+
12461257
/**
12471258
* Creates a valid identifier name. This should *not* be used for synthesizing
12481259
* identifier names: only call this method for identifier names that appear in the

0 commit comments

Comments
 (0)