diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts
index 9a59397126cc5..9ca478b742d4c 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts
+++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts
@@ -281,7 +281,7 @@ const EnvironmentConfigSchema = z.object({
* Enable instruction reordering. See InstructionReordering.ts for the details
* of the approach.
*/
- enableInstructionReordering: z.boolean().default(false),
+ enableInstructionReordering: z.boolean().default(true),
/*
* Enables instrumentation codegen. This emits a dev-mode only call to an
diff --git a/compiler/packages/babel-plugin-react-compiler/src/Optimization/InstructionReordering.ts b/compiler/packages/babel-plugin-react-compiler/src/Optimization/InstructionReordering.ts
index d94cfbbf1801c..fdae8392d60bb 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/Optimization/InstructionReordering.ts
+++ b/compiler/packages/babel-plugin-react-compiler/src/Optimization/InstructionReordering.ts
@@ -243,67 +243,131 @@ function reorderBlock(
DEBUG && console.log(`bb${block.id}`);
- // First emit everything that can't be reordered
- if (previous !== null) {
- DEBUG && console.log(`(last non-reorderable instruction)`);
- DEBUG && print(env, locals, shared, seen, previous);
- emit(env, locals, shared, nextInstructions, previous);
- }
- /*
- * For "value" blocks the final instruction represents its value, so we have to be
- * careful to not change the ordering. Emit the last instruction explicitly.
- * Any non-reorderable instructions will get emitted first, and any unused
- * reorderable instructions can be deferred to the shared node list.
+ /**
+ * The ideal order for emitting instructions may change the final instruction,
+ * but value blocks have special semantics for the final instruction of a block -
+ * that's the expression's value!. So we choose between a less optimal strategy
+ * for value blocks which preserves the final instruction order OR a more optimal
+ * ordering for statement-y blocks.
*/
- if (isExpressionBlockKind(block.kind) && block.instructions.length !== 0) {
- DEBUG && console.log(`(block value)`);
- DEBUG &&
- print(
+ if (isExpressionBlockKind(block.kind)) {
+ // First emit everything that can't be reordered
+ if (previous !== null) {
+ DEBUG && console.log(`(last non-reorderable instruction)`);
+ DEBUG && print(env, locals, shared, seen, previous);
+ emit(env, locals, shared, nextInstructions, previous);
+ }
+ /*
+ * For "value" blocks the final instruction represents its value, so we have to be
+ * careful to not change the ordering. Emit the last instruction explicitly.
+ * Any non-reorderable instructions will get emitted first, and any unused
+ * reorderable instructions can be deferred to the shared node list.
+ */
+ if (block.instructions.length !== 0) {
+ DEBUG && console.log(`(block value)`);
+ DEBUG &&
+ print(
+ env,
+ locals,
+ shared,
+ seen,
+ block.instructions.at(-1)!.lvalue.identifier.id
+ );
+ emit(
env,
locals,
shared,
- seen,
+ nextInstructions,
block.instructions.at(-1)!.lvalue.identifier.id
);
- emit(
- env,
- locals,
- shared,
- nextInstructions,
- block.instructions.at(-1)!.lvalue.identifier.id
- );
- }
- /*
- * Then emit the dependencies of the terminal operand. In many cases they will have
- * already been emitted in the previous step and this is a no-op.
- * TODO: sort the dependencies based on weight, like we do for other nodes. Not a big
- * deal though since most terminals have a single operand
- */
- for (const operand of eachTerminalOperand(block.terminal)) {
- DEBUG && console.log(`(terminal operand)`);
- DEBUG && print(env, locals, shared, seen, operand.identifier.id);
- emit(env, locals, shared, nextInstructions, operand.identifier.id);
- }
- // Anything not emitted yet is globally reorderable
- for (const [id, node] of locals) {
- if (node.instruction == null) {
- continue;
}
- CompilerError.invariant(
- node.instruction != null &&
+ /*
+ * Then emit the dependencies of the terminal operand. In many cases they will have
+ * already been emitted in the previous step and this is a no-op.
+ * TODO: sort the dependencies based on weight, like we do for other nodes. Not a big
+ * deal though since most terminals have a single operand
+ */
+ for (const operand of eachTerminalOperand(block.terminal)) {
+ DEBUG && console.log(`(terminal operand)`);
+ DEBUG && print(env, locals, shared, seen, operand.identifier.id);
+ emit(env, locals, shared, nextInstructions, operand.identifier.id);
+ }
+ // Anything not emitted yet is globally reorderable
+ for (const [id, node] of locals) {
+ if (node.instruction == null) {
+ continue;
+ }
+ CompilerError.invariant(
+ node.instruction != null &&
+ getReoderability(node.instruction, references) ===
+ Reorderability.Reorderable,
+ {
+ reason: `Expected all remaining instructions to be reorderable`,
+ loc: node.instruction?.loc ?? block.terminal.loc,
+ description:
+ node.instruction != null
+ ? `Instruction [${node.instruction.id}] was not emitted yet but is not reorderable`
+ : `Lvalue $${id} was not emitted yet but is not reorderable`,
+ }
+ );
+
+ DEBUG && console.log(`save shared: $${id}`);
+ shared.set(id, node);
+ }
+ } else {
+ /**
+ * If this is not a value block, then the order within the block doesn't matter
+ * and we can optimize more. The observation is that blocks often have instructions
+ * such as:
+ *
+ * ```
+ * t$0 = nonreorderable
+ * t$1 = nonreorderable <-- this gets in the way of merging t$0 and t$2
+ * t$2 = reorderable deps[ t$0 ]
+ * return t$2
+ * ```
+ *
+ * Ie where there is some pair of nonreorderable+reorderable values, with some intervening
+ * also non-reorderable instruction. If we emit all non-reorderable instructions first,
+ * then we'll keep the original order. But reordering instructions don't just mean moving
+ * them later: we can also move then _earlier_. By starting from terminal operands, we
+ * end up emitting:
+ *
+ * ```
+ * t$0 = nonreorderable // dep of t$2
+ * t$2 = reorderable deps[ t$0 ]
+ * t$1 = nonreorderable <-- not in the way of merging anymore!
+ * return t$2
+ * ```
+ *
+ * Ie all nonreorderable transitive deps of the terminal operands will get emitted first,
+ * but we'll be able to intersperse the depending reorderable instructions in between
+ * them in a way that works better with scope merging.
+ */
+ for (const operand of eachTerminalOperand(block.terminal)) {
+ DEBUG && console.log(`(terminal operand)`);
+ DEBUG && print(env, locals, shared, seen, operand.identifier.id);
+ emit(env, locals, shared, nextInstructions, operand.identifier.id);
+ }
+ // Anything not emitted yet is globally reorderable
+ for (const id of Array.from(locals.keys()).reverse()) {
+ const node = locals.get(id);
+ if (node === undefined) {
+ continue;
+ }
+ if (
+ node.instruction !== null &&
getReoderability(node.instruction, references) ===
- Reorderability.Reorderable,
- {
- reason: `Expected all remaining instructions to be reorderable`,
- loc: node.instruction?.loc ?? block.terminal.loc,
- description:
- node.instruction != null
- ? `Instruction [${node.instruction.id}] was not emitted yet but is not reorderable`
- : `Lvalue $${id} was not emitted yet but is not reorderable`,
+ Reorderability.Reorderable
+ ) {
+ DEBUG && console.log(`save shared: $${id}`);
+ shared.set(id, node);
+ } else {
+ DEBUG && console.log("leftover");
+ DEBUG && print(env, locals, shared, seen, id);
+ emit(env, locals, shared, nextInstructions, id);
}
- );
- DEBUG && console.log(`save shared: $${id}`);
- shared.set(id, node);
+ }
}
block.instructions = nextInstructions;
@@ -432,7 +496,6 @@ function getReoderability(
range !== undefined &&
range.end === range.start // this LoadLocal is used exactly once
) {
- console.log(`reorderable: ${name.value}`);
return Reorderability.Reorderable;
}
}
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-computed-load.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-computed-load.expect.md
index f76e98b6c3e32..aecb50b8432f6 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-computed-load.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-computed-load.expect.md
@@ -19,19 +19,20 @@ function component(a) {
import { c as _c } from "react/compiler-runtime";
function component(a) {
const $ = _c(2);
- let x;
+ let t0;
if ($[0] !== a) {
- x = { a };
+ const x = { a };
const y = {};
+ t0 = x;
y.x = x.a;
mutate(y);
$[0] = a;
- $[1] = x;
+ $[1] = t0;
} else {
- x = $[1];
+ t0 = $[1];
}
- return x;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-nested-member-path-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-nested-member-path-mutate.expect.md
index f320d630713ec..6a4392ab93587 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-nested-member-path-mutate.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-nested-member-path-mutate.expect.md
@@ -20,19 +20,21 @@ function component() {
import { c as _c } from "react/compiler-runtime";
function component() {
const $ = _c(1);
- let x;
+ let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
const z = [];
const y = {};
y.z = z;
- x = {};
+ const x = {};
x.y = y;
+
+ t0 = x;
mutate(x.y.z);
- $[0] = x;
+ $[0] = t0;
} else {
- x = $[0];
+ t0 = $[0];
}
- return x;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-nested-member-path.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-nested-member-path.expect.md
index 100567a338500..d7a1d0c7aab93 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-nested-member-path.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-nested-member-path.expect.md
@@ -25,18 +25,20 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function component() {
const $ = _c(1);
- let x;
+ let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
const z = [];
const y = {};
y.z = z;
- x = {};
+ const x = {};
+
+ t0 = x;
x.y = y;
- $[0] = x;
+ $[0] = t0;
} else {
- x = $[0];
+ t0 = $[0];
}
- return x;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-within-nested-valueblock-in-array.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-within-nested-valueblock-in-array.expect.md
index 0d1a54af35f40..62be10a822baa 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-within-nested-valueblock-in-array.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-within-nested-valueblock-in-array.expect.md
@@ -52,11 +52,12 @@ import { Stringify, identity, makeArray, mutate } from "shared-runtime";
* handles this correctly.
*/
function Foo(t0) {
- const $ = _c(4);
+ const $ = _c(3);
const { cond1, cond2 } = t0;
- const arr = makeArray({ a: 2 }, 2, []);
let t1;
- if ($[0] !== cond1 || $[1] !== cond2 || $[2] !== arr) {
+ if ($[0] !== cond1 || $[1] !== cond2) {
+ const arr = makeArray({ a: 2 }, 2, []);
+
t1 = cond1 ? (
<>
;
+ const t4 = String(state);
+ let t5;
+ if ($[4] !== t4) {
+ t5 =
{t4}
;
+ $[4] = t4;
$[5] = t5;
- $[6] = t6;
} else {
- t6 = $[6];
+ t5 = $[5];
}
- return t6;
+ return t5;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx-indirect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx-indirect.expect.md
index 539c9e71ec828..a7efcbe0e52d1 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx-indirect.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx-indirect.expect.md
@@ -66,31 +66,31 @@ function Component() {
}
const onClick = t1;
let t2;
- if ($[3] !== ref) {
- t2 = ;
- $[3] = ref;
+ if ($[3] !== onClick) {
+ t2 = ;
+ $[3] = onClick;
$[4] = t2;
} else {
t2 = $[4];
}
let t3;
- if ($[5] !== onClick) {
- t3 = ;
- $[5] = onClick;
+ if ($[5] !== ref) {
+ t3 = ;
+ $[5] = ref;
$[6] = t3;
} else {
t3 = $[6];
}
let t4;
- if ($[7] !== t2 || $[8] !== t3) {
+ if ($[7] !== t3 || $[8] !== t2) {
t4 = (
<>
- {t2}
{t3}
+ {t2}
>
);
- $[7] = t2;
- $[8] = t3;
+ $[7] = t3;
+ $[8] = t2;
$[9] = t4;
} else {
t4 = $[9];
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx.expect.md
index 5a70f6c86eeca..b22897d90fc5d 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-in-callback-passed-to-jsx.expect.md
@@ -51,31 +51,31 @@ function Component() {
}
const onClick = t0;
let t1;
- if ($[1] !== ref) {
- t1 = ;
- $[1] = ref;
+ if ($[1] !== onClick) {
+ t1 = ;
+ $[1] = onClick;
$[2] = t1;
} else {
t1 = $[2];
}
let t2;
- if ($[3] !== onClick) {
- t2 = ;
- $[3] = onClick;
+ if ($[3] !== ref) {
+ t2 = ;
+ $[3] = ref;
$[4] = t2;
} else {
t2 = $[4];
}
let t3;
- if ($[5] !== t1 || $[6] !== t2) {
+ if ($[5] !== t2 || $[6] !== t1) {
t3 = (
<>
- {t1}
{t2}
+ {t1}
>
);
- $[5] = t1;
- $[6] = t2;
+ $[5] = t2;
+ $[6] = t1;
$[7] = t3;
} else {
t3 = $[7];
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-property-in-callback-passed-to-jsx-indirect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-property-in-callback-passed-to-jsx-indirect.expect.md
index 088ad294ef7b8..8feeb2b26d1a1 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-property-in-callback-passed-to-jsx-indirect.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-property-in-callback-passed-to-jsx-indirect.expect.md
@@ -66,31 +66,31 @@ function Component() {
}
const onClick = t1;
let t2;
- if ($[3] !== ref) {
- t2 = ;
- $[3] = ref;
+ if ($[3] !== onClick) {
+ t2 = ;
+ $[3] = onClick;
$[4] = t2;
} else {
t2 = $[4];
}
let t3;
- if ($[5] !== onClick) {
- t3 = ;
- $[5] = onClick;
+ if ($[5] !== ref) {
+ t3 = ;
+ $[5] = ref;
$[6] = t3;
} else {
t3 = $[6];
}
let t4;
- if ($[7] !== t2 || $[8] !== t3) {
+ if ($[7] !== t3 || $[8] !== t2) {
t4 = (
<>
- {t2}
{t3}
+ {t2}
>
);
- $[7] = t2;
- $[8] = t3;
+ $[7] = t3;
+ $[8] = t2;
$[9] = t4;
} else {
t4 = $[9];
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-property-in-callback-passed-to-jsx.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-property-in-callback-passed-to-jsx.expect.md
index f0c115952fa6e..f8bbc11486b43 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-property-in-callback-passed-to-jsx.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-mutating-ref-property-in-callback-passed-to-jsx.expect.md
@@ -51,31 +51,31 @@ function Component() {
}
const onClick = t0;
let t1;
- if ($[1] !== ref) {
- t1 = ;
- $[1] = ref;
+ if ($[1] !== onClick) {
+ t1 = ;
+ $[1] = onClick;
$[2] = t1;
} else {
t1 = $[2];
}
let t2;
- if ($[3] !== onClick) {
- t2 = ;
- $[3] = onClick;
+ if ($[3] !== ref) {
+ t2 = ;
+ $[3] = ref;
$[4] = t2;
} else {
t2 = $[4];
}
let t3;
- if ($[5] !== t1 || $[6] !== t2) {
+ if ($[5] !== t2 || $[6] !== t1) {
t3 = (
<>
- {t1}
{t2}
+ {t1}
>
);
- $[5] = t1;
- $[6] = t2;
+ $[5] = t2;
+ $[6] = t1;
$[7] = t3;
} else {
t3 = $[7];
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-at-mutate-after-capture.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-at-mutate-after-capture.expect.md
index c2ba7336360d6..ee51f3c543cf9 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-at-mutate-after-capture.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-at-mutate-after-capture.expect.md
@@ -22,18 +22,20 @@ import { c as _c } from "react/compiler-runtime"; // x's mutable range should ex
function Component(props) {
const $ = _c(2);
- let x;
+ let t0;
if ($[0] !== props.b) {
- x = [42, {}];
+ const x = [42, {}];
const idx = foo(props.b);
+
+ t0 = x;
const y = x.at(idx);
mutate(y);
$[0] = props.b;
- $[1] = x;
+ $[1] = t0;
} else {
- x = $[1];
+ t0 = $[1];
}
- return x;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-push-effect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-push-effect.expect.md
index 5173d8a6f84f8..c1205dd080e69 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-push-effect.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/array-push-effect.expect.md
@@ -42,25 +42,27 @@ function Component(props) {
t1 = $[3];
}
const y = t1;
- let arr;
+ let t2;
if ($[4] !== x || $[5] !== y) {
- arr = [];
- let t2;
+ const arr = [];
+ let t3;
if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
- t2 = {};
- $[7] = t2;
+ t3 = {};
+ $[7] = t3;
} else {
- t2 = $[7];
+ t3 = $[7];
}
- arr.push(t2);
+ arr.push(t3);
+
+ t2 = arr;
arr.push(x, y);
$[4] = x;
$[5] = y;
- $[6] = arr;
+ $[6] = t2;
} else {
- arr = $[6];
+ t2 = $[6];
}
- return arr;
+ return t2;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-expression-computed.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-expression-computed.expect.md
index e08a77ba515c5..4f3802f0d81f4 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-expression-computed.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-expression-computed.expect.md
@@ -24,18 +24,20 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(2);
- let x;
+ let t0;
if ($[0] !== props.x) {
- x = [props.x];
+ const x = [props.x];
x[0] = x[0] * 2;
+
+ t0 = x;
x["0"] = x["0"] + 3;
$[0] = props.x;
- $[1] = x;
+ $[1] = t0;
} else {
- x = $[1];
+ t0 = $[1];
}
- return x;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-expression-nested-path.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-expression-nested-path.expect.md
index 686da0f671129..0e99d0a87bfd4 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-expression-nested-path.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-expression-nested-path.expect.md
@@ -23,17 +23,19 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function g(props) {
const $ = _c(2);
- let a;
+ let t0;
if ($[0] !== props.c) {
- a = { b: { c: props.c } };
+ const a = { b: { c: props.c } };
a.b.c = a.b.c + 1;
+
+ t0 = a;
a.b.c = a.b.c * 2;
$[0] = props.c;
- $[1] = a;
+ $[1] = t0;
} else {
- a = $[1];
+ t0 = $[1];
}
- return a;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-variations-complex-lvalue-array.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-variations-complex-lvalue-array.expect.md
index 7ea9a069297f6..8bb482f835050 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-variations-complex-lvalue-array.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-variations-complex-lvalue-array.expect.md
@@ -23,16 +23,18 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function foo() {
const $ = _c(1);
- let a;
+ let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
- a = [[1]];
+ const a = [[1]];
+
+ t0 = a;
const first = a.at(0);
first.set(0, 2);
- $[0] = a;
+ $[0] = t0;
} else {
- a = $[0];
+ t0 = $[0];
}
- return a;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-variations-complex-lvalue.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-variations-complex-lvalue.expect.md
index 3c9346340fc7f..c58dc34eb4aad 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-variations-complex-lvalue.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/assignment-variations-complex-lvalue.expect.md
@@ -23,16 +23,18 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function g() {
const $ = _c(1);
- let x;
+ let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
- x = { y: { z: 1 } };
+ const x = { y: { z: 1 } };
x.y.z = x.y.z + 1;
+
+ t0 = x;
x.y.z = x.y.z * 2;
- $[0] = x;
+ $[0] = t0;
} else {
- x = $[0];
+ t0 = $[0];
}
- return x;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/await-side-effecting-promise.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/await-side-effecting-promise.expect.md
index 6996c2cac7f22..0abe8f0df61fe 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/await-side-effecting-promise.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/await-side-effecting-promise.expect.md
@@ -16,16 +16,18 @@ async function Component(props) {
import { c as _c } from "react/compiler-runtime";
async function Component(props) {
const $ = _c(2);
- let x;
+ let t0;
if ($[0] !== props.id) {
- x = [];
+ const x = [];
+
+ t0 = x;
await populateData(props.id, x);
$[0] = props.id;
- $[1] = x;
+ $[1] = t0;
} else {
- x = $[1];
+ t0 = $[1];
}
- return x;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/call-args-assignment.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/call-args-assignment.expect.md
index 6432d24ff091f..9c3ff2acfeb4e 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/call-args-assignment.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/call-args-assignment.expect.md
@@ -16,15 +16,17 @@ function Component(props) {
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(1);
- let x;
+ let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
- x = makeObject();
+ let x = makeObject();
+
+ t0 = x;
x.foo((x = makeObject()));
- $[0] = x;
+ $[0] = t0;
} else {
- x = $[0];
+ t0 = $[0];
}
- return x;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/call-args-destructuring-assignment.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/call-args-destructuring-assignment.expect.md
index e348b5324478b..c7746ec1a8797 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/call-args-destructuring-assignment.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/call-args-destructuring-assignment.expect.md
@@ -16,15 +16,17 @@ function Component(props) {
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(1);
- let x;
+ let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
- x = makeObject();
+ let x = makeObject();
+
+ t0 = x;
x.foo(([x] = makeObject()));
- $[0] = x;
+ $[0] = t0;
} else {
- x = $[0];
+ t0 = $[0];
}
- return x;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capture-indirect-mutate-alias.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capture-indirect-mutate-alias.expect.md
index 8373795ca1818..0a4ae3440a8b2 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capture-indirect-mutate-alias.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capture-indirect-mutate-alias.expect.md
@@ -30,25 +30,25 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function component(a) {
const $ = _c(2);
- let x;
+ let t0;
if ($[0] !== a) {
- x = { a };
+ const x = { a };
+
+ t0 = x;
const f0 = function () {
const q = x;
const f1 = function () {
q.b = 1;
};
-
f1();
};
-
f0();
$[0] = a;
- $[1] = x;
+ $[1] = t0;
} else {
- x = $[1];
+ t0 = $[1];
}
- return x;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capture_mutate-across-fns.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capture_mutate-across-fns.expect.md
index c9c066fef536e..510cb838fbea1 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capture_mutate-across-fns.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capture_mutate-across-fns.expect.md
@@ -28,24 +28,24 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function component(a) {
const $ = _c(2);
- let z;
+ let t0;
if ($[0] !== a) {
- z = { a };
+ const z = { a };
+
+ t0 = z;
const f0 = function () {
const f1 = function () {
z.b = 1;
};
-
f1();
};
-
f0();
$[0] = a;
- $[1] = z;
+ $[1] = t0;
} else {
- z = $[1];
+ t0 = $[1];
}
- return z;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2-iife.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2-iife.expect.md
index b201c8ec5b210..bd53012d7c73b 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2-iife.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2-iife.expect.md
@@ -31,23 +31,24 @@ import { mutate } from "shared-runtime";
function component(foo, bar) {
const $ = _c(3);
- let x;
+ let t0;
if ($[0] !== foo || $[1] !== bar) {
- x = { foo };
+ const x = { foo };
const y = { bar };
const a = { y };
const b = x;
a.x = b;
+ t0 = x;
mutate(y);
$[0] = foo;
$[1] = bar;
- $[2] = x;
+ $[2] = t0;
} else {
- x = $[2];
+ t0 = $[2];
}
- return x;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2.expect.md
index e4eac820649cb..e7e88e6fad090 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2.expect.md
@@ -23,25 +23,26 @@ function component(foo, bar) {
import { c as _c } from "react/compiler-runtime";
function component(foo, bar) {
const $ = _c(3);
- let x;
+ let t0;
if ($[0] !== foo || $[1] !== bar) {
- x = { foo };
+ const x = { foo };
const y = { bar };
+
+ t0 = x;
const f0 = function () {
const a = { y };
const b = x;
a.x = b;
};
-
f0();
mutate(y);
$[0] = foo;
$[1] = bar;
- $[2] = x;
+ $[2] = t0;
} else {
- x = $[2];
+ t0 = $[2];
}
- return x;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2-iife.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2-iife.expect.md
index d8f889aaf44eb..889c3afc462b2 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2-iife.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2-iife.expect.md
@@ -31,23 +31,24 @@ const { mutate } = require("shared-runtime");
function component(foo, bar) {
const $ = _c(3);
- let x;
+ let t0;
if ($[0] !== foo || $[1] !== bar) {
- x = { foo };
+ const x = { foo };
const y = { bar };
const a = [y];
const b = x;
a.x = b;
+ t0 = x;
mutate(y);
$[0] = foo;
$[1] = bar;
- $[2] = x;
+ $[2] = t0;
} else {
- x = $[2];
+ t0 = $[2];
}
- return x;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2.expect.md
index a912853a91202..c61c6ace2f4e2 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2.expect.md
@@ -23,25 +23,26 @@ function component(foo, bar) {
import { c as _c } from "react/compiler-runtime";
function component(foo, bar) {
const $ = _c(3);
- let x;
+ let t0;
if ($[0] !== foo || $[1] !== bar) {
- x = { foo };
+ const x = { foo };
const y = { bar };
+
+ t0 = x;
const f0 = function () {
const a = [y];
const b = x;
a.x = b;
};
-
f0();
mutate(y);
$[0] = foo;
$[1] = bar;
- $[2] = x;
+ $[2] = t0;
} else {
- x = $[2];
+ t0 = $[2];
}
- return x;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr-iife.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr-iife.expect.md
index d3fd9e16eadf8..2a0f8050fd74a 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr-iife.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr-iife.expect.md
@@ -31,23 +31,24 @@ const { mutate } = require("shared-runtime");
function component(foo, bar) {
const $ = _c(3);
- let y;
+ let t0;
if ($[0] !== foo || $[1] !== bar) {
const x = { foo };
- y = { bar };
+ const y = { bar };
const a = [y];
const b = x;
a.x = b;
+ t0 = y;
mutate(y);
$[0] = foo;
$[1] = bar;
- $[2] = y;
+ $[2] = t0;
} else {
- y = $[2];
+ t0 = $[2];
}
- return y;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr.expect.md
index 13dcc589a638c..9ca686ade149a 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr.expect.md
@@ -23,10 +23,10 @@ function component(foo, bar) {
import { c as _c } from "react/compiler-runtime";
function component(foo, bar) {
const $ = _c(3);
- let y;
+ let t0;
if ($[0] !== foo || $[1] !== bar) {
const x = { foo };
- y = { bar };
+ const y = { bar };
const f0 = function () {
const a = [y];
const b = x;
@@ -34,14 +34,16 @@ function component(foo, bar) {
};
f0();
+
+ t0 = y;
mutate(y);
$[0] = foo;
$[1] = bar;
- $[2] = y;
+ $[2] = t0;
} else {
- y = $[2];
+ t0 = $[2];
}
- return y;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-iife.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-iife.expect.md
index 4b8a5857f8507..91c611107b6a9 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-iife.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-iife.expect.md
@@ -31,23 +31,24 @@ const { mutate } = require("shared-runtime");
function component(foo, bar) {
const $ = _c(3);
- let y;
+ let t0;
if ($[0] !== foo || $[1] !== bar) {
const x = { foo };
- y = { bar };
+ const y = { bar };
const a = { y };
const b = x;
a.x = b;
+ t0 = y;
mutate(y);
$[0] = foo;
$[1] = bar;
- $[2] = y;
+ $[2] = t0;
} else {
- y = $[2];
+ t0 = $[2];
}
- return y;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md
index cb6d0d6e6ad31..b956b9aea1e20 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md
@@ -23,10 +23,10 @@ function component(foo, bar) {
import { c as _c } from "react/compiler-runtime";
function component(foo, bar) {
const $ = _c(3);
- let y;
+ let t0;
if ($[0] !== foo || $[1] !== bar) {
const x = { foo };
- y = { bar };
+ const y = { bar };
const f0 = function () {
const a = { y };
const b = x;
@@ -34,14 +34,16 @@ function component(foo, bar) {
};
f0();
+
+ t0 = y;
mutate(y);
$[0] = foo;
$[1] = bar;
- $[2] = y;
+ $[2] = t0;
} else {
- y = $[2];
+ t0 = $[2];
}
- return y;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate-iife.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate-iife.expect.md
index 7a1405611ab87..d4270e76237e9 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate-iife.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate-iife.expect.md
@@ -29,20 +29,21 @@ const { mutate } = require("shared-runtime");
function component(a) {
const $ = _c(2);
- let y;
+ let t0;
if ($[0] !== a) {
const x = { a };
- y = {};
+ const y = {};
y.x = x;
+ t0 = y;
mutate(y);
$[0] = a;
- $[1] = y;
+ $[1] = t0;
} else {
- y = $[1];
+ t0 = $[1];
}
- return y;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate.expect.md
index b96fcb590c66f..bc3443d3e92d9 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate.expect.md
@@ -21,22 +21,24 @@ function component(a) {
import { c as _c } from "react/compiler-runtime";
function component(a) {
const $ = _c(2);
- let y;
+ let t0;
if ($[0] !== a) {
const x = { a };
- y = {};
+ const y = {};
const f0 = function () {
y.x = x;
};
f0();
+
+ t0 = y;
mutate(y);
$[0] = a;
- $[1] = y;
+ $[1] = t0;
} else {
- y = $[1];
+ t0 = $[1];
}
- return y;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-mutate-iife.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-mutate-iife.expect.md
index e5e1f886888f6..dd289113bb9a8 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-mutate-iife.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-mutate-iife.expect.md
@@ -29,20 +29,21 @@ const { mutate } = require("shared-runtime");
function component(a) {
const $ = _c(2);
- let y;
+ let t0;
if ($[0] !== a) {
const x = { a };
- y = {};
+ const y = {};
y.x = x;
+ t0 = y;
mutate(y);
$[0] = a;
- $[1] = y;
+ $[1] = t0;
} else {
- y = $[1];
+ t0 = $[1];
}
- return y;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-mutate.expect.md
index 4f3ec26a558fc..7ed3d73685b28 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-mutate.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-mutate.expect.md
@@ -21,22 +21,24 @@ function component(a) {
import { c as _c } from "react/compiler-runtime";
function component(a) {
const $ = _c(2);
- let y;
+ let t0;
if ($[0] !== a) {
const x = { a };
- y = {};
+ const y = {};
const f0 = function () {
y.x = x;
};
f0();
+
+ t0 = y;
mutate(y);
$[0] = a;
- $[1] = y;
+ $[1] = t0;
} else {
- y = $[1];
+ t0 = $[1];
}
- return y;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate-iife.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate-iife.expect.md
index c285e3cfce6cd..6e0b8ecece974 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate-iife.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate-iife.expect.md
@@ -30,21 +30,22 @@ import { mutate } from "shared-runtime";
function component(a) {
const $ = _c(2);
- let y;
+ let t0;
if ($[0] !== a) {
const x = { a };
- y = {};
+ const y = {};
const a_0 = y;
a_0.x = x;
+ t0 = y;
mutate(y);
$[0] = a;
- $[1] = y;
+ $[1] = t0;
} else {
- y = $[1];
+ t0 = $[1];
}
- return y;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate.expect.md
index e9bd3e4e0c306..b384a7fdd0df0 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate.expect.md
@@ -22,23 +22,25 @@ function component(a) {
import { c as _c } from "react/compiler-runtime";
function component(a) {
const $ = _c(2);
- let y;
+ let t0;
if ($[0] !== a) {
const x = { a };
- y = {};
+ const y = {};
const f0 = function () {
const a_0 = y;
a_0.x = x;
};
f0();
+
+ t0 = y;
mutate(y);
$[0] = a;
- $[1] = y;
+ $[1] = t0;
} else {
- y = $[1];
+ t0 = $[1];
}
- return y;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate-iife.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate-iife.expect.md
index 5c19fc6dcb71d..3a17980746a2b 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate-iife.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate-iife.expect.md
@@ -30,21 +30,22 @@ const { mutate } = require("shared-runtime");
function component(a) {
const $ = _c(2);
- let y;
+ let t0;
if ($[0] !== a) {
const x = { a };
- y = {};
+ const y = {};
const a_0 = y;
a_0.x = x;
+ t0 = y;
mutate(y);
$[0] = a;
- $[1] = y;
+ $[1] = t0;
} else {
- y = $[1];
+ t0 = $[1];
}
- return y;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate.expect.md
index c4cf99c1e22ff..9843a2c5e3b17 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate.expect.md
@@ -22,23 +22,25 @@ function component(a) {
import { c as _c } from "react/compiler-runtime";
function component(a) {
const $ = _c(2);
- let y;
+ let t0;
if ($[0] !== a) {
const x = { a };
- y = {};
+ const y = {};
const f0 = function () {
const a_0 = y;
a_0.x = x;
};
f0();
+
+ t0 = y;
mutate(y);
$[0] = a;
- $[1] = y;
+ $[1] = t0;
} else {
- y = $[1];
+ t0 = $[1];
}
- return y;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate-2.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate-2.expect.md
index 146c6292cabe5..483440897bc20 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate-2.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate-2.expect.md
@@ -36,21 +36,22 @@ function component(a, b) {
t0 = $[1];
}
const y = t0;
- let z;
+ let t1;
if ($[2] !== a || $[3] !== y.b) {
- z = { a };
+ const z = { a };
+
+ t1 = z;
const x = function () {
z.a = 2;
};
-
x();
$[2] = a;
$[3] = y.b;
- $[4] = z;
+ $[4] = t1;
} else {
- z = $[4];
+ t1 = $[4];
}
- return z;
+ return t1;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate-nested.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate-nested.expect.md
index 7d0edb1a3bc12..3b9acc7c2c9ae 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate-nested.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate-nested.expect.md
@@ -25,20 +25,21 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function component(a) {
const $ = _c(2);
- let y;
+ let t0;
if ($[0] !== a) {
- y = { b: { a } };
+ const y = { b: { a } };
+
+ t0 = y;
const x = function () {
y.b.a = 2;
};
-
x();
$[0] = a;
- $[1] = y;
+ $[1] = t0;
} else {
- y = $[1];
+ t0 = $[1];
}
- return y;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md
index 5b48ec9070c96..a657b26d81675 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md
@@ -27,23 +27,24 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function component(a, b) {
const $ = _c(3);
- let z;
+ let t0;
if ($[0] !== a || $[1] !== b) {
- z = { a };
+ const z = { a };
const y = { b };
+
+ t0 = z;
const x = function () {
z.a = 2;
console.log(y.b);
};
-
x();
$[0] = a;
$[1] = b;
- $[2] = z;
+ $[2] = t0;
} else {
- z = $[2];
+ t0 = $[2];
}
- return z;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-function-decl.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-function-decl.expect.md
index 143ffa5bf91dd..e6bec19d70d5b 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-function-decl.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-function-decl.expect.md
@@ -25,20 +25,21 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function component(a) {
const $ = _c(2);
- let t;
+ let t0;
if ($[0] !== a) {
- t = { a };
+ const t = { a };
const x = function x() {
t.foo();
};
+ t0 = t;
x(t);
$[0] = a;
- $[1] = t;
+ $[1] = t0;
} else {
- t = $[1];
+ t0 = $[1];
}
- return t;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/chained-assignment-expressions.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/chained-assignment-expressions.expect.md
index 5cd4f5238723a..b5e53d0640bba 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/chained-assignment-expressions.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/chained-assignment-expressions.expect.md
@@ -25,18 +25,20 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function foo() {
const $ = _c(1);
- let z;
+ let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
const x = { x: 0 };
const y = { z: 0 };
- z = { z: 0 };
+ const z = { z: 0 };
x.x = x.x + (y.y = y.y * 1);
+
+ t0 = z;
z.z = z.z + (y.y = y.y * (x.x = x.x & 3));
- $[0] = z;
+ $[0] = t0;
} else {
- z = $[0];
+ t0 = $[0];
}
- return z;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-emit-make-read-only.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-emit-make-read-only.expect.md
index ba9e39e691b0e..6802c187a8491 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-emit-make-read-only.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-emit-make-read-only.expect.md
@@ -24,21 +24,23 @@ import { c as _c } from "react/compiler-runtime"; // @enableEmitFreeze true
function MyComponentName(props) {
const $ = _c(3);
- let y;
+ let t0;
if ($[0] !== props.a || $[1] !== props.b) {
const x = {};
foo(x, props.a);
foo(x, props.b);
- y = [];
+ const y = [];
+
+ t0 = y;
y.push(x);
$[0] = props.a;
$[1] = props.b;
- $[2] = __DEV__ ? makeReadOnly(y, "MyComponentName") : y;
+ $[2] = __DEV__ ? makeReadOnly(t0, "MyComponentName") : t0;
} else {
- y = $[2];
+ t0 = $[2];
}
- return y;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/computed-call-evaluation-order.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/computed-call-evaluation-order.expect.md
index 76bdcf1efe4ad..5b6c930395ea0 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/computed-call-evaluation-order.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/computed-call-evaluation-order.expect.md
@@ -41,18 +41,19 @@ function Component() {
t0 = $[0];
}
const changeF = t0;
- let x;
+ let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
- x = { f: () => console.log("original") };
+ const x = { f: () => console.log("original") };
+ t1 = x;
(console.log("A"), x)[(console.log("B"), "f")](
(changeF(x), console.log("arg"), 1),
);
- $[1] = x;
+ $[1] = t1;
} else {
- x = $[1];
+ t1 = $[1];
}
- return x;
+ return t1;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/computed-store-alias.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/computed-store-alias.expect.md
index f08c01f728acd..8f40edbf90e0a 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/computed-store-alias.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/computed-store-alias.expect.md
@@ -18,19 +18,21 @@ function component(a, b) {
import { c as _c } from "react/compiler-runtime";
function component(a, b) {
const $ = _c(3);
- let x;
+ let t0;
if ($[0] !== a || $[1] !== b) {
const y = { a };
- x = { b };
+ const x = { b };
x.y = y;
+
+ t0 = x;
mutate(x);
$[0] = a;
$[1] = b;
- $[2] = x;
+ $[2] = t0;
} else {
- x = $[2];
+ t0 = $[2];
}
- return x;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/conditional-break-labeled.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/conditional-break-labeled.expect.md
index 2c6b373f0c45c..e4271a2eda699 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/conditional-break-labeled.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/conditional-break-labeled.expect.md
@@ -34,9 +34,9 @@ import { c as _c } from "react/compiler-runtime"; /**
*/
function Component(props) {
const $ = _c(2);
- let a;
+ let t0;
if ($[0] !== props) {
- a = [];
+ const a = [];
a.push(props.a);
bb0: {
if (props.b) {
@@ -46,13 +46,14 @@ function Component(props) {
a.push(props.c);
}
+ t0 = a;
a.push(props.d);
$[0] = props;
- $[1] = a;
+ $[1] = t0;
} else {
- a = $[1];
+ t0 = $[1];
}
- return a;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/conditional-early-return.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/conditional-early-return.expect.md
index 04012db573309..2628c67b891b7 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/conditional-early-return.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/conditional-early-return.expect.md
@@ -71,31 +71,32 @@ import { c as _c } from "react/compiler-runtime"; /**
*/
function ComponentA(props) {
const $ = _c(3);
- let a_DEBUG;
let t0;
+ let t1;
if ($[0] !== props) {
- t0 = Symbol.for("react.early_return_sentinel");
+ t1 = Symbol.for("react.early_return_sentinel");
bb0: {
- a_DEBUG = [];
+ const a_DEBUG = [];
a_DEBUG.push(props.a);
if (props.b) {
- t0 = null;
+ t1 = null;
break bb0;
}
+ t0 = a_DEBUG;
a_DEBUG.push(props.d);
}
$[0] = props;
- $[1] = a_DEBUG;
- $[2] = t0;
+ $[1] = t0;
+ $[2] = t1;
} else {
- a_DEBUG = $[1];
- t0 = $[2];
+ t0 = $[1];
+ t1 = $[2];
}
- if (t0 !== Symbol.for("react.early_return_sentinel")) {
- return t0;
+ if (t1 !== Symbol.for("react.early_return_sentinel")) {
+ return t1;
}
- return a_DEBUG;
+ return t0;
}
/**
@@ -103,21 +104,22 @@ function ComponentA(props) {
*/
function ComponentB(props) {
const $ = _c(2);
- let a;
+ let t0;
if ($[0] !== props) {
- a = [];
+ const a = [];
a.push(props.a);
if (props.b) {
a.push(props.c);
}
+ t0 = a;
a.push(props.d);
$[0] = props;
- $[1] = a;
+ $[1] = t0;
} else {
- a = $[1];
+ t0 = $[1];
}
- return a;
+ return t0;
}
/**
@@ -125,32 +127,33 @@ function ComponentB(props) {
*/
function ComponentC(props) {
const $ = _c(3);
- let a;
let t0;
+ let t1;
if ($[0] !== props) {
- t0 = Symbol.for("react.early_return_sentinel");
+ t1 = Symbol.for("react.early_return_sentinel");
bb0: {
- a = [];
+ const a = [];
a.push(props.a);
if (props.b) {
a.push(props.c);
- t0 = null;
+ t1 = null;
break bb0;
}
+ t0 = a;
a.push(props.d);
}
$[0] = props;
- $[1] = a;
- $[2] = t0;
+ $[1] = t0;
+ $[2] = t1;
} else {
- a = $[1];
- t0 = $[2];
+ t0 = $[1];
+ t1 = $[2];
}
- if (t0 !== Symbol.for("react.early_return_sentinel")) {
- return t0;
+ if (t1 !== Symbol.for("react.early_return_sentinel")) {
+ return t1;
}
- return a;
+ return t0;
}
/**
@@ -158,32 +161,33 @@ function ComponentC(props) {
*/
function ComponentD(props) {
const $ = _c(3);
- let a;
let t0;
+ let t1;
if ($[0] !== props) {
- t0 = Symbol.for("react.early_return_sentinel");
+ t1 = Symbol.for("react.early_return_sentinel");
bb0: {
- a = [];
+ const a = [];
a.push(props.a);
if (props.b) {
a.push(props.c);
- t0 = a;
+ t1 = a;
break bb0;
}
+ t0 = a;
a.push(props.d);
}
$[0] = props;
- $[1] = a;
- $[2] = t0;
+ $[1] = t0;
+ $[2] = t1;
} else {
- a = $[1];
- t0 = $[2];
+ t0 = $[1];
+ t1 = $[2];
}
- if (t0 !== Symbol.for("react.early_return_sentinel")) {
- return t0;
+ if (t1 !== Symbol.for("react.early_return_sentinel")) {
+ return t1;
}
- return a;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-computed.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-computed.expect.md
index 4c2db49c80b87..73b08b176731b 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-computed.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-computed.expect.md
@@ -24,17 +24,19 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(2);
- let x;
+ let t0;
if ($[0] !== props.foo) {
- x = {};
+ const x = {};
x.foo = x.foo + x.bar;
+
+ t0 = x;
x.foo(props.foo);
$[0] = props.foo;
- $[1] = x;
+ $[1] = t0;
} else {
- x = $[1];
+ t0 = $[1];
}
- return x;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/debugger-memoized.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/debugger-memoized.expect.md
index 6eb6dacd5f871..545e63b19d55e 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/debugger-memoized.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/debugger-memoized.expect.md
@@ -23,18 +23,19 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(2);
- let x;
+ let t0;
if ($[0] !== props.value) {
- x = [];
+ const x = [];
debugger;
+ t0 = x;
x.push(props.value);
$[0] = props.value;
- $[1] = x;
+ $[1] = t0;
} else {
- x = $[1];
+ t0 = $[1];
}
- return x;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/delete-computed-property.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/delete-computed-property.expect.md
index b7b201d4c51cb..76e48a5828745 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/delete-computed-property.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/delete-computed-property.expect.md
@@ -23,17 +23,19 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(3);
- let x;
+ let t0;
if ($[0] !== props.a || $[1] !== props.b) {
- x = { a: props.a, b: props.b };
+ const x = { a: props.a, b: props.b };
+
+ t0 = x;
delete x["b"];
$[0] = props.a;
$[1] = props.b;
- $[2] = x;
+ $[2] = t0;
} else {
- x = $[2];
+ t0 = $[2];
}
- return x;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/delete-property.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/delete-property.expect.md
index 764a26f07b3e4..962c2ff1256d0 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/delete-property.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/delete-property.expect.md
@@ -22,17 +22,19 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(3);
- let x;
+ let t0;
if ($[0] !== props.a || $[1] !== props.b) {
- x = { a: props.a, b: props.b };
+ const x = { a: props.a, b: props.b };
+
+ t0 = x;
delete x.b;
$[0] = props.a;
$[1] = props.b;
- $[2] = x;
+ $[2] = t0;
} else {
- x = $[2];
+ t0 = $[2];
}
- return x;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/do-while-early-unconditional-break.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/do-while-early-unconditional-break.expect.md
index 1e79a239dd021..67ff401433e1c 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/do-while-early-unconditional-break.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/do-while-early-unconditional-break.expect.md
@@ -19,16 +19,17 @@ function Component(props) {
import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(1);
- let x;
+ let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
- x = [1, 2, 3];
+ const x = [1, 2, 3];
+ t0 = x;
mutate(x);
- $[0] = x;
+ $[0] = t0;
} else {
- x = $[0];
+ t0 = $[0];
}
- return x;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dont-merge-if-dep-is-inner-declaration-of-previous-scope.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dont-merge-if-dep-is-inner-declaration-of-previous-scope.expect.md
index ad843e230fc48..2fc5577fb9712 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dont-merge-if-dep-is-inner-declaration-of-previous-scope.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dont-merge-if-dep-is-inner-declaration-of-previous-scope.expect.md
@@ -99,42 +99,42 @@ function Component(t0) {
t2 = $[12];
}
let t3;
- if ($[13] !== t2 || $[14] !== x) {
- t3 = ;
- $[13] = t2;
- $[14] = x;
+ if ($[13] !== a || $[14] !== b) {
+ t3 = [a, b];
+ $[13] = a;
+ $[14] = b;
$[15] = t3;
} else {
t3 = $[15];
}
let t4;
- if ($[16] !== a || $[17] !== b) {
- t4 = [a, b];
- $[16] = a;
- $[17] = b;
+ if ($[16] !== t3 || $[17] !== z) {
+ t4 = ;
+ $[16] = t3;
+ $[17] = z;
$[18] = t4;
} else {
t4 = $[18];
}
let t5;
- if ($[19] !== t4 || $[20] !== z) {
- t5 = ;
- $[19] = t4;
- $[20] = z;
+ if ($[19] !== t2 || $[20] !== x) {
+ t5 = ;
+ $[19] = t2;
+ $[20] = x;
$[21] = t5;
} else {
t5 = $[21];
}
let t6;
- if ($[22] !== t3 || $[23] !== t5) {
+ if ($[22] !== t5 || $[23] !== t4) {
t6 = (
<>
- {t3}
{t5}
+ {t4}
>
);
- $[22] = t3;
- $[23] = t5;
+ $[22] = t5;
+ $[23] = t4;
$[24] = t6;
} else {
t6 = $[24];
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bug-repro-trycatch-nested-overlapping-range.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bug-repro-trycatch-nested-overlapping-range.expect.md
index ca77829e2f7f4..2390842e78f7d 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bug-repro-trycatch-nested-overlapping-range.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.bug-repro-trycatch-nested-overlapping-range.expect.md
@@ -20,7 +20,7 @@ function Foo() {
## Error
```
-Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 2:24(18:26)
+Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 2:23(17:25)
```
\ No newline at end of file
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.repro-bug-ref-mutable-range.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.repro-bug-ref-mutable-range.expect.md
index 7cd2acc9affab..ead99369987cb 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.repro-bug-ref-mutable-range.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.repro-bug-ref-mutable-range.expect.md
@@ -21,7 +21,7 @@ function Foo(props, ref) {
## Error
```
-Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 1:21(16:23)
+Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 2:20(16:23)
```
\ No newline at end of file
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-iife-return-modified-later-logical.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-iife-return-modified-later-logical.expect.md
index c14ae737e544a..534f390693759 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-iife-return-modified-later-logical.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-iife-return-modified-later-logical.expect.md
@@ -23,7 +23,7 @@ export const FIXTURE_ENTRYPOINT = {
## Error
```
-Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 2:15(3:21)
+Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 2:15(3:22)
```
\ No newline at end of file
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-reactive-scope-overlaps-label.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-reactive-scope-overlaps-label.expect.md
index 62295b9a0ca0a..e2150e883a829 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-reactive-scope-overlaps-label.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-reactive-scope-overlaps-label.expect.md
@@ -34,7 +34,7 @@ export const FIXTURE_ENTRYPOINT = {
## Error
```
-Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 3:14(4:18)
+Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 3:14(5:19)
```
\ No newline at end of file
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-reactive-scope-overlaps-try.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-reactive-scope-overlaps-try.expect.md
index 95cdbe5aeea76..cc391028671d0 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-reactive-scope-overlaps-try.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/error.todo-reactive-scope-overlaps-try.expect.md
@@ -30,7 +30,7 @@ export const FIXTURE_ENTRYPOINT = {
## Error
```
-Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 4:19(5:22)
+Invariant: Invalid nesting in program blocks or scopes. Items overlap but are not nested: 3:17(4:21)
```
\ No newline at end of file
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-allocating-dependency.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-allocating-dependency.expect.md
index 50b96072fdd7a..86ac08765a4a4 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-allocating-dependency.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-allocating-dependency.expect.md
@@ -41,19 +41,21 @@ function Component(props) {
t0 = $[1];
}
const a = t0;
- let b;
+ let t1;
if ($[2] !== a || $[3] !== props.b) {
- b = [];
+ const b = [];
const c = {};
c.a = a;
+
+ t1 = b;
b.push(props.b);
$[2] = a;
$[3] = props.b;
- $[4] = b;
+ $[4] = t1;
} else {
- b = $[4];
+ t1 = $[4];
}
- return b;
+ return t1;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-allocating-nested-dependency.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-allocating-nested-dependency.expect.md
index 99b208b9e08e0..d41af45588768 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-allocating-nested-dependency.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-allocating-nested-dependency.expect.md
@@ -59,19 +59,21 @@ function Component(props) {
t1 = $[3];
}
const b = t1;
- let c;
+ let t2;
if ($[4] !== b || $[5] !== props.b) {
- c = [];
+ const c = [];
const d = {};
d.b = b;
+
+ t2 = c;
c.push(props.b);
$[4] = b;
$[5] = props.b;
- $[6] = c;
+ $[6] = t2;
} else {
- c = $[6];
+ t2 = $[6];
}
- return c;
+ return t2;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-primitive-dependency.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-primitive-dependency.expect.md
index 3132362670df6..08e4573592eeb 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-primitive-dependency.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-non-escaping-interleaved-primitive-dependency.expect.md
@@ -36,19 +36,21 @@ function Component(props) {
const $ = _c(3);
const a = props.a + props.b;
- let b;
+ let t0;
if ($[0] !== a || $[1] !== props.c) {
- b = [];
+ const b = [];
const c = {};
c.a = a;
+
+ t0 = b;
b.push(props.c);
$[0] = a;
$[1] = props.c;
- $[2] = b;
+ $[2] = t0;
} else {
- b = $[2];
+ t0 = $[2];
}
- return b;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-no-whitespace-btw-text-and-param.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-no-whitespace-btw-text-and-param.expect.md
index b48c92bb761d0..a305b961baf09 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-no-whitespace-btw-text-and-param.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-no-whitespace-btw-text-and-param.expect.md
@@ -29,15 +29,16 @@ import fbt from "fbt";
const _ = fbt;
function Component(t0) {
const $ = _c(2);
- const { value } = t0;
let t1;
- if ($[0] !== value) {
+ if ($[0] !== t0) {
+ const { value } = t0;
+
t1 = fbt._(
"Before text{paramName}After text",
[fbt._param("paramName", value)],
{ hk: "aKEGX" },
);
- $[0] = value;
+ $[0] = t0;
$[1] = t1;
} else {
t1 = $[1];
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-preserve-whitespace.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-preserve-whitespace.expect.md
index 5e67bbc163194..13de247d0b4ef 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-preserve-whitespace.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-preserve-whitespace.expect.md
@@ -30,9 +30,10 @@ import fbt from "fbt";
const _ = fbt;
function Component(t0) {
const $ = _c(2);
- const { value } = t0;
let t1;
- if ($[0] !== value) {
+ if ($[0] !== t0) {
+ const { value } = t0;
+
t1 = fbt._(
"Before text {paramName}",
[
@@ -44,7 +45,7 @@ function Component(t0) {
],
{ hk: "3z5SVE" },
);
- $[0] = value;
+ $[0] = t0;
$[1] = t1;
} else {
t1 = $[1];
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-single-space-btw-param-and-text.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-single-space-btw-param-and-text.expect.md
index 7fa312c49f791..b75a8261125d0 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-single-space-btw-param-and-text.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-single-space-btw-param-and-text.expect.md
@@ -29,15 +29,16 @@ import fbt from "fbt";
const _ = fbt;
function Component(t0) {
const $ = _c(2);
- const { value } = t0;
let t1;
- if ($[0] !== value) {
+ if ($[0] !== t0) {
+ const { value } = t0;
+
t1 = fbt._(
"Before text {paramName} after text",
[fbt._param("paramName", value)],
{ hk: "26pxNm" },
);
- $[0] = value;
+ $[0] = t0;
$[1] = t1;
} else {
t1 = $[1];
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-whitespace-around-param-value.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-whitespace-around-param-value.expect.md
index 3bfd3bab52c15..9d939a90b6168 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-whitespace-around-param-value.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-whitespace-around-param-value.expect.md
@@ -29,15 +29,16 @@ import fbt from "fbt";
const _ = fbt;
function Component(t0) {
const $ = _c(2);
- const { value } = t0;
let t1;
- if ($[0] !== value) {
+ if ($[0] !== t0) {
+ const { value } = t0;
+
t1 = fbt._(
"Before text {paramName} after text",
[fbt._param("paramName", value)],
{ hk: "26pxNm" },
);
- $[0] = value;
+ $[0] = t0;
$[1] = t1;
} else {
t1 = $[1];
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-whitespace-within-text.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-whitespace-within-text.expect.md
index 55326204caa41..2e854647a85ac 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-whitespace-within-text.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-whitespace-within-text.expect.md
@@ -31,15 +31,16 @@ import fbt from "fbt";
const _ = fbt;
function Component(t0) {
const $ = _c(2);
- const { value } = t0;
let t1;
- if ($[0] !== value) {
+ if ($[0] !== t0) {
+ const { value } = t0;
+
t1 = fbt._(
"Before text {paramName} after text more text and more and more and more and more and more and more and more and more and blah blah blah blah",
[fbt._param("paramName", value)],
{ hk: "24ZPpO" },
);
- $[0] = value;
+ $[0] = t0;
$[1] = t1;
} else {
t1 = $[1];
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbtparam-with-jsx-element-content.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbtparam-with-jsx-element-content.expect.md
index 387031fc181c7..402b4df8a12ab 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbtparam-with-jsx-element-content.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbtparam-with-jsx-element-content.expect.md
@@ -29,10 +29,11 @@ import { c as _c } from "react/compiler-runtime";
import fbt from "fbt";
function Component(t0) {
- const $ = _c(4);
- const { name, data, icon } = t0;
+ const $ = _c(2);
let t1;
- if ($[0] !== name || $[1] !== icon || $[2] !== data) {
+ if ($[0] !== t0) {
+ const { name, data, icon } = t0;
+
t1 = (
{fbt._(
@@ -61,12 +62,10 @@ function Component(t0) {
)}
);
- $[0] = name;
- $[1] = icon;
- $[2] = data;
- $[3] = t1;
+ $[0] = t0;
+ $[1] = t1;
} else {
- t1 = $[3];
+ t1 = $[1];
}
return t1;
}
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/lambda-with-fbt.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/lambda-with-fbt.expect.md
index 5ac0ad17a0645..f7e71f4be7bb9 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/lambda-with-fbt.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/lambda-with-fbt.expect.md
@@ -42,10 +42,10 @@ import { c as _c } from "react/compiler-runtime";
import { fbt } from "fbt";
function Component() {
- const $ = _c(2);
+ const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
- t0 = () => {
+ const buttonLabel = () => {
if (!someCondition) {
return fbt._("Purchase as a gift", null, { hk: "1gHj4g" });
} else {
@@ -66,23 +66,17 @@ function Component() {
}
}
};
- $[0] = t0;
- } else {
- t0 = $[0];
- }
- const buttonLabel = t0;
- let t1;
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
- t1 = (
+
+ t0 = (
);
- $[1] = t1;
+ $[0] = t0;
} else {
- t1 = $[1];
+ t0 = $[0];
}
- return t1;
+ return t0;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/for-of-nonmutating-loop-local-collection.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/for-of-nonmutating-loop-local-collection.expect.md
index 1c223a50f4a44..4e0040d1b847d 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/for-of-nonmutating-loop-local-collection.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/for-of-nonmutating-loop-local-collection.expect.md
@@ -82,42 +82,42 @@ function Component(t0) {
t4 = $[6];
}
let t5;
- if ($[7] !== t4 || $[8] !== x) {
- t5 = ;
- $[7] = t4;
- $[8] = x;
+ if ($[7] !== x || $[8] !== b) {
+ t5 = [x, b];
+ $[7] = x;
+ $[8] = b;
$[9] = t5;
} else {
t5 = $[9];
}
let t6;
- if ($[10] !== x || $[11] !== b) {
- t6 = [x, b];
- $[10] = x;
- $[11] = b;
+ if ($[10] !== t5 || $[11] !== y) {
+ t6 = ;
+ $[10] = t5;
+ $[11] = y;
$[12] = t6;
} else {
t6 = $[12];
}
let t7;
- if ($[13] !== t6 || $[14] !== y) {
- t7 = ;
- $[13] = t6;
- $[14] = y;
+ if ($[13] !== t4 || $[14] !== x) {
+ t7 = ;
+ $[13] = t4;
+ $[14] = x;
$[15] = t7;
} else {
t7 = $[15];
}
let t8;
- if ($[16] !== t5 || $[17] !== t7) {
+ if ($[16] !== t7 || $[17] !== t6) {
t8 = (
<>
- {t5}
{t7}
+ {t6}
>
);
- $[16] = t5;
- $[17] = t7;
+ $[16] = t7;
+ $[17] = t6;
$[18] = t8;
} else {
t8 = $[18];
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/function-declaration-simple.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/function-declaration-simple.expect.md
index e539fdda96795..e8c2b58ec7f8b 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/function-declaration-simple.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/function-declaration-simple.expect.md
@@ -25,27 +25,28 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function component(a) {
const $ = _c(3);
- let t;
+ let t0;
if ($[0] !== a) {
- t = { a };
- let t0;
+ const t = { a };
+ let t1;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
- t0 = function x(p) {
+ t1 = function x(p) {
p.foo();
};
- $[2] = t0;
+ $[2] = t1;
} else {
- t0 = $[2];
+ t1 = $[2];
}
- const x = t0;
+ const x = t1;
+ t0 = t;
x(t);
$[0] = a;
- $[1] = t;
+ $[1] = t0;
} else {
- t = $[1];
+ t0 = $[1];
}
- return t;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/function-expression-with-store-to-parameter.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/function-expression-with-store-to-parameter.expect.md
index 1803026c6397d..6eb6e756c5507 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/function-expression-with-store-to-parameter.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/function-expression-with-store-to-parameter.expect.md
@@ -31,16 +31,18 @@ function Component(props) {
t0 = $[0];
}
const mutate = t0;
- let x;
+ let t1;
if ($[1] !== props) {
- x = makeObject(props);
+ const x = makeObject(props);
+
+ t1 = x;
mutate(x);
$[1] = props;
- $[2] = x;
+ $[2] = t1;
} else {
- x = $[2];
+ t1 = $[2];
}
- return x;
+ return t1;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/iife-return-modified-later.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/iife-return-modified-later.expect.md
index eb96ed734fc3c..b18a2f55270e4 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/iife-return-modified-later.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/iife-return-modified-later.expect.md
@@ -24,20 +24,21 @@ import { c as _c } from "react/compiler-runtime";
function Component(props) {
const $ = _c(3);
let t0;
- let items;
+ let t1;
if ($[0] !== props.a) {
t0 = [];
- items = t0;
+ const items = t0;
+ t1 = items;
items.push(props.a);
$[0] = props.a;
- $[1] = items;
+ $[1] = t1;
$[2] = t0;
} else {
- items = $[1];
+ t1 = $[1];
t0 = $[2];
}
- return items;
+ return t1;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/inadvertent-mutability-readonly-lambda.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/inadvertent-mutability-readonly-lambda.expect.md
index cedda4ed8c2b8..03d5e46f96e50 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/inadvertent-mutability-readonly-lambda.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/inadvertent-mutability-readonly-lambda.expect.md
@@ -35,15 +35,17 @@ function Component(props) {
const onChange = t0;
useOtherHook();
- let x;
+ let t1;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
- x = {};
+ const x = {};
+
+ t1 = x;
foo(x, onChange);
- $[1] = x;
+ $[1] = t1;
} else {
- x = $[1];
+ t1 = $[1];
}
- return x;
+ return t1;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/independently-memoize-object-property.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/independently-memoize-object-property.expect.md
index 03c096ba9b2d7..05ee53f2279cd 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/independently-memoize-object-property.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/independently-memoize-object-property.expect.md
@@ -24,27 +24,29 @@ export const FIXTURE_ENTRYPOINT = {
import { c as _c } from "react/compiler-runtime";
function foo(a, b, c) {
const $ = _c(7);
- let x;
+ let t0;
if ($[0] !== a || $[1] !== b || $[2] !== c) {
- x = { a };
- let t0;
+ const x = { a };
+ let t1;
if ($[4] !== b || $[5] !== c) {
- t0 = [b, c];
+ t1 = [b, c];
$[4] = b;
$[5] = c;
- $[6] = t0;
+ $[6] = t1;
} else {
- t0 = $[6];
+ t1 = $[6];
}
- x.y = t0;
+
+ t0 = x;
+ x.y = t1;
$[0] = a;
$[1] = b;
$[2] = c;
- $[3] = x;
+ $[3] = t0;
} else {
- x = $[3];
+ t0 = $[3];
}
- return x;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/inner-memo-value-not-promoted-to-outer-scope-dynamic.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/inner-memo-value-not-promoted-to-outer-scope-dynamic.expect.md
index becc4066e7d76..89adf89046f8a 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/inner-memo-value-not-promoted-to-outer-scope-dynamic.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/inner-memo-value-not-promoted-to-outer-scope-dynamic.expect.md
@@ -24,69 +24,50 @@ function Component(props) {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(props) {
- const $ = _c(15);
+ const $ = _c(7);
const item = useFragment(FRAGMENT, props.item);
useFreeze(item);
let t0;
- let T0;
- let t1;
- let T1;
if ($[0] !== item) {
const count = new MaybeMutable(item);
- T1 = View;
- T0 = View;
- if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
- t1 = Text;
- $[5] = t1;
- } else {
- t1 = $[5];
- }
t0 = maybeMutate(count);
$[0] = item;
$[1] = t0;
- $[2] = T0;
- $[3] = t1;
- $[4] = T1;
} else {
t0 = $[1];
- T0 = $[2];
+ }
+ let t1;
+ if ($[2] !== t0) {
+ t1 = {t0};
+ $[2] = t0;
+ $[3] = t1;
+ } else {
t1 = $[3];
- T1 = $[4];
}
let t2;
- if ($[6] !== t0) {
- t2 = {t0};
- $[6] = t0;
- $[7] = t2;
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
+ t2 = Text;
+ $[4] = t2;
} else {
- t2 = $[7];
+ t2 = $[4];
}
let t3;
- if ($[8] !== T0 || $[9] !== t1 || $[10] !== t2) {
+ if ($[5] !== t1) {
t3 = (
-
- {t1}
- {t2}
-
+
+
+ {t2}
+ {t1}
+
+
);
- $[8] = T0;
- $[9] = t1;
- $[10] = t2;
- $[11] = t3;
- } else {
- t3 = $[11];
- }
- let t4;
- if ($[12] !== T1 || $[13] !== t3) {
- t4 = {t3};
- $[12] = T1;
- $[13] = t3;
- $[14] = t4;
+ $[5] = t1;
+ $[6] = t3;
} else {
- t4 = $[14];
+ t3 = $[6];
}
- return t4;
+ return t3;
}
```
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/issue933-disjoint-set-infinite-loop.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/issue933-disjoint-set-infinite-loop.expect.md
index 789135049a9df..3edace1441969 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/issue933-disjoint-set-infinite-loop.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/issue933-disjoint-set-infinite-loop.expect.md
@@ -42,17 +42,19 @@ function makeObj() {
// This caused an infinite loop in the compiler
function MyApp(props) {
const $ = _c(1);
- let y;
+ let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
- y = makeObj();
+ const y = makeObj();
const tmp = y.a;
const tmp2 = tmp.b;
+
+ t0 = y;
y.push(tmp2);
- $[0] = y;
+ $[0] = t0;
} else {
- y = $[0];
+ t0 = $[0];
}
- return y;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-freeze.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-freeze.expect.md
index 735f469c83639..30ee912b93a6e 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-freeze.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-freeze.expect.md
@@ -31,17 +31,19 @@ import { shallowCopy } from "shared-runtime";
function Component(props) {
const $ = _c(2);
- let element;
+ let t0;
if ($[0] !== props.width) {
const childprops = { style: { width: props.width } };
- element = _jsx("div", { childprops, children: '"hello world"' });
+ const element = _jsx("div", { childprops, children: '"hello world"' });
+
+ t0 = element;
shallowCopy(childprops);
$[0] = props.width;
- $[1] = element;
+ $[1] = t0;
} else {
- element = $[1];
+ t0 = $[1];
}
- return element;
+ return t0;
}
export const FIXTURE_ENTRYPOINT = {
diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-preserve-whitespace.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-preserve-whitespace.expect.md
index b9f791ed8bd88..063ffb548b708 100644
--- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-preserve-whitespace.expect.md
+++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/jsx-preserve-whitespace.expect.md
@@ -36,39 +36,29 @@ import { c as _c } from "react/compiler-runtime";
import { StaticText1 } from "shared-runtime";
function Component() {
- const $ = _c(3);
+ const $ = _c(1);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
- t0 = ;
- $[0] = t0;
- } else {
- t0 = $[0];
- }
- let t1;
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
- t1 = ;
- $[1] = t1;
- } else {
- t1 = $[1];
- }
- let t2;
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
- t2 = (
+ t0 = (
- Before text{t0}Middle text
+ Before text
+
+ Middle text
- Inner before text{t1}Inner middle text
+ Inner before text
+
+ Inner middle text
Inner after text
After text