From fe282194b2c8443d76eeb42e8e76e4c010d448e1 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Thu, 30 May 2024 08:30:21 -0700 Subject: [PATCH] compiler: allow reordering of loadlocal after last assignment [ghstack-poisoned] --- .../src/Optimization/InstructionReordering.ts | 84 +++++++++++++------ .../compiler/alias-computed-load.expect.md | 13 +-- .../alias-nested-member-path-mutate.expect.md | 12 +-- .../alias-nested-member-path.expect.md | 12 +-- .../array-at-mutate-after-capture.expect.md | 12 +-- .../compiler/array-push-effect.expect.md | 22 ++--- .../assignment-expression-computed.expect.md | 11 +-- ...ssignment-expression-nested-path.expect.md | 12 +-- ...-variations-complex-lvalue-array.expect.md | 12 +-- ...gnment-variations-complex-lvalue.expect.md | 12 +-- .../await-side-effecting-promise.expect.md | 12 +-- .../compiler/call-args-assignment.expect.md | 12 +-- ...ll-args-destructuring-assignment.expect.md | 12 +-- .../fixtures/compiler/call.expect.md | 4 +- .../capture-indirect-mutate-alias.expect.md | 14 ++-- .../capture_mutate-across-fns.expect.md | 14 ++-- ...fun-alias-captured-mutate-2-iife.expect.md | 11 +-- ...ring-fun-alias-captured-mutate-2.expect.md | 13 +-- ...alias-captured-mutate-arr-2-iife.expect.md | 11 +-- ...-fun-alias-captured-mutate-arr-2.expect.md | 13 +-- ...c-alias-captured-mutate-arr-iife.expect.md | 11 +-- ...g-func-alias-captured-mutate-arr.expect.md | 13 +-- ...-func-alias-captured-mutate-iife.expect.md | 11 +-- ...uring-func-alias-captured-mutate.expect.md | 13 +-- ...-func-alias-computed-mutate-iife.expect.md | 11 +-- ...uring-func-alias-computed-mutate.expect.md | 13 +-- ...capturing-func-alias-mutate-iife.expect.md | 11 +-- .../capturing-func-alias-mutate.expect.md | 13 +-- ...as-receiver-computed-mutate-iife.expect.md | 11 +-- ...c-alias-receiver-computed-mutate.expect.md | 13 +-- ...-func-alias-receiver-mutate-iife.expect.md | 11 +-- ...uring-func-alias-receiver-mutate.expect.md | 13 +-- .../capturing-func-mutate-2.expect.md | 13 +-- .../capturing-func-mutate-nested.expect.md | 13 +-- .../compiler/capturing-func-mutate.expect.md | 13 +-- .../capturing-function-decl.expect.md | 13 +-- .../chained-assignment-expressions.expect.md | 12 +-- .../codegen-emit-make-read-only.expect.md | 12 +-- .../computed-call-evaluation-order.expect.md | 11 +-- .../compiler/computed-store-alias.expect.md | 12 +-- .../conditional-break-labeled.expect.md | 11 +-- .../conditional-early-return.expect.md | 80 +++++++++--------- .../compiler/constant-computed.expect.md | 12 +-- .../fixtures/compiler/constructor.expect.md | 3 +- ...ble-reassigned-outside-of-lambda.expect.md | 13 ++- .../compiler/debugger-memoized.expect.md | 13 +-- .../delete-computed-property.expect.md | 12 +-- .../compiler/delete-property.expect.md | 12 +-- ...and-local-variables-with-default.expect.md | 2 +- ...ed-scope-declarations-and-locals.expect.md | 48 +++++------ ...-while-early-unconditional-break.expect.md | 11 +-- ...ng-scopes-store-const-used-later.expect.md | 2 +- ...fe-return-modified-later-logical.expect.md | 2 +- ...do-reactive-scope-overlaps-label.expect.md | 2 +- ...todo-reactive-scope-overlaps-try.expect.md | 2 +- .../escape-analysis-jsx-child.expect.md | 20 ++--- ...nterleaved-allocating-dependency.expect.md | 12 +-- ...ved-allocating-nested-dependency.expect.md | 12 +-- ...interleaved-primitive-dependency.expect.md | 12 +-- .../function-declaration-simple.expect.md | 23 ++--- ...pression-with-store-to-parameter.expect.md | 12 +-- ...sting-computed-member-expression.expect.md | 20 ++--- .../hoisting-member-expression.expect.md | 10 +-- .../fixtures/compiler/hook-call.expect.md | 2 +- .../iife-return-modified-later.expect.md | 11 +-- ...rtent-mutability-readonly-lambda.expect.md | 12 +-- ...endently-memoize-object-property.expect.md | 22 ++--- .../compiler/interdependent.expect.md | 26 ++---- ...ue933-disjoint-set-infinite-loop.expect.md | 12 +-- .../fixtures/compiler/jsx-freeze.expect.md | 12 +-- .../lambda-capture-returned-alias.expect.md | 12 +-- ...e-nested-scopes-with-same-inputs.expect.md | 12 +-- .../compiler/merge-scopes-callback.expect.md | 28 +++---- .../mutable-lifetime-with-aliasing.expect.md | 11 +-- ...mutation-during-jsx-construction.expect.md | 11 +-- ...-within-capture-and-mutablerange.expect.md | 11 +-- ...opes-begin-same-instr-valueblock.expect.md | 11 +-- ...bj-literal-mutated-after-if-else.expect.md | 10 ++- ...mutated-after-if-else-with-alias.expect.md | 10 ++- .../obj-mutated-after-if-else.expect.md | 10 ++- ...-after-nested-if-else-with-alias.expect.md | 10 ++- ...d-shorthand-aliased-mutate-after.expect.md | 11 +-- ...t-method-shorthand-mutated-after.expect.md | 11 +-- ...-within-capture-and-mutablerange.expect.md | 25 +++--- ...ng-scopes-shadowing-within-block.expect.md | 20 ++--- .../compiler/property-assignment.expect.md | 3 +- .../property-call-evaluation-order.expect.md | 11 +-- .../reactive-scope-grouping.expect.md | 12 +-- ...ject-method-calls-mutable-lambda.expect.md | 12 +-- .../readonly-object-method-calls.expect.md | 51 +++++------ .../reassignment-conditional.expect.md | 3 +- .../fixtures/compiler/reassignment.expect.md | 3 +- ...active-cond-deps-return-in-scope.expect.md | 23 ++--- .../conditional-member-expr.expect.md | 12 +-- .../jump-poisoned/return-in-scope.expect.md | 23 ++--- .../return-poisons-outer-scope.expect.md | 34 ++++---- .../jump-target-within-scope-label.expect.md | 11 +-- ...p-target-within-scope-loop-break.expect.md | 11 +-- .../return-before-scope-starts.expect.md | 12 +-- .../throw-before-scope-starts.expect.md | 12 +-- .../memberexpr-join-optional-chain.expect.md | 12 +-- .../memberexpr-join-optional-chain2.expect.md | 12 +-- .../subpath-order2.expect.md | 11 +-- .../superpath-order2.expect.md | 11 +-- .../uncond-nonoverlap-descendant.expect.md | 12 +-- .../uncond-nonoverlap-direct.expect.md | 12 +-- .../uncond-overlap-descendant.expect.md | 12 +-- .../uncond-overlap-direct.expect.md | 12 +-- .../uncond-subpath-order1.expect.md | 12 +-- .../uncond-subpath-order2.expect.md | 12 +-- .../uncond-subpath-order3.expect.md | 12 +-- .../fixtures/compiler/ref-in-effect.expect.md | 24 +++--- ...repro-renaming-conflicting-decls.expect.md | 79 +++++++++-------- ...react-hooks-based-on-import-name.expect.md | 28 +++---- .../fixtures/compiler/simple-alias.expect.md | 12 +-- .../compiler/ssa-call-jsx-2.expect.md | 2 +- .../fixtures/compiler/ssa-call-jsx.expect.md | 4 +- .../ssa-cascading-eliminated-phis.expect.md | 11 +-- ...a-property-alias-alias-mutate-if.expect.md | 11 +-- .../ssa-property-alias-mutate-if.expect.md | 11 +-- .../ssa-property-alias-mutate.expect.md | 13 +-- .../compiler/ssa-property-call.expect.md | 12 +-- .../compiler/ssa-property-mutate-2.expect.md | 12 +-- .../ssa-property-mutate-alias.expect.md | 14 ++-- .../compiler/ssa-property-mutate.expect.md | 12 +-- .../fixtures/compiler/ssa-property.expect.md | 12 +-- ...ernary-destruction-with-mutation.expect.md | 12 +-- ...a-renaming-ternary-with-mutation.expect.md | 12 +-- ...onditional-ternary-with-mutation.expect.md | 12 +-- ...ming-unconditional-with-mutation.expect.md | 11 +-- ...-via-destructuring-with-mutation.expect.md | 11 +-- .../ssa-renaming-with-mutation.expect.md | 11 +-- .../compiler/store-via-call.expect.md | 12 +-- .../fixtures/compiler/store-via-new.expect.md | 12 +-- .../switch-non-final-default.expect.md | 2 +- .../fixtures/compiler/switch.expect.md | 2 +- ...temporary-accessed-outside-scope.expect.md | 31 ++++--- ...erty-load-accessed-outside-scope.expect.md | 31 ++++--- ...sion-captures-value-later-frozen.expect.md | 2 +- .../try-catch-alias-try-values.expect.md | 15 ++-- .../try-catch-in-nested-scope.expect.md | 50 +++++------ .../try-catch-within-mutable-range.expect.md | 31 +++---- ...pendency-is-pruned-as-dependency.expect.md | 12 +-- ...-value-dont-preserve-memoization.expect.md | 12 +-- ...table-value-preserve-memoization.expect.md | 3 +- ...operty-dont-preserve-memoization.expect.md | 3 +- .../compiler/useEffect-snap-test.expect.md | 30 +++---- ...-preserve-memoization-guarantees.expect.md | 12 +-- 148 files changed, 1143 insertions(+), 1013 deletions(-) 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 368e5865b0..d107b1546f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Optimization/InstructionReordering.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Optimization/InstructionReordering.ts @@ -4,6 +4,8 @@ import { HIRFunction, IdentifierId, Instruction, + InstructionId, + makeInstructionId, markInstructionIds, } from "../HIR"; import { @@ -67,13 +69,41 @@ import { getOrInsertDefault } from "../Utils/utils"; * - Probably more things. */ export function instructionReordering(fn: HIRFunction): void { + const lastReassignments = findLasReassignment(fn); const globalDependencies: Dependencies = new Map(); for (const [, block] of fn.body.blocks) { - reorderBlock(fn.env, block, globalDependencies); + reorderBlock(fn.env, block, globalDependencies, lastReassignments); } markInstructionIds(fn.body); } +function findLasReassignment(fn: HIRFunction): Reassignments { + const lastReassignments: Reassignments = new Map(); + for (const [, block] of fn.body.blocks) { + for (const instr of block.instructions) { + for (const lvalue of eachInstructionValueLValue(instr.value)) { + if ( + lvalue.identifier.name !== null && + lvalue.identifier.name.kind === "named" + ) { + const name = lvalue.identifier.name.value; + const previous = lastReassignments.get(name); + if (previous !== undefined) { + lastReassignments.set( + name, + makeInstructionId(Math.max(previous, instr.id)) + ); + } else { + lastReassignments.set(name, instr.id); + } + } + } + } + } + return lastReassignments; +} + +type Reassignments = Map; type Dependencies = Map; type Node = { instruction: Instruction | null; @@ -81,10 +111,17 @@ type Node = { depth: number | null; }; +enum ReorderingLevel { + None = "none", + Local = "local", + Global = "global", +} + function reorderBlock( env: Environment, block: BasicBlock, - globalDependencies: Dependencies + globalDependencies: Dependencies, + lastReassignments: Reassignments ): void { const dependencies: Dependencies = new Map(); const locals = new Map(); @@ -99,7 +136,7 @@ function reorderBlock( depth: null, } ); - if (getReorderingLevel(instr) === ReorderingLevel.None) { + if (getReorderingLevel(instr, lastReassignments) === ReorderingLevel.None) { if (previousIdentifier !== null) { node.dependencies.push(previousIdentifier); } @@ -206,7 +243,8 @@ function reorderBlock( } if ( node.instruction !== null && - getReorderingLevel(node.instruction) === ReorderingLevel.Global && + getReorderingLevel(node.instruction, lastReassignments) === + ReorderingLevel.Global && (block.kind === "block" || block.kind === "catch") ) { globalDependencies.set(id, node); @@ -221,12 +259,10 @@ function reorderBlock( block.instructions = instructions; } -enum ReorderingLevel { - None = "none", - Local = "local", - Global = "global", -} -function getReorderingLevel(instr: Instruction): ReorderingLevel { +function getReorderingLevel( + instr: Instruction, + lastReassignments: Reassignments +): ReorderingLevel { switch (instr.value.kind) { case "JsxExpression": case "JsxFragment": @@ -236,21 +272,19 @@ function getReorderingLevel(instr: Instruction): ReorderingLevel { case "TemplateLiteral": { return ReorderingLevel.Global; } - /* - * For locals, a simple and robust strategy is to figure out the range of instructions where the identifier may be reassigned, - * and then allow reordering of LoadLocal instructions which occur after this range. Obviously for const, this means that all - * LoadLocals can be reordered, so a simpler thing to start with is just to only allow reordering of loads of known-consts. - * - * With this overall strategy we can allow global reordering of LoadLocals and remove the global/local reordering distinction - * (all reordering can be global). - * - * case "Destructure": - * case "StoreLocal": - * case "LoadLocal": - * { - * return ReorderingLevel.Local; - * } - */ + case "LoadLocal": { + if ( + instr.value.place.identifier.name !== null && + instr.value.place.identifier.name.kind === "named" + ) { + const name = instr.value.place.identifier.name.value; + const lastAssignment = lastReassignments.get(name); + if (lastAssignment !== undefined && lastAssignment < instr.id) { + return ReorderingLevel.Global; + } + } + return ReorderingLevel.None; + } default: { return ReorderingLevel.None; } 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 f76e98b6c3..2a9a70fae5 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 y = {}; + const x = { a }; + t0 = x; + const y = {}; 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 f320d63071..3e40188e78 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 = {}; + + t0 = x; x.y = y; 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 100567a338..d7a1d0c7aa 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/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 c2ba733636..2b4b2973c4 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, {}]; + + t0 = x; const idx = foo(props.b); 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 5173d8a6f8..85f3212e9f 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 = []; + + t2 = 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); 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 e08a77ba51..069a756126 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,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.x) { - x = [props.x]; + const x = [props.x]; + t0 = x; x[0] = x[0] * 2; 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 686da0f671..dc6f152f2c 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 } }; + + t0 = a; a.b.c = a.b.c + 1; 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 7ea9a06929..8bb482f835 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 3c9346340f..4fa815287c 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 } }; + + t0 = x; x.y.z = x.y.z + 1; 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 6996c2cac7..0abe8f0df6 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 6432d24ff0..9c3ff2acfe 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 e348b53244..c7746ec1a8 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/call.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/call.expect.md index b0bd96c2bf..0398272ff0 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/call.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/call.expect.md @@ -27,10 +27,10 @@ function Component(props) { if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const a = []; const b = {}; - foo(a, b); - foo(b); t0 =
; + foo(a, b); + foo(b); $[0] = t0; } else { t0 = $[0]; 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 8373795ca1..0a4ae3440a 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 c9c066fef5..510cb838fb 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 b201c8ec5b..bd53012d7c 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 e4eac82064..87e261b0e3 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 }; + + t0 = x; const y = { bar }; 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 d8f889aaf4..889c3afc46 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 a912853a91..15cbaebf0b 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 }; + + t0 = x; const y = { bar }; 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 d3fd9e16ea..2a0f8050fd 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 13dcc589a6..199a4ea953 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,25 +23,26 @@ 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 }; + + t0 = y; const f0 = function () { const a = [y]; const b = x; a.x = b; }; - f0(); 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 4b8a5857f8..91c611107b 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 cb6d0d6e6a..822e74703a 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,25 +23,26 @@ 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 }; + + t0 = y; const f0 = function () { const a = { y }; const b = x; a.x = b; }; - f0(); 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 7a1405611a..d4270e7623 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 b96fcb590c..dd8ccc1429 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,23 @@ 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 = {}; + + t0 = y; const f0 = function () { y.x = x; }; - f0(); 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 e5e1f88688..dd289113bb 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 4f3ec26a55..e3b7fa50df 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,23 @@ 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 = {}; + + t0 = y; const f0 = function () { y.x = x; }; - f0(); 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 c285e3cfce..6e0b8ecece 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 e9bd3e4e0c..3b8999ac71 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,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 = {}; + + t0 = y; const f0 = function () { const a_0 = y; a_0.x = x; }; - f0(); 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 5c19fc6dcb..3a17980746 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 c4cf99c1e2..6d30d743fe 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,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 = {}; + + t0 = y; const f0 = function () { const a_0 = y; a_0.x = x; }; - f0(); 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 146c6292ca..483440897b 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 7d0edb1a3b..3b9acc7c2c 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 5b48ec9070..dd60c47bfa 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 }; + + t0 = z; const y = { b }; 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 143ffa5bf9..95de2fe918 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 }; + + t0 = t; const x = function x() { t.foo(); }; - 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 5cd4f52387..0f8bc98066 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 }; + + t0 = z; x.x = x.x + (y.y = y.y * 1); 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 ba9e39e691..6802c187a8 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 76bdcf1efe..5b6c930395 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 f08c01f728..6b71954ea7 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 }; + + t0 = x; x.y = y; 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 2c6b373f0c..e4271a2eda 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 04012db573..2628c67b89 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 4c2db49c80..3b08ab802d 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 = {}; + + t0 = x; x.foo = x.foo + x.bar; 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/constructor.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constructor.expect.md index bfa6c83071..ae678e709d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constructor.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constructor.expect.md @@ -27,9 +27,10 @@ function Component(props) { if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const a = []; const b = {}; + + t0 =
; new Foo(a, b); new Foo(b); - t0 =
; $[0] = t0; } else { t0 = $[0]; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/context-variable-reassigned-outside-of-lambda.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/context-variable-reassigned-outside-of-lambda.expect.md index 8d53b0cc42..78eea60354 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/context-variable-reassigned-outside-of-lambda.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/context-variable-reassigned-outside-of-lambda.expect.md @@ -28,20 +28,19 @@ import { Stringify } from "shared-runtime"; function Component(props) { const $ = _c(1); + let x; + x = null; + const callback = () => { + console.log(x); + }; let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - let x; - x = null; - const callback = () => { - console.log(x); - }; - - x = {}; t0 = ; $[0] = t0; } else { t0 = $[0]; } + x = {}; return t0; } 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 6eb6dacd5f..993fe99055 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 = []; - debugger; + const x = []; + t0 = x; + debugger; 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 b7b201d4c5..76e48a5828 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 764a26f07b..962c2ff125 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/destructuring-mixed-scope-and-local-variables-with-default.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.expect.md index d8be3af6cb..87d3117dac 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.expect.md @@ -105,8 +105,8 @@ function Component(props) { } const onClick = t7; - allUrls.push(...urls); t1 = ; + allUrls.push(...urls); $[1] = post; $[2] = t1; } else { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.expect.md index 69e0f07088..a848c8316e 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.expect.md @@ -30,37 +30,37 @@ function Component(props) { ```javascript import { c as _c } from "react/compiler-runtime"; function Component(props) { - const $ = _c(4); + const $ = _c(5); const post = useFragment(graphql`...`, props.post); + const allUrls = []; + + const { media, comments, urls } = post; let t0; - if ($[0] !== post) { - const allUrls = []; + if ($[0] !== comments.length) { + t0 = (e) => { + if (!comments.length) { + return; + } - const { media, comments, urls } = post; - let t1; - if ($[2] !== comments.length) { - t1 = (e) => { - if (!comments.length) { - return; - } - - console.log(comments.length); - }; - $[2] = comments.length; - $[3] = t1; - } else { - t1 = $[3]; - } - const onClick = t1; - - allUrls.push(...urls); - t0 = ; - $[0] = post; + console.log(comments.length); + }; + $[0] = comments.length; $[1] = t0; } else { t0 = $[1]; } - return t0; + const onClick = t0; + let t1; + if ($[2] !== media || $[3] !== onClick) { + t1 = ; + $[2] = media; + $[3] = onClick; + $[4] = t1; + } else { + t1 = $[4]; + } + allUrls.push(...urls); + return t1; } ``` 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 1e79a239dd..67ff401433 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-overlapping-scopes-store-const-used-later.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dont-merge-overlapping-scopes-store-const-used-later.expect.md index ccbd69e840..d22f38e8b0 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dont-merge-overlapping-scopes-store-const-used-later.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/dont-merge-overlapping-scopes-store-const-used-later.expect.md @@ -46,7 +46,6 @@ function Component(props) { t1 = $[3]; } const element = t1; - console.log(x); let t2; if ($[4] !== element) { t2 =
{element}
; @@ -55,6 +54,7 @@ function Component(props) { } else { t2 = $[5]; } + console.log(x); return t2; } 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 c14ae737e5..534f390693 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 62295b9a0c..e2150e883a 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 e10a451cf3..cc39102867 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: 3:17(4:20) +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-jsx-child.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-jsx-child.expect.md index 20a669365f..8d5d94a9a9 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-jsx-child.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/escape-analysis-jsx-child.expect.md @@ -27,30 +27,24 @@ export const FIXTURE_ENTRYPOINT = { ```javascript import { c as _c } from "react/compiler-runtime"; function foo(a, b, c) { - const $ = _c(9); + const $ = _c(7); let x; if ($[0] !== a || $[1] !== b || $[2] !== c) { x = []; if (a) { - let y; + let t0; if ($[4] !== b || $[5] !== c) { - y = []; + const y = []; if (b) { y.push(c); } + + t0 =
{y}
; $[4] = b; $[5] = c; - $[6] = y; + $[6] = t0; } else { - y = $[6]; - } - let t0; - if ($[7] !== y) { - t0 =
{y}
; - $[7] = y; - $[8] = t0; - } else { - t0 = $[8]; + t0 = $[6]; } x.push(t0); } 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 50b96072fd..27aa39fcb4 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 = []; + + t1 = b; const c = {}; c.a = a; 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 99b208b9e0..8c9e77ded7 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 = []; + + t2 = c; const d = {}; d.b = b; 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 3132362670..6b4abdabd2 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 = []; + + t0 = b; const c = {}; c.a = a; 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/function-declaration-simple.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/function-declaration-simple.expect.md index e539fdda96..5337a8ccce 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 }; + + t0 = t; + 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; 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 1803026c63..6eb6e756c5 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/hoisting-computed-member-expression.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-computed-member-expression.expect.md index 081a10e967..9ce26db948 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-computed-member-expression.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-computed-member-expression.expect.md @@ -34,19 +34,15 @@ import { Stringify } from "shared-runtime"; function hoisting() { const $ = _c(1); + const onClick = function onClick() { + return bar.baz; + }; + + const onClick2 = function onClick2() { + return bar[baz]; + }; let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - const onClick = function onClick() { - return bar.baz; - }; - - const onClick2 = function onClick2() { - return bar[baz]; - }; - - const baz = "baz"; - const bar = { baz: 1 }; - t0 = ( ); @@ -54,6 +50,8 @@ function hoisting() { } else { t0 = $[0]; } + const baz = "baz"; + const bar = { baz: 1 }; return t0; } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-member-expression.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-member-expression.expect.md index 54c3cf3a24..acc1b03556 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-member-expression.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hoisting-member-expression.expect.md @@ -29,19 +29,17 @@ import { Stringify } from "shared-runtime"; function hoisting() { const $ = _c(1); + const onClick = function onClick(x) { + return x + bar.baz; + }; let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - const onClick = function onClick(x) { - return x + bar.baz; - }; - - const bar = { baz: 1 }; - t0 = ; $[0] = t0; } else { t0 = $[0]; } + const bar = { baz: 1 }; return t0; } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call.expect.md index cd01f8ad98..ac0d4ac430 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hook-call.expect.md @@ -37,7 +37,6 @@ function Component(props) { } const x = t0; const y = useFreeze(x); - foo(y, x); let t1; if ($[1] !== y) { t1 = ( @@ -51,6 +50,7 @@ function Component(props) { } else { t1 = $[2]; } + foo(y, 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 eb96ed734f..b18a2f5527 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 cedda4ed8c..03d5e46f96 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 03c096ba9b..adad18feb8 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 }; + + t0 = x; + 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; + 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/interdependent.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/interdependent.expect.md index 32e87ab33f..bd1b4408d2 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/interdependent.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/interdependent.expect.md @@ -37,29 +37,19 @@ import { c as _c } from "react/compiler-runtime"; /** * return = */ function Component(props) { - const $ = _c(7); - let a; - let b; + const $ = _c(3); + let t0; if ($[0] !== props.a || $[1] !== props.b) { - a = compute(props.a); - b = compute(props.b); + const a = compute(props.a); + const b = compute(props.b); + + t0 = ; foo(a, b); $[0] = props.a; $[1] = props.b; - $[2] = a; - $[3] = b; + $[2] = t0; } else { - a = $[2]; - b = $[3]; - } - let t0; - if ($[4] !== a || $[5] !== b) { - t0 = ; - $[4] = a; - $[5] = b; - $[6] = t0; - } else { - t0 = $[6]; + t0 = $[2]; } return t0; } 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 789135049a..bfdafb5cb3 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(); + + t0 = y; const tmp = y.a; const tmp2 = tmp.b; 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 735f469c83..30ee912b93 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/lambda-capture-returned-alias.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/lambda-capture-returned-alias.expect.md index b468585f8c..c74fd866ef 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/lambda-capture-returned-alias.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/lambda-capture-returned-alias.expect.md @@ -43,7 +43,7 @@ function CaptureNotMutate(props) { t0 = $[1]; } const idx = t0; - let aliasedElement; + let t1; if ($[2] !== props.el || $[3] !== idx) { const element = bar(props.el); @@ -52,15 +52,17 @@ function CaptureNotMutate(props) { return arr[idx]; }; - aliasedElement = fn(); + const aliasedElement = fn(); + + t1 = aliasedElement; mutate(aliasedElement); $[2] = props.el; $[3] = idx; - $[4] = aliasedElement; + $[4] = t1; } else { - aliasedElement = $[4]; + t1 = $[4]; } - return aliasedElement; + return t1; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/merge-nested-scopes-with-same-inputs.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/merge-nested-scopes-with-same-inputs.expect.md index 6a7c8a5a28..12cffb7890 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/merge-nested-scopes-with-same-inputs.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/merge-nested-scopes-with-same-inputs.expect.md @@ -35,21 +35,21 @@ import { setProperty } from "shared-runtime"; function Component(props) { const $ = _c(2); - let y; + let t0; if ($[0] !== props.a) { - y = {}; + const y = {}; + t0 = y; const x = {}; setProperty(x, props.a); - y.a = props.a; y.x = x; $[0] = props.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/merge-scopes-callback.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/merge-scopes-callback.expect.md index 8e80428cce..e77177a882 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/merge-scopes-callback.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/merge-scopes-callback.expect.md @@ -26,39 +26,33 @@ import { c as _c } from "react/compiler-runtime"; import { useState } from "react"; function Component() { - const $ = _c(4); + const $ = _c(3); const [state, setState] = useState(0); let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - t0 = () => { + const onClick = () => { setState((s) => s + 1); }; + + t0 = ; $[0] = t0; } else { t0 = $[0]; } - const onClick = t0; let t1; - if ($[1] === Symbol.for("react.memo_cache_sentinel")) { - t1 = ; - $[1] = t1; - } else { - t1 = $[1]; - } - let t2; - if ($[2] !== state) { - t2 = ( + if ($[1] !== state) { + t1 = ( <> Count: {state} - {t1} + {t0} ); - $[2] = state; - $[3] = t2; + $[1] = state; + $[2] = t1; } else { - t2 = $[3]; + t1 = $[2]; } - return t2; + return t1; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutable-lifetime-with-aliasing.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutable-lifetime-with-aliasing.expect.md index 0fd482ea4d..3aab273f8e 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutable-lifetime-with-aliasing.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutable-lifetime-with-aliasing.expect.md @@ -68,14 +68,14 @@ function mutate(x, y) { function Component(props) { const $ = _c(1); - let x; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const a = {}; const b = [a]; const c = {}; const d = { c }; - x = {}; + const x = {}; x.b = b; const y = mutate(x, d); if (a) { @@ -89,12 +89,13 @@ function Component(props) { if (y) { } + t0 = x; mutate(x, null); - $[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/mutation-during-jsx-construction.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutation-during-jsx-construction.expect.md index d1f8165d61..d29bebd1c1 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutation-during-jsx-construction.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutation-during-jsx-construction.expect.md @@ -29,19 +29,20 @@ import { identity, mutate, mutateAndReturnNewValue } from "shared-runtime"; function Component(props) { const $ = _c(2); - let element; + let t0; if ($[0] !== props.value) { const key = {}; - element =
{props.value}
; + const element =
{props.value}
; + t0 = element; mutate(key); $[0] = props.value; - $[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/mutation-within-capture-and-mutablerange.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutation-within-capture-and-mutablerange.expect.md index 79370f8713..1972d9a9d1 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutation-within-capture-and-mutablerange.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/mutation-within-capture-and-mutablerange.expect.md @@ -53,22 +53,23 @@ import { mutate } from "shared-runtime"; function useFoo(t0) { const $ = _c(3); const { a, b } = t0; - let z; + let t1; if ($[0] !== a || $[1] !== b) { const x = { a }; const y = [b]; mutate(x); - z = [mutate(y)]; + const z = [mutate(y)]; + t1 = z; mutate(y); $[0] = a; $[1] = b; - $[2] = z; + $[2] = t1; } else { - z = $[2]; + t1 = $[2]; } - return z; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/nested-scopes-begin-same-instr-valueblock.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/nested-scopes-begin-same-instr-valueblock.expect.md index b962759ef3..4dccaf3a9e 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/nested-scopes-begin-same-instr-valueblock.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/nested-scopes-begin-same-instr-valueblock.expect.md @@ -33,17 +33,18 @@ import { identity, mutate } from "shared-runtime"; function Foo(t0) { const $ = _c(2); const { cond } = t0; - let x; + let t1; if ($[0] !== cond) { - x = identity(identity(cond)) ? { a: 2 } : { b: 2 }; + const x = identity(identity(cond)) ? { a: 2 } : { b: 2 }; + t1 = x; mutate(x); $[0] = cond; - $[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/obj-literal-mutated-after-if-else.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-literal-mutated-after-if-else.expect.md index a3bf0e5ee8..b62d7517ad 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-literal-mutated-after-if-else.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-literal-mutated-after-if-else.expect.md @@ -22,22 +22,24 @@ function foo(a, b, c, d) { import { c as _c } from "react/compiler-runtime"; function foo(a, b, c, d) { const $ = _c(3); - let x; + let t0; if ($[0] !== b || $[1] !== c) { + let x; if (someVal) { x = { b }; } else { x = { c }; } + t0 = x; x.f = 1; $[0] = b; $[1] = c; - $[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/obj-mutated-after-if-else-with-alias.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-mutated-after-if-else-with-alias.expect.md index 52077b6b89..47c22c1694 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-mutated-after-if-else-with-alias.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-mutated-after-if-else-with-alias.expect.md @@ -25,8 +25,9 @@ import { c as _c } from "react/compiler-runtime"; function foo(a, b, c, d) { const $ = _c(2); someObj(); - let x; + let t0; if ($[0] !== a) { + let x; if (a) { const y = someObj(); const z = y; @@ -35,13 +36,14 @@ function foo(a, b, c, d) { x = someObj(); } + t0 = x; x.f = 1; $[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/obj-mutated-after-if-else.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-mutated-after-if-else.expect.md index 933e05d155..db1ea1b788 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-mutated-after-if-else.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-mutated-after-if-else.expect.md @@ -23,21 +23,23 @@ import { c as _c } from "react/compiler-runtime"; function foo(a, b, c, d) { const $ = _c(2); someObj(); - let x; + let t0; if ($[0] !== a) { + let x; if (a) { x = someObj(); } else { x = someObj(); } + t0 = x; x.f = 1; $[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/obj-mutated-after-nested-if-else-with-alias.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-mutated-after-nested-if-else-with-alias.expect.md index 8c4a8b1a3c..0c1c88cd40 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-mutated-after-nested-if-else-with-alias.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/obj-mutated-after-nested-if-else-with-alias.expect.md @@ -31,8 +31,9 @@ import { c as _c } from "react/compiler-runtime"; function foo(a, b, c, d) { const $ = _c(3); someObj(); - let x; + let t0; if ($[0] !== a || $[1] !== b) { + let x; if (a) { let z; if (b) { @@ -47,14 +48,15 @@ function foo(a, b, c, d) { x = someObj(); } + t0 = x; x.f = 1; $[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/object-method-shorthand-aliased-mutate-after.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-aliased-mutate-after.expect.md index 3ad02df030..c9dbcf057b 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-aliased-mutate-after.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-aliased-mutate-after.expect.md @@ -29,22 +29,23 @@ import { createHookWrapper, mutate, mutateAndReturn } from "shared-runtime"; function useHook(t0) { const $ = _c(2); const { value } = t0; - let obj; + let t1; if ($[0] !== value) { const x = mutateAndReturn({ value }); - obj = { + const obj = { getValue() { return value; }, }; + t1 = obj; mutate(x); $[0] = value; - $[1] = obj; + $[1] = t1; } else { - obj = $[1]; + t1 = $[1]; } - return obj; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-mutated-after.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-mutated-after.expect.md index 46d532308b..89ce380c58 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-mutated-after.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-mutated-after.expect.md @@ -29,22 +29,23 @@ import { createHookWrapper, mutate, mutateAndReturn } from "shared-runtime"; function useHook(t0) { const $ = _c(2); const { value } = t0; - let obj; + let t1; if ($[0] !== value) { const x = mutateAndReturn({ value }); - obj = { + const obj = { getValue() { return x; }, }; + t1 = obj; mutate(obj); $[0] = value; - $[1] = obj; + $[1] = t1; } else { - obj = $[1]; + t1 = $[1]; } - return obj; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutation-within-capture-and-mutablerange.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutation-within-capture-and-mutablerange.expect.md index f3278e91ba..e0de2ea29a 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutation-within-capture-and-mutablerange.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/original-reactive-scopes-fork/mutation-within-capture-and-mutablerange.expect.md @@ -54,31 +54,32 @@ import { mutate } from "shared-runtime"; function useFoo(t0) { const $ = _c(5); const { a, b } = t0; - let z; + let t1; if ($[0] !== a || $[1] !== b) { const x = { a }; const y = [b]; mutate(x); - const t1 = mutate(y); - let t2; - if ($[3] !== t1) { - t2 = [t1]; - $[3] = t1; - $[4] = t2; + const t2 = mutate(y); + let t3; + if ($[3] !== t2) { + t3 = [t2]; + $[3] = t2; + $[4] = t3; } else { - t2 = $[4]; + t3 = $[4]; } - z = t2; + const z = t3; + t1 = z; mutate(y); $[0] = a; $[1] = b; - $[2] = z; + $[2] = t1; } else { - z = $[2]; + t1 = $[2]; } - return z; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowing-within-block.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowing-within-block.expect.md index d5ffcdb931..071aa2dd80 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowing-within-block.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/overlapping-scopes-shadowing-within-block.expect.md @@ -28,30 +28,24 @@ export const FIXTURE_ENTRYPOINT = { ```javascript import { c as _c } from "react/compiler-runtime"; function foo(a, b, c) { - const $ = _c(9); + const $ = _c(7); let x; if ($[0] !== a || $[1] !== b || $[2] !== c) { x = []; if (a) { - let y; + let t0; if ($[4] !== b || $[5] !== c) { - y = []; + const y = []; if (b) { y.push(c); } + + t0 =
{y}
; $[4] = b; $[5] = c; - $[6] = y; + $[6] = t0; } else { - y = $[6]; - } - let t0; - if ($[7] !== y) { - t0 =
{y}
; - $[7] = y; - $[8] = t0; - } else { - t0 = $[8]; + t0 = $[6]; } x.push(t0); } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-assignment.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-assignment.expect.md index 523b5b29bd..29618edff9 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-assignment.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-assignment.expect.md @@ -25,8 +25,9 @@ function Component(props) { const y = []; x.y = y; const child = ; - x.y.push(props.p0); + t0 = {child}; + x.y.push(props.p0); $[0] = props.p0; $[1] = t0; } else { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-evaluation-order.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-evaluation-order.expect.md index d097ee0fad..0f0a336c4e 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-evaluation-order.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/property-call-evaluation-order.expect.md @@ -41,16 +41,17 @@ 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).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/reactive-scope-grouping.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scope-grouping.expect.md index 71cd4e526a..a7e04fbe9b 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scope-grouping.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reactive-scope-grouping.expect.md @@ -26,18 +26,20 @@ export const FIXTURE_ENTRYPOINT = { import { c as _c } from "react/compiler-runtime"; function foo() { const $ = _c(1); - let x; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - x = {}; + const x = {}; + + t0 = x; const y = []; const z = {}; y.push(z); 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/readonly-object-method-calls-mutable-lambda.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.expect.md index 9a9314db7a..4e124025b7 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls-mutable-lambda.expect.md @@ -25,7 +25,7 @@ function Component(props) { ```javascript import { c as _c } from "react/compiler-runtime"; function Component(props) { - const $ = _c(3); + const $ = _c(1); const x = makeObject(); const user = useFragment( graphql`fragment Component_user on User { ... }`, @@ -45,15 +45,7 @@ function Component(props) { posts.push(t0); const count = posts.length; foo(count); - let t1; - if ($[1] !== posts) { - t1 = <>{posts}; - $[1] = posts; - $[2] = t1; - } else { - t1 = $[2]; - } - return t1; + return <>{posts}; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls.expect.md index 3418d008c3..20c97df977 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/readonly-object-method-calls.expect.md @@ -23,38 +23,39 @@ function Component(props) { ```javascript import { c as _c } from "react/compiler-runtime"; function Component(props) { - const $ = _c(5); + const $ = _c(4); const user = useFragment( graphql`fragment Component_user on User { ... }`, props.user, ); - let posts; - if ($[0] !== user.timeline.posts.edges.nodes) { - posts = user.timeline.posts.edges.nodes.map((node) => ); - let t0; - if ($[2] === Symbol.for("react.memo_cache_sentinel")) { - t0 = {}; - $[2] = t0; - } else { - t0 = $[2]; - } - posts.push(t0); - $[0] = user.timeline.posts.edges.nodes; - $[1] = posts; - } else { - posts = $[1]; - } - const count = posts.length; - foo(count); let t0; - if ($[3] !== posts) { - t0 = <>{posts}; - $[3] = posts; - $[4] = t0; + let t1; + if ($[0] !== user.timeline.posts.edges.nodes) { + const posts = user.timeline.posts.edges.nodes.map((node) => ( + + )); + + t0 = posts; + + t1 = <>{posts}; + let t2; + if ($[3] === Symbol.for("react.memo_cache_sentinel")) { + t2 = {}; + $[3] = t2; + } else { + t2 = $[3]; + } + posts.push(t2); + $[0] = user.timeline.posts.edges.nodes; + $[1] = t0; + $[2] = t1; } else { - t0 = $[4]; + t0 = $[1]; + t1 = $[2]; } - return t0; + const count = t0.length; + foo(count); + return t1; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-conditional.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-conditional.expect.md index 9358d39cf4..4f9d914ea7 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-conditional.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment-conditional.expect.md @@ -40,9 +40,8 @@ function Component(props) { x = t1; } - y.push(props.p2); - t0 = ; + y.push(props.p2); $[0] = props.p0; $[1] = props.p1; $[2] = props.p2; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment.expect.md index 3804326553..0b9979fbd3 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reassignment.expect.md @@ -37,9 +37,8 @@ function Component(props) { } x = t1; - y.push(props.p1); - t0 = ; + y.push(props.p1); $[0] = props.p0; $[1] = props.p1; $[2] = t0; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-return-in-scope.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-return-in-scope.expect.md index 59fea6bcd0..106598b36b 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-return-in-scope.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-cond-deps-return-in-scope.expect.md @@ -31,33 +31,34 @@ import { c as _c } from "react/compiler-runtime"; function useFoo(t0) { const $ = _c(4); const { obj, objIsNull } = t0; - let x; let t1; + let t2; if ($[0] !== objIsNull || $[1] !== obj) { - t1 = Symbol.for("react.early_return_sentinel"); + t2 = Symbol.for("react.early_return_sentinel"); bb0: { - x = []; + const x = []; if (objIsNull) { - t1 = undefined; + t2 = undefined; break bb0; } else { x.push(obj.a); } + t1 = x; x.push(obj.b); } $[0] = objIsNull; $[1] = obj; - $[2] = x; - $[3] = t1; + $[2] = t1; + $[3] = t2; } else { - x = $[2]; - t1 = $[3]; + t1 = $[2]; + t2 = $[3]; } - if (t1 !== Symbol.for("react.early_return_sentinel")) { - return t1; + if (t2 !== Symbol.for("react.early_return_sentinel")) { + return t2; } - return x; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/conditional-member-expr.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/conditional-member-expr.expect.md index be2c1c49cb..9b99d254ee 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/conditional-member-expr.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/conditional-member-expr.expect.md @@ -28,16 +28,18 @@ import { c as _c } from "react/compiler-runtime"; // To preserve the nullthrows function Component(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props.a) { - x = []; + const x = []; + + t0 = x; x.push(props.a?.b); $[0] = props.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/reduce-reactive-deps/jump-poisoned/return-in-scope.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-in-scope.expect.md index 258155e11c..29feb0e40c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-in-scope.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-in-scope.expect.md @@ -33,31 +33,32 @@ import { c as _c } from "react/compiler-runtime"; function useFoo(t0) { const $ = _c(4); const { obj, objIsNull } = t0; - let x; let t1; + let t2; if ($[0] !== objIsNull || $[1] !== obj) { - t1 = Symbol.for("react.early_return_sentinel"); + t2 = Symbol.for("react.early_return_sentinel"); bb0: { - x = []; + const x = []; if (objIsNull) { - t1 = undefined; + t2 = undefined; break bb0; } + t1 = x; x.push(obj.b); } $[0] = objIsNull; $[1] = obj; - $[2] = x; - $[3] = t1; + $[2] = t1; + $[3] = t2; } else { - x = $[2]; - t1 = $[3]; + t1 = $[2]; + t2 = $[3]; } - if (t1 !== Symbol.for("react.early_return_sentinel")) { - return t1; + if (t2 !== Symbol.for("react.early_return_sentinel")) { + return t2; } - return x; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-poisons-outer-scope.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-poisons-outer-scope.expect.md index 5c41853c5d..39e776ca87 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-poisons-outer-scope.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-poisoned/return-poisons-outer-scope.expect.md @@ -39,38 +39,40 @@ import { identity } from "shared-runtime"; function useFoo(t0) { const $ = _c(6); const { input, cond } = t0; - let x; let t1; + let t2; if ($[0] !== cond || $[1] !== input) { - t1 = Symbol.for("react.early_return_sentinel"); + t2 = Symbol.for("react.early_return_sentinel"); bb0: { - x = []; + const x = []; if (cond) { - t1 = null; + t2 = null; break bb0; } - let t2; + + t1 = x; + let t3; if ($[4] !== input.a.b) { - t2 = identity(input.a.b); + t3 = identity(input.a.b); $[4] = input.a.b; - $[5] = t2; + $[5] = t3; } else { - t2 = $[5]; + t3 = $[5]; } - x.push(t2); + x.push(t3); } $[0] = cond; $[1] = input; - $[2] = x; - $[3] = t1; + $[2] = t1; + $[3] = t2; } else { - x = $[2]; - t1 = $[3]; + t1 = $[2]; + t2 = $[3]; } - if (t1 !== Symbol.for("react.early_return_sentinel")) { - return t1; + if (t2 !== Symbol.for("react.early_return_sentinel")) { + return t2; } - return x; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-label.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-label.expect.md index 65fd8710ed..f9fd27f1d4 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-label.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-label.expect.md @@ -37,21 +37,22 @@ import { c as _c } from "react/compiler-runtime"; function useFoo(t0) { const $ = _c(3); const { input, cond } = t0; - let x; + let t1; if ($[0] !== cond || $[1] !== input.a.b) { - x = []; + const x = []; bb0: if (cond) { break bb0; } + t1 = x; x.push(input.a.b); $[0] = cond; $[1] = input.a.b; - $[2] = x; + $[2] = t1; } else { - x = $[2]; + t1 = $[2]; } - return x; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-loop-break.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-loop-break.expect.md index 97142a36f4..c3c080a243 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-loop-break.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/jump-target-within-scope-loop-break.expect.md @@ -39,9 +39,9 @@ import { c as _c } from "react/compiler-runtime"; function useFoo(t0) { const $ = _c(3); const { input, max } = t0; - let x; + let t1; if ($[0] !== max || $[1] !== input.a.b) { - x = []; + const x = []; let i = 0; while (true) { i = i + 1; @@ -50,15 +50,16 @@ function useFoo(t0) { } } + t1 = x; x.push(i); x.push(input.a.b); $[0] = max; $[1] = input.a.b; - $[2] = x; + $[2] = t1; } else { - x = $[2]; + t1 = $[2]; } - return x; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/return-before-scope-starts.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/return-before-scope-starts.expect.md index 5edc13dead..c95da73e8f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/return-before-scope-starts.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/return-before-scope-starts.expect.md @@ -51,16 +51,18 @@ function useFoo(t0) { } return t1; } - let x; + let t1; if ($[1] !== input.a.b) { - x = []; + const x = []; + + t1 = x; arrayPush(x, input.a.b); $[1] = input.a.b; - $[2] = x; + $[2] = t1; } else { - x = $[2]; + t1 = $[2]; } - return x; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/throw-before-scope-starts.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/throw-before-scope-starts.expect.md index 5751d26c94..8f638ac9fa 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/throw-before-scope-starts.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/jump-unpoisoned/throw-before-scope-starts.expect.md @@ -44,16 +44,18 @@ function useFoo(t0) { if (cond) { throw new Error("throw with error!"); } - let x; + let t1; if ($[0] !== input.a.b) { - x = []; + const x = []; + + t1 = x; arrayPush(x, input.a.b); $[0] = input.a.b; - $[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/reduce-reactive-deps/memberexpr-join-optional-chain.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/memberexpr-join-optional-chain.expect.md index fcb9926c22..069a4e47b4 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/memberexpr-join-optional-chain.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/memberexpr-join-optional-chain.expect.md @@ -43,17 +43,19 @@ import { c as _c } from "react/compiler-runtime"; // To preserve the nullthrows function Component(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props.a) { - x = []; + const x = []; + + t0 = x; x.push(props.a?.b); x.push(props.a.b.c); $[0] = props.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/reduce-reactive-deps/memberexpr-join-optional-chain2.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/memberexpr-join-optional-chain2.expect.md index ad5dc911af..1247ef1ac7 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/memberexpr-join-optional-chain2.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/memberexpr-join-optional-chain2.expect.md @@ -22,17 +22,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.items) { - x = []; + const x = []; x.push(props.items?.length); + + t0 = x; x.push(props.items?.edges?.map?.(render)?.filter?.(Boolean) ?? []); $[0] = props.items; - $[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/reduce-reactive-deps/subpath-order2.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/subpath-order2.expect.md index 66239c1c56..a5bf4d3af9 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/subpath-order2.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/subpath-order2.expect.md @@ -39,21 +39,22 @@ import { identity } from "shared-runtime"; // ordering of accesses should not matter function useConditionalSubpath2(props, other) { const $ = _c(3); - let x; + let t0; if ($[0] !== other || $[1] !== props.a) { - x = {}; + const x = {}; if (identity(other)) { x.a = props.a; } + t0 = x; x.b = props.a.b; $[0] = other; $[1] = props.a; - $[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/reduce-reactive-deps/superpath-order2.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/superpath-order2.expect.md index 86d435d4cc..21ec0568da 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/superpath-order2.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/superpath-order2.expect.md @@ -47,21 +47,22 @@ import { identity } from "shared-runtime"; function useConditionalSuperpath2(t0) { const $ = _c(3); const { props, cond } = t0; - let x; + let t1; if ($[0] !== cond || $[1] !== props.a) { - x = {}; + const x = {}; if (identity(cond)) { x.b = props.a.b; } + t1 = x; x.a = props.a; $[0] = cond; $[1] = props.a; - $[2] = x; + $[2] = t1; } else { - x = $[2]; + t1 = $[2]; } - return x; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-nonoverlap-descendant.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-nonoverlap-descendant.expect.md index ffdc707d1f..c31b612d01 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-nonoverlap-descendant.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-nonoverlap-descendant.expect.md @@ -26,20 +26,22 @@ import { c as _c } from "react/compiler-runtime"; // Test that we can track non- // (not needed for correctness but for dependency granularity) function TestNonOverlappingDescendantTracked(props) { const $ = _c(4); - let x; + let t0; if ($[0] !== props.a.x.y || $[1] !== props.a.c.x.y.z || $[2] !== props.b) { - x = {}; + const x = {}; + + t0 = x; x.a = props.a.x.y; x.b = props.b; x.c = props.a.c.x.y.z; $[0] = props.a.x.y; $[1] = props.a.c.x.y.z; $[2] = props.b; - $[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/reduce-reactive-deps/uncond-nonoverlap-direct.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-nonoverlap-direct.expect.md index 21db959c98..4a1ff67932 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-nonoverlap-direct.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-nonoverlap-direct.expect.md @@ -25,18 +25,20 @@ import { c as _c } from "react/compiler-runtime"; // Test that we can track non- // (not needed for correctness but for dependency granularity) function TestNonOverlappingTracked(props) { const $ = _c(3); - let x; + let t0; if ($[0] !== props.a.b || $[1] !== props.a.c) { - x = {}; + const x = {}; + + t0 = x; x.b = props.a.b; x.c = props.a.c; $[0] = props.a.b; $[1] = props.a.c; - $[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/reduce-reactive-deps/uncond-overlap-descendant.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-overlap-descendant.expect.md index 13fa6d680e..9fcd9267fe 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-overlap-descendant.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-overlap-descendant.expect.md @@ -26,18 +26,20 @@ import { c as _c } from "react/compiler-runtime"; // Test that we correctly trac // a dependency function TestOverlappingDescendantTracked(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props.a) { - x = {}; + const x = {}; + + t0 = x; x.b = props.a.b.c; x.c = props.a.b.c.x.y; x.a = props.a; $[0] = props.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/reduce-reactive-deps/uncond-overlap-direct.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-overlap-direct.expect.md index d0f9d45fa7..5cc7588333 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-overlap-direct.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-overlap-direct.expect.md @@ -26,18 +26,20 @@ import { c as _c } from "react/compiler-runtime"; // Test that we correctly trac // a dependency function TestOverlappingTracked(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props.a) { - x = {}; + const x = {}; + + t0 = x; x.b = props.a.b; x.c = props.a.c; x.a = props.a; $[0] = props.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/reduce-reactive-deps/uncond-subpath-order1.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-subpath-order1.expect.md index a2855ad305..b881a1cd79 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-subpath-order1.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-subpath-order1.expect.md @@ -26,18 +26,20 @@ import { c as _c } from "react/compiler-runtime"; // Determine that we only need // Ordering of access should not matter function TestDepsSubpathOrder1(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props.a) { - x = {}; + const x = {}; + + t0 = x; x.b = props.a.b; x.a = props.a; x.c = props.a.b.c; $[0] = props.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/reduce-reactive-deps/uncond-subpath-order2.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-subpath-order2.expect.md index c731aeb907..77ff54c0f1 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-subpath-order2.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-subpath-order2.expect.md @@ -26,18 +26,20 @@ import { c as _c } from "react/compiler-runtime"; // Determine that we only need // Ordering of access should not matter function TestDepsSubpathOrder2(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props.a) { - x = {}; + const x = {}; + + t0 = x; x.a = props.a; x.b = props.a.b; x.c = props.a.b.c; $[0] = props.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/reduce-reactive-deps/uncond-subpath-order3.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-subpath-order3.expect.md index bd9df044ec..30bcdd6b80 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-subpath-order3.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reduce-reactive-deps/uncond-subpath-order3.expect.md @@ -26,18 +26,20 @@ import { c as _c } from "react/compiler-runtime"; // Determine that we only need // Ordering of access should not matter function TestDepsSubpathOrder3(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props.a) { - x = {}; + const x = {}; + + t0 = x; x.c = props.a.b.c; x.a = props.a; x.b = props.a.b; $[0] = props.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/ref-in-effect.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ref-in-effect.expect.md index d3c033aed4..1a41c0a2c2 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ref-in-effect.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ref-in-effect.expect.md @@ -35,24 +35,24 @@ function Component(props) { } const onChange = t0; let t1; - if ($[1] === Symbol.for("react.memo_cache_sentinel")) { - t1 = () => { + if ($[1] !== onChange) { + t1 = ; + $[1] = onChange; + $[2] = t1; + } else { + t1 = $[2]; + } + let t2; + if ($[3] === Symbol.for("react.memo_cache_sentinel")) { + t2 = () => { console.log(ref.current); }; - $[1] = t1; - } else { - t1 = $[1]; - } - useEffect(t1); - let t2; - if ($[2] !== onChange) { - t2 = ; - $[2] = onChange; $[3] = t2; } else { t2 = $[3]; } - return t2; + useEffect(t2); + return t1; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-renaming-conflicting-decls.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-renaming-conflicting-decls.expect.md index 686752f9fd..38ae15a47f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-renaming-conflicting-decls.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-renaming-conflicting-decls.expect.md @@ -46,7 +46,7 @@ import { Stringify, identity, makeArray, toJSON } from "shared-runtime"; import { useMemo } from "react"; function Component(props) { - const $ = _c(13); + const $ = _c(15); let t0; let t1; let t2; @@ -84,49 +84,56 @@ function Component(props) { } const linkProps = t3; let t4; - if ($[6] !== linkProps) { + let t5; + let t6; + let t7; + let t8; + let t9; + if ($[6] === Symbol.for("react.memo_cache_sentinel")) { const x = {}; - let t5; - let t6; - let t7; - let t8; - let t9; - if ($[8] === Symbol.for("react.memo_cache_sentinel")) { - t5 = [1]; - t6 = [2]; - t7 = [3]; - t8 = [4]; - t9 = [5]; - $[8] = t5; - $[9] = t6; - $[10] = t7; - $[11] = t8; - $[12] = t9; - } else { - t5 = $[8]; - t6 = $[9]; - t7 = $[10]; - t8 = $[11]; - t9 = $[12]; - } - t4 = ( + + t4 = [1]; + t5 = [2]; + t6 = [3]; + t7 = [4]; + t8 = [5]; + + t9 = makeArray(x, 2); + $[6] = t4; + $[7] = t5; + $[8] = t6; + $[9] = t7; + $[10] = t8; + $[11] = t9; + } else { + t4 = $[6]; + t5 = $[7]; + t6 = $[8]; + t7 = $[9]; + t8 = $[10]; + t9 = $[11]; + } + let t10; + if ($[12] !== linkProps || $[13] !== t9) { + t10 = ( - {makeArray(x, 2)} + {t9} ); - $[6] = linkProps; - $[7] = t4; + $[12] = linkProps; + $[13] = t9; + $[14] = t10; } else { - t4 = $[7]; + t10 = $[14]; } - return t4; + return t10; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/resolve-react-hooks-based-on-import-name.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/resolve-react-hooks-based-on-import-name.expect.md index 787c957ca4..09ee719ad9 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/resolve-react-hooks-based-on-import-name.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/resolve-react-hooks-based-on-import-name.expect.md @@ -33,39 +33,33 @@ import { c as _c } from "react/compiler-runtime"; import { useState as useReactState } from "react"; function Component() { - const $ = _c(4); + const $ = _c(3); const [state, setState] = useReactState(0); let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - t0 = () => { + const onClick = () => { setState((s) => s + 1); }; + + t0 = ; $[0] = t0; } else { t0 = $[0]; } - const onClick = t0; let t1; - if ($[1] === Symbol.for("react.memo_cache_sentinel")) { - t1 = ; - $[1] = t1; - } else { - t1 = $[1]; - } - let t2; - if ($[2] !== state) { - t2 = ( + if ($[1] !== state) { + t1 = ( <> Count {state} - {t1} + {t0} ); - $[2] = state; - $[3] = t2; + $[1] = state; + $[2] = t1; } else { - t2 = $[3]; + t1 = $[2]; } - return t2; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/simple-alias.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/simple-alias.expect.md index 8e4e6a61e6..dee6ee9a40 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/simple-alias.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/simple-alias.expect.md @@ -24,21 +24,23 @@ function mutate() {} function foo() { const $ = _c(2); let a; - let c; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { let b = {}; - c = {}; + let c = {}; a = b; b = c; c = a; + + t0 = c; mutate(a, b); - $[0] = c; + $[0] = t0; $[1] = a; } else { - c = $[0]; + t0 = $[0]; a = $[1]; } - return c; + return t0; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-call-jsx-2.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-call-jsx-2.expect.md index 530153679a..e1cced745c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-call-jsx-2.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-call-jsx-2.expect.md @@ -34,8 +34,8 @@ function Component(props) { if (foo()) { } - foo(a, b); t0 =
; + foo(a, b); $[0] = t0; } else { t0 = $[0]; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-call-jsx.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-call-jsx.expect.md index 44e1e3ae76..759e7ceadb 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-call-jsx.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-call-jsx.expect.md @@ -27,10 +27,10 @@ function Component(props) { if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const a = []; const b = {}; - foo(a, b); - foo(a, b); t0 =
; + foo(a, b); + foo(a, b); $[0] = t0; } else { t0 = $[0]; diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.expect.md index 061aa03c08..533ca70732 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.expect.md @@ -33,9 +33,9 @@ import { c as _c } from "react/compiler-runtime"; function Component(props) { const $ = _c(4); let x = 0; - let values; + let t0; if ($[0] !== props || $[1] !== x) { - values = []; + const values = []; const y = props.a || props.b; values.push(y); if (props.c) { @@ -47,16 +47,17 @@ function Component(props) { x = 2; } + t0 = values; values.push(x); $[0] = props; $[1] = x; - $[2] = values; + $[2] = t0; $[3] = x; } else { - values = $[2]; + t0 = $[2]; x = $[3]; } - return values; + return t0; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-alias-alias-mutate-if.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-alias-alias-mutate-if.expect.md index 7e6f28953c..df57d4a6ea 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-alias-alias-mutate-if.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-alias-alias-mutate-if.expect.md @@ -24,10 +24,10 @@ function foo(a) { import { c as _c } from "react/compiler-runtime"; function foo(a) { const $ = _c(2); - let x; + let t0; if ($[0] !== a) { const b = {}; - x = b; + const x = b; if (a) { const y = {}; x.y = y; @@ -36,13 +36,14 @@ function foo(a) { x.z = z; } + t0 = x; mutate(b); $[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/ssa-property-alias-mutate-if.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-alias-mutate-if.expect.md index d303dedec2..691ef9283a 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-alias-mutate-if.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-alias-mutate-if.expect.md @@ -23,9 +23,9 @@ function foo(a) { import { c as _c } from "react/compiler-runtime"; function foo(a) { const $ = _c(2); - let x; + let t0; if ($[0] !== a) { - x = {}; + const x = {}; if (a) { const y = {}; x.y = y; @@ -34,13 +34,14 @@ function foo(a) { x.z = z; } + t0 = x; mutate(x); $[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/ssa-property-alias-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-alias-mutate.expect.md index ae0daf1213..dfc5f11976 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-alias-mutate.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-alias-mutate.expect.md @@ -21,20 +21,21 @@ function foo() { import { c as _c } from "react/compiler-runtime"; function foo() { const $ = _c(1); - let y; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const a = {}; const x = a; - y = {}; - y.x = x; + const y = {}; + t0 = y; + y.x = x; mutate(a); - $[0] = y; + $[0] = t0; } else { - y = $[0]; + t0 = $[0]; } - return y; + return t0; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-call.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-call.expect.md index b4bab7cfb9..29732b6f67 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-call.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-call.expect.md @@ -23,16 +23,18 @@ export const FIXTURE_ENTRYPOINT = { import { c as _c } from "react/compiler-runtime"; function foo() { const $ = _c(1); - let y; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const x = []; - y = { x }; + const y = { x }; + + t0 = y; y.x.push([]); - $[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/ssa-property-mutate-2.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-mutate-2.expect.md index 3709a298cb..e1ae7b6d26 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-mutate-2.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-mutate-2.expect.md @@ -18,17 +18,19 @@ function foo() { import { c as _c } from "react/compiler-runtime"; function foo() { const $ = _c(1); - let y; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const x = []; - y = {}; + const y = {}; + + t0 = y; y.x = x; mutate(x); - $[0] = y; + $[0] = t0; } else { - y = $[0]; + t0 = $[0]; } - return y; + return t0; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-mutate-alias.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-mutate-alias.expect.md index f01d01f63b..33dada441d 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-mutate-alias.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-mutate-alias.expect.md @@ -21,20 +21,20 @@ function foo() { import { c as _c } from "react/compiler-runtime"; function foo() { const $ = _c(1); - let y; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const a = {}; - y = a; + const y = a; + + t0 = y; const x = []; - y.x = x; - mutate(a); - $[0] = y; + $[0] = t0; } else { - y = $[0]; + t0 = $[0]; } - return y; + return t0; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-mutate.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-mutate.expect.md index 46f974ef42..daa4c2c096 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-mutate.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property-mutate.expect.md @@ -18,17 +18,19 @@ function foo() { import { c as _c } from "react/compiler-runtime"; function foo() { const $ = _c(1); - let y; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const x = []; - y = {}; + const y = {}; + + t0 = y; y.x = x; mutate(y); - $[0] = y; + $[0] = t0; } else { - y = $[0]; + t0 = $[0]; } - return y; + return t0; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property.expect.md index 565313fc0d..1ca3d8c72f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-property.expect.md @@ -23,16 +23,18 @@ export const FIXTURE_ENTRYPOINT = { import { c as _c } from "react/compiler-runtime"; function foo() { const $ = _c(1); - let y; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { const x = []; - y = {}; + const y = {}; + + t0 = y; y.x = x; - $[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/ssa-renaming-ternary-destruction-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md index 11d328201e..0250927df9 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md @@ -18,18 +18,20 @@ function foo(props) { import { c as _c } from "react/compiler-runtime"; function foo(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props) { - x = []; + let x = []; x.push(props.bar); props.cond ? (([x] = [[]]), x.push(props.foo)) : null; + + t0 = x; mut(x); $[0] = props; - $[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/ssa-renaming-ternary-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md index 3ec90ca887..263e3428aa 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md @@ -18,18 +18,20 @@ function foo(props) { import { c as _c } from "react/compiler-runtime"; function foo(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props) { - x = []; + let x = []; x.push(props.bar); props.cond ? ((x = []), x.push(props.foo)) : null; + + t0 = x; mut(x); $[0] = props; - $[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/ssa-renaming-unconditional-ternary-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md index 598d9677aa..a56211b41c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md @@ -32,18 +32,20 @@ import { c as _c } from "react/compiler-runtime"; import { arrayPush } from "shared-runtime"; function foo(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props) { - x = []; + let x = []; x.push(props.bar); props.cond ? ((x = []), x.push(props.foo)) : ((x = []), x.push(props.bar)); + + t0 = x; arrayPush(x, 4); $[0] = props; - $[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/ssa-renaming-unconditional-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.expect.md index e27e00db70..cf4ddc6e05 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.expect.md @@ -26,9 +26,9 @@ function foo(props) { import { c as _c } from "react/compiler-runtime"; function foo(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props) { - x = []; + let x = []; x.push(props.bar); if (props.cond) { x = []; @@ -38,13 +38,14 @@ function foo(props) { x.push(props.bar); } + t0 = x; mut(x); $[0] = props; - $[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/ssa-renaming-via-destructuring-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.expect.md index b202302d65..1b1d3cd76b 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.expect.md @@ -22,22 +22,23 @@ function foo(props) { import { c as _c } from "react/compiler-runtime"; function foo(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props) { - ({ x } = { x: [] }); + let { x } = { x: [] }; x.push(props.bar); if (props.cond) { ({ x } = { x: [] }); x.push(props.foo); } + t0 = x; mut(x); $[0] = props; - $[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/ssa-renaming-with-mutation.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.expect.md index 76ccbae06a..4687acb610 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.expect.md @@ -22,22 +22,23 @@ function foo(props) { import { c as _c } from "react/compiler-runtime"; function foo(props) { const $ = _c(2); - let x; + let t0; if ($[0] !== props) { - x = []; + let x = []; x.push(props.bar); if (props.cond) { x = []; x.push(props.foo); } + t0 = x; mut(x); $[0] = props; - $[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/store-via-call.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/store-via-call.expect.md index 31bb71ca02..af9f891777 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/store-via-call.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/store-via-call.expect.md @@ -17,16 +17,18 @@ function foo() { import { c as _c } from "react/compiler-runtime"; function foo() { const $ = _c(1); - let x; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - x = {}; + const x = {}; + + t0 = x; const y = foo(x); y.mutate(); - $[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/store-via-new.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/store-via-new.expect.md index 2d7b0d455e..d1e81cc22f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/store-via-new.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/store-via-new.expect.md @@ -17,16 +17,18 @@ function Foo() { import { c as _c } from "react/compiler-runtime"; function Foo() { const $ = _c(1); - let x; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - x = {}; + const x = {}; + + t0 = x; const y = new Foo(x); y.mutate(); - $[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/switch-non-final-default.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/switch-non-final-default.expect.md index 915218fcfa..55be13256c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/switch-non-final-default.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/switch-non-final-default.expect.md @@ -70,7 +70,6 @@ function Component(props) { t0 = $[2]; } const child = t0; - y.push(props.p4); let t1; if ($[4] !== y || $[5] !== child) { t1 = {child}; @@ -80,6 +79,7 @@ function Component(props) { } else { t1 = $[6]; } + y.push(props.p4); return t1; } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/switch.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/switch.expect.md index 0c5aea9c7d..b77ad1d91f 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/switch.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/switch.expect.md @@ -52,7 +52,6 @@ function Component(props) { t0 = $[2]; } const child = t0; - y.push(props.p4); let t1; if ($[3] !== y || $[4] !== child) { t1 = {child}; @@ -62,6 +61,7 @@ function Component(props) { } else { t1 = $[5]; } + y.push(props.p4); return t1; } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/temporary-accessed-outside-scope.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/temporary-accessed-outside-scope.expect.md index 0ea366c161..05195a76fa 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/temporary-accessed-outside-scope.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/temporary-accessed-outside-scope.expect.md @@ -16,30 +16,29 @@ function Component(props) { import { c as _c } from "react/compiler-runtime"; function Component(props) { const $ = _c(6); + let x; let t0; - let t1; if ($[0] !== props) { const maybeMutable = new MaybeMutable(); - const x = props; - t0 = x; - t1 = maybeMutate(maybeMutable); + x = props; + t0 = maybeMutate(maybeMutable); $[0] = props; - $[1] = t0; - $[2] = t1; + $[1] = x; + $[2] = t0; } else { - t0 = $[1]; - t1 = $[2]; + x = $[1]; + t0 = $[2]; } - let t2; - if ($[3] !== t0 || $[4] !== t1) { - t2 = [t0, t1]; - $[3] = t0; - $[4] = t1; - $[5] = t2; + let t1; + if ($[3] !== x || $[4] !== t0) { + t1 = [x, t0]; + $[3] = x; + $[4] = t0; + $[5] = t1; } else { - t2 = $[5]; + t1 = $[5]; } - return t2; + return t1; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/temporary-property-load-accessed-outside-scope.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/temporary-property-load-accessed-outside-scope.expect.md index 1aebc80b27..2495bc3b69 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/temporary-property-load-accessed-outside-scope.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/temporary-property-load-accessed-outside-scope.expect.md @@ -16,30 +16,29 @@ function Component(props) { import { c as _c } from "react/compiler-runtime"; function Component(props) { const $ = _c(6); + let x; let t0; - let t1; if ($[0] !== props.value) { const maybeMutable = new MaybeMutable(); - const x = props.value; - t0 = x; - t1 = maybeMutate(maybeMutable); + x = props.value; + t0 = maybeMutate(maybeMutable); $[0] = props.value; - $[1] = t0; - $[2] = t1; + $[1] = x; + $[2] = t0; } else { - t0 = $[1]; - t1 = $[2]; + x = $[1]; + t0 = $[2]; } - let t2; - if ($[3] !== t0 || $[4] !== t1) { - t2 = [t0, t1]; - $[3] = t0; - $[4] = t1; - $[5] = t2; + let t1; + if ($[3] !== x || $[4] !== t0) { + t1 = [x, t0]; + $[3] = x; + $[4] = t0; + $[5] = t1; } else { - t2 = $[5]; + t1 = $[5]; } - return t2; + return t1; } ``` diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/todo-function-expression-captures-value-later-frozen.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/todo-function-expression-captures-value-later-frozen.expect.md index 9f8fed44f0..3e1e209899 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/todo-function-expression-captures-value-later-frozen.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/todo-function-expression-captures-value-later-frozen.expect.md @@ -35,8 +35,8 @@ function Component(props) { if (props.cond) { } - onChange(); t0 = ; + onChange(); $[0] = props.cond; $[1] = t0; } else { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-alias-try-values.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-alias-try-values.expect.md index afae9ba9d7..5eb1804d16 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-alias-try-values.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-alias-try-values.expect.md @@ -33,24 +33,25 @@ const { throwInput } = require("shared-runtime"); function Component(props) { const $ = _c(1); - let x; + let t0; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { let y; - x = []; + const x = []; try { throwInput(x); - } catch (t0) { - const e = t0; + } catch (t1) { + const e = t1; y = e; } + t0 = x; y.push(null); - $[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/try-catch-in-nested-scope.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-in-nested-scope.expect.md index ccbcae1636..b9c25a3d86 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-in-nested-scope.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-in-nested-scope.expect.md @@ -40,46 +40,40 @@ import { c as _c } from "react/compiler-runtime"; import { mutate, setProperty, throwErrorWithMessageIf } from "shared-runtime"; function useFoo(t0) { - const $ = _c(6); + const $ = _c(4); const { value, cond } = t0; - let y; let t1; + let t2; if ($[0] !== value || $[1] !== cond) { - t1 = Symbol.for("react.early_return_sentinel"); + t2 = Symbol.for("react.early_return_sentinel"); bb0: { - y = [value]; - let x; - if ($[4] !== cond) { - x = { cond }; - try { - mutate(x); - throwErrorWithMessageIf(x.cond, "error"); - } catch { - setProperty(x, "henderson"); - t1 = x; - break bb0; - } - - setProperty(x, "nevada"); - $[4] = cond; - $[5] = x; - } else { - x = $[5]; + const y = [value]; + const x = { cond }; + try { + mutate(x); + throwErrorWithMessageIf(x.cond, "error"); + } catch { + setProperty(x, "henderson"); + t2 = x; + break bb0; } + + t1 = y; + setProperty(x, "nevada"); y.push(x); } $[0] = value; $[1] = cond; - $[2] = y; - $[3] = t1; + $[2] = t1; + $[3] = t2; } else { - y = $[2]; - t1 = $[3]; + t1 = $[2]; + t2 = $[3]; } - if (t1 !== Symbol.for("react.early_return_sentinel")) { - return t1; + if (t2 !== Symbol.for("react.early_return_sentinel")) { + return t2; } - return y; + return t1; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-within-mutable-range.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-within-mutable-range.expect.md index 1a1b048ab7..5aa81d1829 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-within-mutable-range.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/try-catch-within-mutable-range.expect.md @@ -30,36 +30,37 @@ const { throwErrorWithMessage, shallowCopy } = require("shared-runtime"); function Component(props) { const $ = _c(4); - let x; + let t0; if ($[0] !== props.value) { - x = []; + const x = []; try { - let t0; + let t1; if ($[2] === Symbol.for("react.memo_cache_sentinel")) { - t0 = throwErrorWithMessage("oops"); - $[2] = t0; + t1 = throwErrorWithMessage("oops"); + $[2] = t1; } else { - t0 = $[2]; + t1 = $[2]; } - x.push(t0); + x.push(t1); } catch { - let t0; + let t1; if ($[3] === Symbol.for("react.memo_cache_sentinel")) { - t0 = shallowCopy({}); - $[3] = t0; + t1 = shallowCopy({}); + $[3] = t1; } else { - t0 = $[3]; + t1 = $[3]; } - x.push(t0); + x.push(t1); } + 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/unmemoized-nonreactive-dependency-is-pruned-as-dependency.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/unmemoized-nonreactive-dependency-is-pruned-as-dependency.expect.md index cc829c9190..96ac447902 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/unmemoized-nonreactive-dependency-is-pruned-as-dependency.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/unmemoized-nonreactive-dependency-is-pruned-as-dependency.expect.md @@ -25,23 +25,13 @@ export const FIXTURE_ENTRYPOINT = { ## Code ```javascript -import { c as _c } from "react/compiler-runtime"; import { mutate, useNoAlias } from "shared-runtime"; function Component(props) { - const $ = _c(1); - const x = []; useNoAlias(); mutate(x); - let t0; - if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - t0 =
{x}
; - $[0] = t0; - } else { - t0 = $[0]; - } - return t0; + return
{x}
; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-call-second-function-which-captures-maybe-mutable-value-dont-preserve-memoization.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-call-second-function-which-captures-maybe-mutable-value-dont-preserve-memoization.expect.md index b43bac8f7d..bb680e5839 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-call-second-function-which-captures-maybe-mutable-value-dont-preserve-memoization.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-call-second-function-which-captures-maybe-mutable-value-dont-preserve-memoization.expect.md @@ -39,7 +39,7 @@ export const FIXTURE_ENTRYPOINT = { ## Code ```javascript -import { c as _c } from "react/compiler-runtime"; // @enablePreserveExistingMemoizationGuarantees:false @enableTransitivelyFreezeFunctionExpressions:false +// @enablePreserveExistingMemoizationGuarantees:false @enableTransitivelyFreezeFunctionExpressions:false import { useCallback } from "react"; import { identity, @@ -49,7 +49,6 @@ import { } from "shared-runtime"; function Component(props) { - const $ = _c(1); const object = makeObject_Primitives(); useHook(); @@ -63,14 +62,7 @@ function Component(props) { }; identity(object); - let t0; - if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - t0 =
; - $[0] = t0; - } else { - t0 = $[0]; - } - return t0; + return
; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-call-second-function-which-captures-maybe-mutable-value-preserve-memoization.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-call-second-function-which-captures-maybe-mutable-value-preserve-memoization.expect.md index 16639d3844..f74f53286c 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-call-second-function-which-captures-maybe-mutable-value-preserve-memoization.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-call-second-function-which-captures-maybe-mutable-value-preserve-memoization.expect.md @@ -80,8 +80,6 @@ function Component(props) { t2 = $[2]; } const onClick = t2; - - identity(object); let t3; if ($[3] === Symbol.for("react.memo_cache_sentinel")) { t3 =
; @@ -89,6 +87,7 @@ function Component(props) { } else { t3 = $[3]; } + identity(object); return t3; } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-set-ref-nested-property-dont-preserve-memoization.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-set-ref-nested-property-dont-preserve-memoization.expect.md index 2e469a824b..1ac85b5df2 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-set-ref-nested-property-dont-preserve-memoization.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useCallback-set-ref-nested-property-dont-preserve-memoization.expect.md @@ -46,8 +46,6 @@ function Component(props) { const onChange = (event) => { ref.current.inner = event.target.value; }; - - ref.current.inner = null; let t1; if ($[1] !== onChange) { t1 = ; @@ -56,6 +54,7 @@ function Component(props) { } else { t1 = $[2]; } + ref.current.inner = null; return t1; } diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useEffect-snap-test.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useEffect-snap-test.expect.md index 930302faec..1e2ed4abd4 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useEffect-snap-test.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useEffect-snap-test.expect.md @@ -30,28 +30,28 @@ function Component() { const $ = _c(4); const [state, setState] = useState("hello"); let t0; + if ($[0] !== state) { + t0 =
{state}
; + $[0] = state; + $[1] = t0; + } else { + t0 = $[1]; + } let t1; - if ($[0] === Symbol.for("react.memo_cache_sentinel")) { - t0 = () => { + let t2; + if ($[2] === Symbol.for("react.memo_cache_sentinel")) { + t1 = () => { setState("goodbye"); }; - t1 = []; - $[0] = t0; - $[1] = t1; - } else { - t0 = $[0]; - t1 = $[1]; - } - useEffect(t0, t1); - let t2; - if ($[2] !== state) { - t2 =
{state}
; - $[2] = state; + t2 = []; + $[2] = t1; $[3] = t2; } else { + t1 = $[2]; t2 = $[3]; } - return t2; + useEffect(t1, t2); + return t0; } export const FIXTURE_ENTRYPOINT = { diff --git a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-maybe-modified-later-dont-preserve-memoization-guarantees.expect.md b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-maybe-modified-later-dont-preserve-memoization-guarantees.expect.md index c033932b31..0381421782 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-maybe-modified-later-dont-preserve-memoization-guarantees.expect.md +++ b/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-maybe-modified-later-dont-preserve-memoization-guarantees.expect.md @@ -29,18 +29,20 @@ import { identity, makeObject_Primitives, mutate } from "shared-runtime"; function Component(props) { const $ = _c(2); let t0; - let object; + let t1; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { t0 = makeObject_Primitives(); - object = t0; + const object = t0; + + t1 = object; identity(object); - $[0] = object; + $[0] = t1; $[1] = t0; } else { - object = $[0]; + t1 = $[0]; t0 = $[1]; } - return object; + return t1; } export const FIXTURE_ENTRYPOINT = {