Skip to content

Commit

Permalink
[compiler] Wrap inline jsx transform codegen in conditional (#31267)
Browse files Browse the repository at this point in the history
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__`
  • Loading branch information
jackpope authored Nov 4, 2024
1 parent 4d577fd commit 543eb09
Show file tree
Hide file tree
Showing 6 changed files with 694 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const ReactElementSymbolSchema = z.object({
z.literal('react.element'),
z.literal('react.transitional.element'),
]),
globalDevVar: z.string(),
});

export const ExternalFunctionSchema = z.object({
Expand Down
11 changes: 11 additions & 0 deletions compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,17 @@ export function makeTemporaryIdentifier(
};
}

export function forkTemporaryIdentifier(
id: IdentifierId,
source: Identifier,
): Identifier {
return {
...source,
mutableRange: {start: makeInstructionId(0), end: makeInstructionId(0)},
id,
};
}

/**
* Creates a valid identifier name. This should *not* be used for synthesizing
* identifier names: only call this method for identifier names that appear in the
Expand Down
Loading

0 comments on commit 543eb09

Please sign in to comment.