@samitouri / QOS-React-1 / commits / 956d770adf

[compiler] Improve IIFE inlining (#33726)

We currently inline IIFEs by creating a temporary and a labeled block w the original code. The original return statements turn into an assignment to the temporary and break out of the label. However, many cases of IIFEs are due to inlining of manual `useMemo()`, and these cases often have only a single return statement. Here, the output is cleaner if we avoid the temporary and label - so that's what we do in this PR. Note that the most complex part of the change is actually around ValidatePreserveExistingMemo - we have some logic to track the IIFE temporary reassignmetns which needs to be updated to handle the simpler version of inlining. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33726). * __->__ #33726 * #33725

Joseph Savona committed Jul 8, 2025 at 19:36 UTC 956d770adf59e1f8a00a7b7c52b5727ef9e353e7
93 files changed +1126 -1269
compiler/packages/babel-plugin-react-compiler/src/HIR/PrintHIR.ts
+1 -1
@@ -715,7 +715,7 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
715 break;
716 }
717 case 'FinishMemoize': {
718 - value = `FinishMemoize decl=${printPlace(instrValue.decl)}`;
718 + value = `FinishMemoize decl=${printPlace(instrValue.decl)}${instrValue.pruned ? ' pruned' : ''}`;
719 break;
720 }
721 default: {
compiler/packages/babel-plugin-react-compiler/src/Inference/InlineImmediatelyInvokedFunctionExpressions.ts
+88 -28
@@ -11,6 +11,7 @@ import {
11 Environment,
12 FunctionExpression,
13 GeneratedSource,
14 + GotoTerminal,
15 GotoVariant,
16 HIRFunction,
17 IdentifierId,
@@ -19,6 +20,7 @@ import {
20 Place,
21 isStatementBlockKind,
22 makeInstructionId,
23 + mergeConsecutiveBlocks,
24 promoteTemporary,
25 reversePostorderBlocks,
26 } from '../HIR';
@@ -73,6 +75,10 @@ import {retainWhere} from '../Utils/utils';
75 * - All return statements in the original function expression are replaced with a
76 * StoreLocal to the temporary we allocated before plus a Goto to the fallthrough
77 * block (code following the CallExpression).
78 + *
79 + * Note that if the inliined function has only one return, we avoid the labeled block
80 + * and fully inline the code. The original return is replaced with an assignmen to the
81 + * IIFE's call expression lvalue.
82 */
83 export function inlineImmediatelyInvokedFunctionExpressions(
84 fn: HIRFunction,
@@ -146,37 +152,75 @@ export function inlineImmediatelyInvokedFunctionExpressions(
152 */
153 block.instructions.length = ii;
154
149 - /*
150 - * To account for complex control flow within the lambda, we treat the lambda
151 - * as if it were a single labeled statement, and replace all returns with gotos
152 - * to the label fallthrough.
153 - */
154 - const newTerminal: LabelTerminal = {
155 - block: body.loweredFunc.func.body.entry,
156 - id: makeInstructionId(0),
157 - kind: 'label',
158 - fallthrough: continuationBlockId,
159 - loc: block.terminal.loc,
160 - };
161 - block.terminal = newTerminal;
155 + if (hasSingleExitReturnTerminal(body.loweredFunc.func)) {
156 + block.terminal = {
157 + kind: 'goto',
158 + block: body.loweredFunc.func.body.entry,
159 + id: block.terminal.id,
160 + loc: block.terminal.loc,
161 + variant: GotoVariant.Break,
162 + } as GotoTerminal;
163 + for (const block of body.loweredFunc.func.body.blocks.values()) {
164 + if (block.terminal.kind === 'return') {
165 + block.instructions.push({
166 + id: makeInstructionId(0),
167 + loc: block.terminal.loc,
168 + lvalue: instr.lvalue,
169 + value: {
170 + kind: 'LoadLocal',
171 + loc: block.terminal.loc,
172 + place: block.terminal.value,
173 + },
174 + effects: null,
175 + });
176 + block.terminal = {
177 + kind: 'goto',
178 + block: continuationBlockId,
179 + id: block.terminal.id,
180 + loc: block.terminal.loc,
181 + variant: GotoVariant.Break,
182 + } as GotoTerminal;
183 + }
184 + }
185 + for (const [id, block] of body.loweredFunc.func.body.blocks) {
186 + block.preds.clear();
187 + fn.body.blocks.set(id, block);
188 + }
189 + } else {
190 + /*
191 + * To account for multiple returns within the lambda, we treat the lambda
192 + * as if it were a single labeled statement, and replace all returns with gotos
193 + * to the label fallthrough.
194 + */
195 + const newTerminal: LabelTerminal = {
196 + block: body.loweredFunc.func.body.entry,
197 + id: makeInstructionId(0),
198 + kind: 'label',
199 + fallthrough: continuationBlockId,
200 + loc: block.terminal.loc,
201 + };
202 + block.terminal = newTerminal;
203
163 - // We store the result in the IIFE temporary
164 - const result = instr.lvalue;
204 + // We store the result in the IIFE temporary
205 + const result = instr.lvalue;
206
166 - // Declare the IIFE temporary
167 - declareTemporary(fn.env, block, result);
207 + // Declare the IIFE temporary
208 + declareTemporary(fn.env, block, result);
209
169 - // Promote the temporary with a name as we require this to persist
170 - promoteTemporary(result.identifier);
210 + // Promote the temporary with a name as we require this to persist
211 + if (result.identifier.name == null) {
212 + promoteTemporary(result.identifier);
213 + }
214
172 - /*
173 - * Rewrite blocks from the lambda to replace any `return` with a
174 - * store to the result and `goto` the continuation block
175 - */
176 - for (const [id, block] of body.loweredFunc.func.body.blocks) {
177 - block.preds.clear();
178 - rewriteBlock(fn.env, block, continuationBlockId, result);
179 - fn.body.blocks.set(id, block);
215 + /*
216 + * Rewrite blocks from the lambda to replace any `return` with a
217 + * store to the result and `goto` the continuation block
218 + */
219 + for (const [id, block] of body.loweredFunc.func.body.blocks) {
220 + block.preds.clear();
221 + rewriteBlock(fn.env, block, continuationBlockId, result);
222 + fn.body.blocks.set(id, block);
223 + }
224 }
225
226 /*
@@ -199,7 +243,7 @@ export function inlineImmediatelyInvokedFunctionExpressions(
243
244 if (inlinedFunctions.size !== 0) {
245 // Remove instructions that define lambdas which we inlined
202 - for (const [, block] of fn.body.blocks) {
246 + for (const block of fn.body.blocks.values()) {
247 retainWhere(
248 block.instructions,
249 instr => !inlinedFunctions.has(instr.lvalue.identifier.id),
@@ -213,7 +257,23 @@ export function inlineImmediatelyInvokedFunctionExpressions(
257 reversePostorderBlocks(fn.body);
258 markInstructionIds(fn.body);
259 markPredecessors(fn.body);
260 + mergeConsecutiveBlocks(fn);
261 + }
262 +}
263 +
264 +/**
265 + * Returns true if the function has a single exit terminal (throw/return) which is a return
266 + */
267 +function hasSingleExitReturnTerminal(fn: HIRFunction): boolean {
268 + let hasReturn = false;
269 + let exitCount = 0;
270 + for (const [, block] of fn.body.blocks) {
271 + if (block.terminal.kind === 'return' || block.terminal.kind === 'throw') {
272 + hasReturn ||= block.terminal.kind === 'return';
273 + exitCount++;
274 + }
275 }
276 + return exitCount === 1 && hasReturn;
277 }
278
279 /*
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/PruneNonEscapingScopes.ts
+17
@@ -1064,12 +1064,29 @@ class PruneScopesTransform extends ReactiveFunctionTransform<
1064
1065 const value = instruction.value;
1066 if (value.kind === 'StoreLocal' && value.lvalue.kind === 'Reassign') {
1067 + // Complex cases of useMemo inlining result in a temporary that is reassigned
1068 const ids = getOrInsertDefault(
1069 this.reassignments,
1070 value.lvalue.place.identifier.declarationId,
1071 new Set(),
1072 );
1073 ids.add(value.value.identifier);
1074 + } else if (
1075 + value.kind === 'LoadLocal' &&
1076 + value.place.identifier.scope != null &&
1077 + instruction.lvalue != null &&
1078 + instruction.lvalue.identifier.scope == null
1079 + ) {
1080 + /*
1081 + * Simpler cases result in a direct assignment to the original lvalue, with a
1082 + * LoadLocal
1083 + */
1084 + const ids = getOrInsertDefault(
1085 + this.reassignments,
1086 + instruction.lvalue.identifier.declarationId,
1087 + new Set(),
1088 + );
1089 + ids.add(value.place.identifier);
1090 } else if (value.kind === 'FinishMemoize') {
1091 let decls;
1092 if (value.decl.identifier.scope == null) {
compiler/packages/babel-plugin-react-compiler/src/Validation/ValidatePreservedManualMemoization.ts
+17
@@ -445,11 +445,13 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
445 */
446 this.recordTemporaries(instruction, state);
447 const value = instruction.value;
448 + // Track reassignments from inlining of manual memo
449 if (
450 value.kind === 'StoreLocal' &&
451 value.lvalue.kind === 'Reassign' &&
452 state.manualMemoState != null
453 ) {
454 + // Complex cases of inlining end up with a temporary that is reassigned
455 const ids = getOrInsertDefault(
456 state.manualMemoState.reassignments,
457 value.lvalue.place.identifier.declarationId,
@@ -457,6 +459,21 @@ class Visitor extends ReactiveFunctionVisitor<VisitorState> {
459 );
460 ids.add(value.value.identifier);
461 }
462 + if (
463 + value.kind === 'LoadLocal' &&
464 + value.place.identifier.scope != null &&
465 + instruction.lvalue != null &&
466 + instruction.lvalue.identifier.scope == null &&
467 + state.manualMemoState != null
468 + ) {
469 + // Simpler cases of inlining assign to the original IIFE lvalue
470 + const ids = getOrInsertDefault(
471 + state.manualMemoState.reassignments,
472 + instruction.lvalue.identifier.declarationId,
473 + new Set(),
474 + );
475 + ids.add(value.place.identifier);
476 + }
477 if (value.kind === 'StartMemoize') {
478 let depsFromSource: Array<ManualMemoDependency> | null = null;
479 if (value.deps != null) {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-iife-return-modified-later-logical.expect.md
+2 -6
@@ -26,20 +26,16 @@ import { c as _c } from "react/compiler-runtime";
26 import { getNull } from "shared-runtime";
27
28 function Component(props) {
29 - const $ = _c(3);
30 - let t0;
29 + const $ = _c(2);
30 let items;
31 if ($[0] !== props.a) {
33 - t0 = getNull() ?? [];
34 - items = t0;
32 + items = getNull() ?? [];
33
34 items.push(props.a);
35 $[0] = props.a;
36 $[1] = items;
39 - $[2] = t0;
37 } else {
38 items = $[1];
42 - t0 = $[2];
39 }
40 return items;
41 }
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/allow-modify-global-in-callback-jsx.expect.md
+3 -5
@@ -52,15 +52,13 @@ function Component(t0) {
52 }
53 const onClick = t1;
54 let t2;
55 - let t3;
55 if ($[2] !== onClick) {
57 - t3 = <div onClick={onClick}>{someGlobal.value}</div>;
56 + t2 = <div onClick={onClick}>{someGlobal.value}</div>;
57 $[2] = onClick;
59 - $[3] = t3;
58 + $[3] = t2;
59 } else {
61 - t3 = $[3];
60 + t2 = $[3];
61 }
63 - t2 = t3;
62 return t2;
63 }
64
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/babel-existing-react-import.expect.md
+16 -20
@@ -30,50 +30,46 @@ function Component(props) {
30 const $ = _c(4);
31 const [x] = useState(0);
32 let t0;
33 - let t1;
33 if ($[0] !== x) {
35 - t1 = calculateExpensiveNumber(x);
34 + t0 = calculateExpensiveNumber(x);
35 $[0] = x;
37 - $[1] = t1;
36 + $[1] = t0;
37 } else {
39 - t1 = $[1];
38 + t0 = $[1];
39 }
41 - t0 = t1;
40 const expensiveNumber = t0;
43 - let t2;
41 + let t1;
42 if ($[2] !== expensiveNumber) {
45 - t2 = <div>{expensiveNumber}</div>;
43 + t1 = <div>{expensiveNumber}</div>;
44 $[2] = expensiveNumber;
47 - $[3] = t2;
45 + $[3] = t1;
46 } else {
49 - t2 = $[3];
47 + t1 = $[3];
48 }
51 - return t2;
49 + return t1;
50 }
51
52 function Component2(props) {
53 const $ = _c(4);
54 const [x] = useState(0);
55 let t0;
58 - let t1;
56 if ($[0] !== x) {
60 - t1 = calculateExpensiveNumber(x);
57 + t0 = calculateExpensiveNumber(x);
58 $[0] = x;
62 - $[1] = t1;
59 + $[1] = t0;
60 } else {
64 - t1 = $[1];
61 + t0 = $[1];
62 }
66 - t0 = t1;
63 const expensiveNumber = t0;
68 - let t2;
64 + let t1;
65 if ($[2] !== expensiveNumber) {
70 - t2 = <div>{expensiveNumber}</div>;
66 + t1 = <div>{expensiveNumber}</div>;
67 $[2] = expensiveNumber;
72 - $[3] = t2;
68 + $[3] = t1;
69 } else {
74 - t2 = $[3];
70 + t1 = $[3];
71 }
76 - return t2;
72 + return t1;
73 }
74
75 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/babel-existing-react-kitchensink-import.expect.md
+16 -20
@@ -32,50 +32,46 @@ function Component(props) {
32 const $ = _c(4);
33 const [x] = useState(0);
34 let t0;
35 - let t1;
35 if ($[0] !== x) {
37 - t1 = calculateExpensiveNumber(x);
36 + t0 = calculateExpensiveNumber(x);
37 $[0] = x;
39 - $[1] = t1;
38 + $[1] = t0;
39 } else {
41 - t1 = $[1];
40 + t0 = $[1];
41 }
43 - t0 = t1;
42 const expensiveNumber = t0;
45 - let t2;
43 + let t1;
44 if ($[2] !== expensiveNumber) {
47 - t2 = <div>{expensiveNumber}</div>;
45 + t1 = <div>{expensiveNumber}</div>;
46 $[2] = expensiveNumber;
49 - $[3] = t2;
47 + $[3] = t1;
48 } else {
51 - t2 = $[3];
49 + t1 = $[3];
50 }
53 - return t2;
51 + return t1;
52 }
53
54 function Component2(props) {
55 const $ = _c(4);
56 const [x] = useState(0);
57 let t0;
60 - let t1;
58 if ($[0] !== x) {
62 - t1 = calculateExpensiveNumber(x);
59 + t0 = calculateExpensiveNumber(x);
60 $[0] = x;
64 - $[1] = t1;
61 + $[1] = t0;
62 } else {
66 - t1 = $[1];
63 + t0 = $[1];
64 }
68 - t0 = t1;
65 const expensiveNumber = t0;
70 - let t2;
66 + let t1;
67 if ($[2] !== expensiveNumber) {
72 - t2 = <div>{expensiveNumber}</div>;
68 + t1 = <div>{expensiveNumber}</div>;
69 $[2] = expensiveNumber;
74 - $[3] = t2;
70 + $[3] = t1;
71 } else {
76 - t2 = $[3];
72 + t1 = $[3];
73 }
78 - return t2;
74 + return t1;
75 }
76
77 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/babel-existing-react-namespace-import.expect.md
+8 -10
@@ -30,25 +30,23 @@ function Component(props) {
30 const $ = _c(4);
31 const [x] = React.useState(0);
32 let t0;
33 - let t1;
33 if ($[0] !== x) {
35 - t1 = calculateExpensiveNumber(x);
34 + t0 = calculateExpensiveNumber(x);
35 $[0] = x;
37 - $[1] = t1;
36 + $[1] = t0;
37 } else {
39 - t1 = $[1];
38 + t0 = $[1];
39 }
41 - t0 = t1;
40 const expensiveNumber = t0;
43 - let t2;
41 + let t1;
42 if ($[2] !== expensiveNumber) {
45 - t2 = <div>{expensiveNumber}</div>;
43 + t1 = <div>{expensiveNumber}</div>;
44 $[2] = expensiveNumber;
47 - $[3] = t2;
45 + $[3] = t1;
46 } else {
49 - t2 = $[3];
47 + t1 = $[3];
48 }
51 - return t2;
49 + return t1;
50 }
51
52 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/babel-existing-react-runtime-import.expect.md
+8 -10
@@ -36,30 +36,28 @@ function Component(props) {
36 const $ = _c(4);
37 const [x] = React.useState(0);
38 let t0;
39 - let t1;
39 if ($[0] !== x) {
41 - t1 = calculateExpensiveNumber(x);
40 + t0 = calculateExpensiveNumber(x);
41 $[0] = x;
43 - $[1] = t1;
42 + $[1] = t0;
43 } else {
45 - t1 = $[1];
44 + t0 = $[1];
45 }
47 - t0 = t1;
46 const expensiveNumber = t0;
49 - let t2;
47 + let t1;
48 if ($[2] !== expensiveNumber) {
51 - t2 = (
49 + t1 = (
50 <div>
51 {expensiveNumber}
52 {`${someImport}`}
53 </div>
54 );
55 $[2] = expensiveNumber;
58 - $[3] = t2;
56 + $[3] = t1;
57 } else {
60 - t2 = $[3];
58 + t1 = $[3];
59 }
62 - return t2;
60 + return t1;
61 }
62
63 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/block-scoping-switch-variable-scoping.expect.md
+5 -8
@@ -36,15 +36,14 @@ import { useMemo } from "react";
36 function Component(props) {
37 const $ = _c(2);
38 let t0;
39 - let t1;
39 if ($[0] !== props.value) {
41 - t1 = { value: props.value };
40 + t0 = { value: props.value };
41 $[0] = props.value;
43 - $[1] = t1;
42 + $[1] = t0;
43 } else {
45 - t1 = $[1];
44 + t0 = $[1];
45 }
47 - const handlers = t1;
46 + const handlers = t0;
47 bb0: switch (props.test) {
48 case true: {
49 console.log(handlers.value);
@@ -52,9 +51,7 @@ function Component(props) {
51 }
52 default:
53 }
55 -
56 - t0 = handlers;
57 - const outerHandlers = t0;
54 + const outerHandlers = handlers;
55 return outerHandlers;
56 }
57
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-inline-iife-reassign.expect.md
+1 -3
@@ -37,11 +37,9 @@ function useTest() {
37
38 const t1 = (w = 42);
39 const t2 = w;
40 - let t3;
40
41 w = 999;
43 - t3 = 2;
44 - t0 = makeArray(t1, t2, t3);
42 + t0 = makeArray(t1, t2, 2);
43 $[0] = t0;
44 } else {
45 t0 = $[0];
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-inline-iife-storeprop.expect.md
+1 -3
@@ -37,11 +37,9 @@ function useTest() {
37
38 const t1 = (w.x = 42);
39 const t2 = w.x;
40 - let t3;
40
41 w.x = 999;
43 - t3 = 2;
44 - t0 = makeArray(t1, t2, t3);
42 + t0 = makeArray(t1, t2, 2);
43 $[0] = t0;
44 } else {
45 t0 = $[0];
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-inline-iife.expect.md
+1 -3
@@ -32,11 +32,9 @@ function useTest() {
32 let t0;
33 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
34 const t1 = print(1);
35 - let t2;
35
36 print(2);
38 - t2 = 2;
39 - t0 = makeArray(t1, t2);
37 + t0 = makeArray(t1, 2);
38 $[0] = t0;
39 } else {
40 t0 = $[0];
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/consecutive-use-memo.expect.md
+13 -17
@@ -29,37 +29,33 @@ function useHook(t0) {
29 const $ = _c(7);
30 const { a, b } = t0;
31 let t1;
32 - let t2;
32 if ($[0] !== a) {
34 - t2 = identity({ a });
33 + t1 = identity({ a });
34 $[0] = a;
36 - $[1] = t2;
35 + $[1] = t1;
36 } else {
38 - t2 = $[1];
37 + t1 = $[1];
38 }
40 - t1 = t2;
39 const valA = t1;
42 - let t3;
43 - let t4;
40 + let t2;
41 if ($[2] !== b) {
45 - t4 = identity([b]);
42 + t2 = identity([b]);
43 $[2] = b;
47 - $[3] = t4;
44 + $[3] = t2;
45 } else {
49 - t4 = $[3];
46 + t2 = $[3];
47 }
51 - t3 = t4;
52 - const valB = t3;
53 - let t5;
48 + const valB = t2;
49 + let t3;
50 if ($[4] !== valA || $[5] !== valB) {
55 - t5 = [valA, valB];
51 + t3 = [valA, valB];
52 $[4] = valA;
53 $[5] = valB;
58 - $[6] = t5;
54 + $[6] = t3;
55 } else {
60 - t5 = $[6];
56 + t3 = $[6];
57 }
62 - return t5;
58 + return t3;
59 }
60
61 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/context-variable-as-jsx-element-tag.expect.md
+1 -3
@@ -34,10 +34,8 @@ function Component(props) {
34 let Component;
35 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36 Component = Stringify;
37 - let t0;
37
39 - t0 = Component;
40 - Component = t0;
38 + Component = Component;
39 $[0] = Component;
40 } else {
41 Component = $[0];
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/deeply-nested-function-expressions-with-params.expect.md
+6 -8
@@ -28,20 +28,18 @@ import { c as _c } from "react/compiler-runtime";
28 function Foo() {
29 const $ = _c(1);
30 let t0;
31 - let t1;
31 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
33 - t1 = function a(t2) {
34 - const x_0 = t2 === undefined ? _temp : t2;
35 - return (function b(t3) {
36 - const y_0 = t3 === undefined ? [] : t3;
32 + t0 = function a(t1) {
33 + const x_0 = t1 === undefined ? _temp : t1;
34 + return (function b(t2) {
35 + const y_0 = t2 === undefined ? [] : t2;
36 return [x_0, y_0];
37 })();
38 };
40 - $[0] = t1;
39 + $[0] = t0;
40 } else {
42 - t1 = $[0];
41 + t0 = $[0];
42 }
44 - t0 = t1;
43 return t0;
44 }
45 function _temp() {}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/drop-methodcall-usememo.expect.md
+1 -3
@@ -28,7 +28,6 @@ import * as React from "react";
28
29 function Component(props) {
30 const $ = _c(2);
31 - let t0;
31 let x;
32 if ($[0] !== props.value) {
33 x = [];
@@ -38,8 +37,7 @@ function Component(props) {
37 } else {
38 x = $[1];
39 }
41 - t0 = x;
42 - const x_0 = t0;
40 + const x_0 = x;
41 return x_0;
42 }
43
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/existing-variables-with-c-name.expect.md
+14 -16
@@ -42,34 +42,32 @@ function Component(props) {
42 const c1 = __c;
43 const $c = c1;
44 let t0;
45 - let t1;
45 if ($[0] !== $c) {
47 - t1 = [$c];
46 + t0 = [$c];
47 $[0] = $c;
49 - $[1] = t1;
48 + $[1] = t0;
49 } else {
51 - t1 = $[1];
50 + t0 = $[1];
51 }
53 - t0 = t1;
52 const array = t0;
55 - let t2;
53 + let t1;
54 if ($[2] !== state) {
57 - t2 = [state];
55 + t1 = [state];
56 $[2] = state;
59 - $[3] = t2;
57 + $[3] = t1;
58 } else {
61 - t2 = $[3];
59 + t1 = $[3];
60 }
63 - let t3;
64 - if ($[4] !== array || $[5] !== t2) {
65 - t3 = <ValidateMemoization inputs={t2} output={array} />;
61 + let t2;
62 + if ($[4] !== array || $[5] !== t1) {
63 + t2 = <ValidateMemoization inputs={t1} output={array} />;
64 $[4] = array;
67 - $[5] = t2;
68 - $[6] = t3;
65 + $[5] = t1;
66 + $[6] = t2;
67 } else {
70 - t3 = $[6];
68 + t2 = $[6];
69 }
72 - return t3;
70 + return t2;
71 }
72
73 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fast-refresh-dont-refresh-const-changes-prod.expect.md
+8 -10
@@ -63,23 +63,21 @@ function Component() {
63
64 unsafeUpdateConst();
65 let t0;
66 - let t1;
66 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
68 - t1 = [{ pretendConst }];
69 - $[0] = t1;
67 + t0 = [{ pretendConst }];
68 + $[0] = t0;
69 } else {
71 - t1 = $[0];
70 + t0 = $[0];
71 }
73 - t0 = t1;
72 const value = t0;
75 - let t2;
73 + let t1;
74 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
77 - t2 = <ValidateMemoization inputs={[]} output={value} />;
78 - $[1] = t2;
75 + t1 = <ValidateMemoization inputs={[]} output={value} />;
76 + $[1] = t1;
77 } else {
80 - t2 = $[1];
78 + t1 = $[1];
79 }
82 - return t2;
80 + return t1;
81 }
82 function _temp() {
83 unsafeResetConst();
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fast-refresh-refresh-on-const-changes-dev.expect.md
+8 -10
@@ -74,23 +74,21 @@ function Component() {
74
75 unsafeUpdateConst();
76 let t0;
77 - let t1;
77 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
79 - t1 = [{ pretendConst }];
80 - $[1] = t1;
78 + t0 = [{ pretendConst }];
79 + $[1] = t0;
80 } else {
82 - t1 = $[1];
81 + t0 = $[1];
82 }
84 - t0 = t1;
83 const value = t0;
86 - let t2;
84 + let t1;
85 if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
88 - t2 = <ValidateMemoization inputs={[pretendConst]} output={value} />;
89 - $[2] = t2;
86 + t1 = <ValidateMemoization inputs={[pretendConst]} output={value} />;
87 + $[2] = t1;
88 } else {
91 - t2 = $[2];
89 + t1 = $[2];
90 }
93 - return t2;
91 + return t1;
92 }
93 function _temp() {
94 unsafeResetConst();
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fast-refresh-reloading.expect.md
+19 -21
@@ -38,36 +38,34 @@ function Component(props) {
38 $[0] = "20945b0193e529df490847c66111b38d7b02485d5b53d0829ff3b23af87b105c";
39 }
40 const [state] = useState(0);
41 - let t0;
42 - const t1 = state * 2;
43 - let t2;
44 - if ($[1] !== t1) {
45 - t2 = [t1];
46 - $[1] = t1;
47 - $[2] = t2;
41 + const t0 = state * 2;
42 + let t1;
43 + if ($[1] !== t0) {
44 + t1 = [t0];
45 + $[1] = t0;
46 + $[2] = t1;
47 } else {
49 - t2 = $[2];
48 + t1 = $[2];
49 }
51 - t0 = t2;
52 - const doubled = t0;
53 - let t3;
50 + const doubled = t1;
51 + let t2;
52 if ($[3] !== state) {
55 - t3 = [state];
53 + t2 = [state];
54 $[3] = state;
57 - $[4] = t3;
55 + $[4] = t2;
56 } else {
59 - t3 = $[4];
57 + t2 = $[4];
58 }
61 - let t4;
62 - if ($[5] !== doubled || $[6] !== t3) {
63 - t4 = <ValidateMemoization inputs={t3} output={doubled} />;
59 + let t3;
60 + if ($[5] !== doubled || $[6] !== t2) {
61 + t3 = <ValidateMemoization inputs={t2} output={doubled} />;
62 $[5] = doubled;
65 - $[6] = t3;
66 - $[7] = t4;
63 + $[6] = t2;
64 + $[7] = t3;
65 } else {
68 - t4 = $[7];
66 + t3 = $[7];
67 }
70 - return t4;
68 + return t3;
69 }
70
71 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/fbt/fbt-repro-invalid-mutable-range-destructured-prop.expect.md
+14 -16
@@ -40,36 +40,34 @@ function Component(t0) {
40 const $ = _c(7);
41 const { data } = t0;
42 let t1;
43 - let t2;
43 if ($[0] !== data.name) {
45 - t2 = fbt._("{name}", [fbt._param("name", data.name ?? "")], {
44 + t1 = fbt._("{name}", [fbt._param("name", data.name ?? "")], {
45 hk: "csQUH",
46 });
47 $[0] = data.name;
49 - $[1] = t2;
48 + $[1] = t1;
49 } else {
51 - t2 = $[1];
50 + t1 = $[1];
51 }
53 - t1 = t2;
52 const el = t1;
55 - let t3;
53 + let t2;
54 if ($[2] !== data.name) {
57 - t3 = [data.name];
55 + t2 = [data.name];
56 $[2] = data.name;
59 - $[3] = t3;
57 + $[3] = t2;
58 } else {
61 - t3 = $[3];
59 + t2 = $[3];
60 }
63 - let t4;
64 - if ($[4] !== el || $[5] !== t3) {
65 - t4 = <ValidateMemoization inputs={t3} output={el} />;
61 + let t3;
62 + if ($[4] !== el || $[5] !== t2) {
63 + t3 = <ValidateMemoization inputs={t2} output={el} />;
64 $[4] = el;
67 - $[5] = t3;
68 - $[6] = t4;
65 + $[5] = t2;
66 + $[6] = t3;
67 } else {
70 - t4 = $[6];
68 + t3 = $[6];
69 }
72 - return t4;
70 + return t3;
71 }
72
73 const props1 = { data: { name: "Mike" } };
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/for-of-nonmutating-loop-local-collection.expect.md
+33 -38
@@ -47,17 +47,14 @@ function Component(t0) {
47 const $ = _c(19);
48 const { a, b } = t0;
49 let t1;
50 - let t2;
50 if ($[0] !== a) {
52 - t2 = [a];
51 + t1 = [a];
52 $[0] = a;
54 - $[1] = t2;
53 + $[1] = t1;
54 } else {
56 - t2 = $[1];
55 + t1 = $[1];
56 }
58 - t1 = t2;
57 const x = t1;
60 - let t3;
58 let items;
59 if ($[2] !== b || $[3] !== x) {
60 items = [b];
@@ -70,59 +67,57 @@ function Component(t0) {
67 } else {
68 items = $[4];
69 }
73 -
74 - t3 = items;
75 - const y = t3;
76 - let t4;
70 + const y = items;
71 + let t2;
72 if ($[5] !== a) {
78 - t4 = [a];
73 + t2 = [a];
74 $[5] = a;
80 - $[6] = t4;
75 + $[6] = t2;
76 } else {
82 - t4 = $[6];
77 + t2 = $[6];
78 }
84 - let t5;
85 - if ($[7] !== t4 || $[8] !== x) {
86 - t5 = <ValidateMemoization inputs={t4} output={x} />;
87 - $[7] = t4;
79 + let t3;
80 + if ($[7] !== t2 || $[8] !== x) {
81 + t3 = <ValidateMemoization inputs={t2} output={x} />;
82 + $[7] = t2;
83 $[8] = x;
89 - $[9] = t5;
84 + $[9] = t3;
85 } else {
91 - t5 = $[9];
86 + t3 = $[9];
87 }
93 - let t6;
88 + let t4;
89 if ($[10] !== b || $[11] !== x) {
95 - t6 = [x, b];
90 + t4 = [x, b];
91 $[10] = b;
92 $[11] = x;
98 - $[12] = t6;
93 + $[12] = t4;
94 } else {
100 - t6 = $[12];
95 + t4 = $[12];
96 }
102 - let t7;
103 - if ($[13] !== t6 || $[14] !== y) {
104 - t7 = <ValidateMemoization inputs={t6} output={y} />;
105 - $[13] = t6;
97 + let t5;
98 + if ($[13] !== t4 || $[14] !== y) {
99 + t5 = <ValidateMemoization inputs={t4} output={y} />;
100 + $[13] = t4;
101 $[14] = y;
107 - $[15] = t7;
102 + $[15] = t5;
103 } else {
109 - t7 = $[15];
104 + t5 = $[15];
105 }
111 - let t8;
112 - if ($[16] !== t5 || $[17] !== t7) {
113 - t8 = (
106 + let t6;
107 + if ($[16] !== t3 || $[17] !== t5) {
108 + t6 = (
109 <>
110 + {t3}
111 {t5}
116 - {t7}
112 </>
113 );
119 - $[16] = t5;
120 - $[17] = t7;
121 - $[18] = t8;
114 + $[16] = t3;
115 + $[17] = t5;
116 + $[18] = t6;
117 } else {
123 - t8 = $[18];
118 + t6 = $[18];
119 }
125 - return t8;
120 + return t6;
121 }
122
123 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/function-expression-prototype-call-mutating.expect.md
+12 -14
@@ -34,7 +34,6 @@ import { ValidateMemoization } from "shared-runtime";
34
35 function Component(props) {
36 const $ = _c(7);
37 - let t0;
37 let a;
38 if ($[0] !== props.name) {
39 a = [];
@@ -48,26 +47,25 @@ function Component(props) {
47 } else {
48 a = $[1];
49 }
51 - t0 = a;
52 - const a_0 = t0;
53 - let t1;
50 + const a_0 = a;
51 + let t0;
52 if ($[2] !== props.name) {
55 - t1 = [props.name];
53 + t0 = [props.name];
54 $[2] = props.name;
57 - $[3] = t1;
55 + $[3] = t0;
56 } else {
59 - t1 = $[3];
57 + t0 = $[3];
58 }
61 - let t2;
62 - if ($[4] !== a_0 || $[5] !== t1) {
63 - t2 = <ValidateMemoization inputs={t1} output={a_0} />;
59 + let t1;
60 + if ($[4] !== a_0 || $[5] !== t0) {
61 + t1 = <ValidateMemoization inputs={t0} output={a_0} />;
62 $[4] = a_0;
65 - $[5] = t1;
66 - $[6] = t2;
63 + $[5] = t0;
64 + $[6] = t1;
65 } else {
68 - t2 = $[6];
66 + t1 = $[6];
67 }
70 - return t2;
68 + return t1;
69 }
70
71 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/hooks-with-prefix.expect.md
+13 -17
@@ -46,7 +46,7 @@ const React$useMemo = React.useMemo;
46 const Internal$Reassigned$useHook = useHook;
47
48 function Component() {
49 - const $ = _c(8);
49 + const $ = _c(7);
50 const [state] = React$useState(0);
51 const object = Internal$Reassigned$useHook();
52 let t0;
@@ -59,34 +59,30 @@ function Component() {
59 }
60 const json = t0;
61 let t1;
62 - let t2;
62 if ($[2] !== state) {
64 - t1 = makeArray(state);
65 - const doubledArray = t1;
63 + const doubledArray = makeArray(state);
64
67 - t2 = doubledArray.join("");
65 + t1 = doubledArray.join("");
66 $[2] = state;
69 - $[3] = t2;
70 - $[4] = t1;
67 + $[3] = t1;
68 } else {
72 - t2 = $[3];
73 - t1 = $[4];
69 + t1 = $[3];
70 }
75 - let t3;
76 - if ($[5] !== json || $[6] !== t2) {
77 - t3 = (
71 + let t2;
72 + if ($[4] !== json || $[5] !== t1) {
73 + t2 = (
74 <div>
79 - {t2}
75 + {t1}
76 {json}
77 </div>
78 );
83 - $[5] = json;
79 + $[4] = json;
80 + $[5] = t1;
81 $[6] = t2;
85 - $[7] = t3;
82 } else {
87 - t3 = $[7];
83 + t2 = $[6];
84 }
89 - return t3;
85 + return t2;
86 }
87
88 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/iife-return-modified-later.expect.md
+2 -6
@@ -22,20 +22,16 @@ export const FIXTURE_ENTRYPOINT = {
22 ```javascript
23 import { c as _c } from "react/compiler-runtime";
24 function Component(props) {
25 - const $ = _c(3);
26 - let t0;
25 + const $ = _c(2);
26 let items;
27 if ($[0] !== props.a) {
29 - t0 = [];
30 - items = t0;
28 + items = [];
29
30 items.push(props.a);
31 $[0] = props.a;
32 $[1] = items;
35 - $[2] = t0;
33 } else {
34 items = $[1];
38 - t0 = $[2];
35 }
36 return items;
37 }
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/inner-function/nullable-objects/assume-invoked/use-memo-returned.expect.md
+3 -5
@@ -50,19 +50,17 @@ function useMakeCallback(t0) {
50
51 const [, setState] = useState(0);
52 let t1;
53 - let t2;
53 if ($[0] !== obj.value) {
55 - t2 = () => {
54 + t1 = () => {
55 if (obj.value !== 0) {
56 setState(obj.value);
57 }
58 };
59 $[0] = obj.value;
61 - $[1] = t2;
60 + $[1] = t1;
61 } else {
63 - t2 = $[1];
62 + t1 = $[1];
63 }
65 - t1 = t2;
64 const cb = t1;
65
66 useIdentity(null);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/nested-function-with-param-as-captured-dep.expect.md
+4 -6
@@ -26,17 +26,15 @@ import { c as _c } from "react/compiler-runtime";
26 function Foo() {
27 const $ = _c(1);
28 let t0;
29 - let t1;
29 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
31 - t1 = function a(t2) {
32 - const x_0 = t2 === undefined ? _temp : t2;
30 + t0 = function a(t1) {
31 + const x_0 = t1 === undefined ? _temp : t1;
32 return x_0;
33 };
35 - $[0] = t1;
34 + $[0] = t0;
35 } else {
37 - t1 = $[0];
36 + t0 = $[0];
37 }
39 - t0 = t1;
38 return t0;
39 }
40 function _temp() {}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-through-identity-function-expression.expect.md
+17 -21
@@ -37,13 +37,11 @@ import { useMemo } from "react";
37 import { identity, ValidateMemoization } from "shared-runtime";
38
39 function Component(t0) {
40 - const $ = _c(10);
40 + const $ = _c(9);
41 const { a, b } = t0;
42 - let t1;
42 let x;
43 if ($[0] !== a || $[1] !== b) {
45 - t1 = { a };
46 - x = t1;
44 + x = { a };
45 const f = () => identity(x);
46
47 const x2 = f();
@@ -51,30 +49,28 @@ function Component(t0) {
49 $[0] = a;
50 $[1] = b;
51 $[2] = x;
54 - $[3] = t1;
52 } else {
53 x = $[2];
57 - t1 = $[3];
54 }
59 - let t2;
60 - if ($[4] !== a || $[5] !== b) {
61 - t2 = [a, b];
62 - $[4] = a;
63 - $[5] = b;
64 - $[6] = t2;
55 + let t1;
56 + if ($[3] !== a || $[4] !== b) {
57 + t1 = [a, b];
58 + $[3] = a;
59 + $[4] = b;
60 + $[5] = t1;
61 } else {
66 - t2 = $[6];
62 + t1 = $[5];
63 }
68 - let t3;
69 - if ($[7] !== t2 || $[8] !== x) {
70 - t3 = <ValidateMemoization inputs={t2} output={x} />;
71 - $[7] = t2;
72 - $[8] = x;
73 - $[9] = t3;
64 + let t2;
65 + if ($[6] !== t1 || $[7] !== x) {
66 + t2 = <ValidateMemoization inputs={t1} output={x} />;
67 + $[6] = t1;
68 + $[7] = x;
69 + $[8] = t2;
70 } else {
75 - t3 = $[9];
71 + t2 = $[8];
72 }
77 - return t3;
73 + return t2;
74 }
75
76 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/mutate-through-identity.expect.md
+17 -21
@@ -34,42 +34,38 @@ import { useMemo } from "react";
34 import { identity, ValidateMemoization } from "shared-runtime";
35
36 function Component(t0) {
37 - const $ = _c(10);
37 + const $ = _c(9);
38 const { a, b } = t0;
39 - let t1;
39 let x;
40 if ($[0] !== a || $[1] !== b) {
42 - t1 = { a };
43 - x = t1;
41 + x = { a };
42 const x2 = identity(x);
43 x2.b = b;
44 $[0] = a;
45 $[1] = b;
46 $[2] = x;
49 - $[3] = t1;
47 } else {
48 x = $[2];
52 - t1 = $[3];
49 }
54 - let t2;
55 - if ($[4] !== a || $[5] !== b) {
56 - t2 = [a, b];
57 - $[4] = a;
58 - $[5] = b;
59 - $[6] = t2;
50 + let t1;
51 + if ($[3] !== a || $[4] !== b) {
52 + t1 = [a, b];
53 + $[3] = a;
54 + $[4] = b;
55 + $[5] = t1;
56 } else {
61 - t2 = $[6];
57 + t1 = $[5];
58 }
63 - let t3;
64 - if ($[7] !== t2 || $[8] !== x) {
65 - t3 = <ValidateMemoization inputs={t2} output={x} />;
66 - $[7] = t2;
67 - $[8] = x;
68 - $[9] = t3;
59 + let t2;
60 + if ($[6] !== t1 || $[7] !== x) {
61 + t2 = <ValidateMemoization inputs={t1} output={x} />;
62 + $[6] = t1;
63 + $[7] = x;
64 + $[8] = t2;
65 } else {
70 - t3 = $[9];
66 + t2 = $[8];
67 }
72 - return t3;
68 + return t2;
69 }
70
71 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/todo-control-flow-sensitive-mutation.expect.md
+38 -42
@@ -60,13 +60,11 @@ import {
60 } from "shared-runtime";
61
62 function Component(t0) {
63 - const $ = _c(22);
63 + const $ = _c(21);
64 const { a, b, c } = t0;
65 - let t1;
65 let x;
66 if ($[0] !== a || $[1] !== b || $[2] !== c) {
68 - t1 = [{ value: a }];
69 - x = t1;
67 + x = [{ value: a }];
68 if (b === 0) {
69 x.push({ value: c });
70 } else {
@@ -76,63 +74,61 @@ function Component(t0) {
74 $[1] = b;
75 $[2] = c;
76 $[3] = x;
79 - $[4] = t1;
77 } else {
78 x = $[3];
82 - t1 = $[4];
79 + }
80 + let t1;
81 + if ($[4] !== a || $[5] !== b || $[6] !== c) {
82 + t1 = [a, b, c];
83 + $[4] = a;
84 + $[5] = b;
85 + $[6] = c;
86 + $[7] = t1;
87 + } else {
88 + t1 = $[7];
89 }
90 let t2;
85 - if ($[5] !== a || $[6] !== b || $[7] !== c) {
86 - t2 = [a, b, c];
87 - $[5] = a;
88 - $[6] = b;
89 - $[7] = c;
90 - $[8] = t2;
91 + if ($[8] !== t1 || $[9] !== x) {
92 + t2 = <ValidateMemoization inputs={t1} output={x} />;
93 + $[8] = t1;
94 + $[9] = x;
95 + $[10] = t2;
96 } else {
92 - t2 = $[8];
97 + t2 = $[10];
98 }
99 let t3;
95 - if ($[9] !== t2 || $[10] !== x) {
96 - t3 = <ValidateMemoization inputs={t2} output={x} />;
97 - $[9] = t2;
98 - $[10] = x;
99 - $[11] = t3;
100 + if ($[11] !== a || $[12] !== b || $[13] !== c) {
101 + t3 = [a, b, c];
102 + $[11] = a;
103 + $[12] = b;
104 + $[13] = c;
105 + $[14] = t3;
106 } else {
101 - t3 = $[11];
107 + t3 = $[14];
108 }
109 let t4;
104 - if ($[12] !== a || $[13] !== b || $[14] !== c) {
105 - t4 = [a, b, c];
106 - $[12] = a;
107 - $[13] = b;
108 - $[14] = c;
109 - $[15] = t4;
110 + if ($[15] !== t3 || $[16] !== x[0]) {
111 + t4 = <ValidateMemoization inputs={t3} output={x[0]} />;
112 + $[15] = t3;
113 + $[16] = x[0];
114 + $[17] = t4;
115 } else {
111 - t4 = $[15];
116 + t4 = $[17];
117 }
118 let t5;
114 - if ($[16] !== t4 || $[17] !== x[0]) {
115 - t5 = <ValidateMemoization inputs={t4} output={x[0]} />;
116 - $[16] = t4;
117 - $[17] = x[0];
118 - $[18] = t5;
119 - } else {
120 - t5 = $[18];
121 - }
122 - let t6;
123 - if ($[19] !== t3 || $[20] !== t5) {
124 - t6 = (
119 + if ($[18] !== t2 || $[19] !== t4) {
120 + t5 = (
121 <>
126 - {t3};{t5};
122 + {t2};{t4};
123 </>
124 );
129 - $[19] = t3;
125 + $[18] = t2;
126 + $[19] = t4;
127 $[20] = t5;
131 - $[21] = t6;
128 } else {
133 - t6 = $[21];
129 + t5 = $[20];
130 }
135 - return t6;
131 + return t5;
132 }
133
134 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/todo-transitivity-createfrom-capture-lambda.expect.md
+17 -21
@@ -51,13 +51,11 @@ import {
51 } from "shared-runtime";
52
53 function Component(t0) {
54 - const $ = _c(10);
54 + const $ = _c(9);
55 const { a, b } = t0;
56 - let t1;
56 let x;
57 if ($[0] !== a || $[1] !== b) {
59 - t1 = [{ a }];
60 - x = t1;
58 + x = [{ a }];
59 const f = () => {
60 const y = typedCreateFrom(x);
61 const z = typedCapture(y);
@@ -70,30 +68,28 @@ function Component(t0) {
68 $[0] = a;
69 $[1] = b;
70 $[2] = x;
73 - $[3] = t1;
71 } else {
72 x = $[2];
76 - t1 = $[3];
73 }
78 - let t2;
79 - if ($[4] !== a || $[5] !== b) {
80 - t2 = [a, b];
81 - $[4] = a;
82 - $[5] = b;
83 - $[6] = t2;
74 + let t1;
75 + if ($[3] !== a || $[4] !== b) {
76 + t1 = [a, b];
77 + $[3] = a;
78 + $[4] = b;
79 + $[5] = t1;
80 } else {
85 - t2 = $[6];
81 + t1 = $[5];
82 }
87 - let t3;
88 - if ($[7] !== t2 || $[8] !== x) {
89 - t3 = <ValidateMemoization inputs={t2} output={x} />;
90 - $[7] = t2;
91 - $[8] = x;
92 - $[9] = t3;
83 + let t2;
84 + if ($[6] !== t1 || $[7] !== x) {
85 + t2 = <ValidateMemoization inputs={t1} output={x} />;
86 + $[6] = t1;
87 + $[7] = x;
88 + $[8] = t2;
89 } else {
94 - t3 = $[9];
90 + t2 = $[8];
91 }
96 - return t3;
92 + return t2;
93 }
94
95 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/transitivity-add-captured-array-to-itself.expect.md
+40 -46
@@ -52,24 +52,20 @@ import {
52 } from "shared-runtime";
53
54 function Component(t0) {
55 - const $ = _c(20);
55 + const $ = _c(19);
56 const { a, b } = t0;
57 let t1;
58 - let t2;
58 if ($[0] !== a) {
60 - t2 = { a };
59 + t1 = { a };
60 $[0] = a;
62 - $[1] = t2;
61 + $[1] = t1;
62 } else {
64 - t2 = $[1];
63 + t1 = $[1];
64 }
66 - t1 = t2;
65 const o = t1;
68 - let t3;
66 let x;
67 if ($[2] !== b || $[3] !== o) {
71 - t3 = [o];
72 - x = t3;
68 + x = [o];
69 const y = typedCapture(x);
70 const z = typedCapture(y);
71 x.push(z);
@@ -77,60 +73,58 @@ function Component(t0) {
73 $[2] = b;
74 $[3] = o;
75 $[4] = x;
80 - $[5] = t3;
76 } else {
77 x = $[4];
83 - t3 = $[5];
78 }
85 - let t4;
86 - if ($[6] !== a) {
87 - t4 = [a];
88 - $[6] = a;
89 - $[7] = t4;
79 + let t2;
80 + if ($[5] !== a) {
81 + t2 = [a];
82 + $[5] = a;
83 + $[6] = t2;
84 } else {
91 - t4 = $[7];
85 + t2 = $[6];
86 }
93 - let t5;
94 - if ($[8] !== o || $[9] !== t4) {
95 - t5 = <ValidateMemoization inputs={t4} output={o} />;
96 - $[8] = o;
97 - $[9] = t4;
98 - $[10] = t5;
87 + let t3;
88 + if ($[7] !== o || $[8] !== t2) {
89 + t3 = <ValidateMemoization inputs={t2} output={o} />;
90 + $[7] = o;
91 + $[8] = t2;
92 + $[9] = t3;
93 } else {
100 - t5 = $[10];
94 + t3 = $[9];
95 }
102 - let t6;
103 - if ($[11] !== a || $[12] !== b) {
104 - t6 = [a, b];
105 - $[11] = a;
106 - $[12] = b;
107 - $[13] = t6;
96 + let t4;
97 + if ($[10] !== a || $[11] !== b) {
98 + t4 = [a, b];
99 + $[10] = a;
100 + $[11] = b;
101 + $[12] = t4;
102 } else {
109 - t6 = $[13];
103 + t4 = $[12];
104 }
111 - let t7;
112 - if ($[14] !== t6 || $[15] !== x) {
113 - t7 = <ValidateMemoization inputs={t6} output={x} />;
114 - $[14] = t6;
115 - $[15] = x;
116 - $[16] = t7;
105 + let t5;
106 + if ($[13] !== t4 || $[14] !== x) {
107 + t5 = <ValidateMemoization inputs={t4} output={x} />;
108 + $[13] = t4;
109 + $[14] = x;
110 + $[15] = t5;
111 } else {
118 - t7 = $[16];
112 + t5 = $[15];
113 }
120 - let t8;
121 - if ($[17] !== t5 || $[18] !== t7) {
122 - t8 = (
114 + let t6;
115 + if ($[16] !== t3 || $[17] !== t5) {
116 + t6 = (
117 <>
124 - {t5};{t7};
118 + {t3};{t5};
119 </>
120 );
121 + $[16] = t3;
122 $[17] = t5;
128 - $[18] = t7;
129 - $[19] = t8;
123 + $[18] = t6;
124 } else {
131 - t8 = $[19];
125 + t6 = $[18];
126 }
133 - return t8;
127 + return t6;
128 }
129
130 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/transitivity-capture-createfrom-lambda.expect.md
+17 -21
@@ -50,13 +50,11 @@ import {
50 } from "shared-runtime";
51
52 function Component(t0) {
53 - const $ = _c(10);
53 + const $ = _c(9);
54 const { a, b } = t0;
55 - let t1;
55 let x;
56 if ($[0] !== a || $[1] !== b) {
58 - t1 = { a };
59 - x = t1;
57 + x = { a };
58 const f = () => {
59 const y = typedCapture(x);
60 const z = typedCreateFrom(y);
@@ -69,30 +67,28 @@ function Component(t0) {
67 $[0] = a;
68 $[1] = b;
69 $[2] = x;
72 - $[3] = t1;
70 } else {
71 x = $[2];
75 - t1 = $[3];
72 }
77 - let t2;
78 - if ($[4] !== a || $[5] !== b) {
79 - t2 = [a, b];
80 - $[4] = a;
81 - $[5] = b;
82 - $[6] = t2;
73 + let t1;
74 + if ($[3] !== a || $[4] !== b) {
75 + t1 = [a, b];
76 + $[3] = a;
77 + $[4] = b;
78 + $[5] = t1;
79 } else {
84 - t2 = $[6];
80 + t1 = $[5];
81 }
86 - let t3;
87 - if ($[7] !== t2 || $[8] !== x) {
88 - t3 = <ValidateMemoization inputs={t2} output={x} />;
89 - $[7] = t2;
90 - $[8] = x;
91 - $[9] = t3;
82 + let t2;
83 + if ($[6] !== t1 || $[7] !== x) {
84 + t2 = <ValidateMemoization inputs={t1} output={x} />;
85 + $[6] = t1;
86 + $[7] = x;
87 + $[8] = t2;
88 } else {
93 - t3 = $[9];
89 + t2 = $[8];
90 }
95 - return t3;
91 + return t2;
92 }
93
94 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/transitivity-capture-createfrom.expect.md
+17 -21
@@ -46,13 +46,11 @@ import {
46 } from "shared-runtime";
47
48 function Component(t0) {
49 - const $ = _c(10);
49 + const $ = _c(9);
50 const { a, b } = t0;
51 - let t1;
51 let x;
52 if ($[0] !== a || $[1] !== b) {
54 - t1 = { a };
55 - x = t1;
53 + x = { a };
54 const y = typedCapture(x);
55 const z = typedCreateFrom(y);
56
@@ -60,30 +58,28 @@ function Component(t0) {
58 $[0] = a;
59 $[1] = b;
60 $[2] = x;
63 - $[3] = t1;
61 } else {
62 x = $[2];
66 - t1 = $[3];
63 }
68 - let t2;
69 - if ($[4] !== a || $[5] !== b) {
70 - t2 = [a, b];
71 - $[4] = a;
72 - $[5] = b;
73 - $[6] = t2;
64 + let t1;
65 + if ($[3] !== a || $[4] !== b) {
66 + t1 = [a, b];
67 + $[3] = a;
68 + $[4] = b;
69 + $[5] = t1;
70 } else {
75 - t2 = $[6];
71 + t1 = $[5];
72 }
77 - let t3;
78 - if ($[7] !== t2 || $[8] !== x) {
79 - t3 = <ValidateMemoization inputs={t2} output={x} />;
80 - $[7] = t2;
81 - $[8] = x;
82 - $[9] = t3;
73 + let t2;
74 + if ($[6] !== t1 || $[7] !== x) {
75 + t2 = <ValidateMemoization inputs={t1} output={x} />;
76 + $[6] = t1;
77 + $[7] = x;
78 + $[8] = t2;
79 } else {
84 - t3 = $[9];
80 + t2 = $[8];
81 }
86 - return t3;
82 + return t2;
83 }
84
85 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/transitivity-createfrom-capture.expect.md
+14 -16
@@ -49,38 +49,36 @@ function Component(t0) {
49 const $ = _c(7);
50 const { a, b } = t0;
51 let t1;
52 - let t2;
52 if ($[0] !== a) {
54 - t2 = [{ a }];
53 + t1 = [{ a }];
54 $[0] = a;
56 - $[1] = t2;
55 + $[1] = t1;
56 } else {
58 - t2 = $[1];
57 + t1 = $[1];
58 }
60 - t1 = t2;
59 const x = t1;
60 const y = typedCreateFrom(x);
61 const z = typedCapture(y);
62
63 typedMutate(z, b);
66 - let t3;
64 + let t2;
65 if ($[2] !== a) {
68 - t3 = [a];
66 + t2 = [a];
67 $[2] = a;
70 - $[3] = t3;
68 + $[3] = t2;
69 } else {
72 - t3 = $[3];
70 + t2 = $[3];
71 }
74 - let t4;
75 - if ($[4] !== t3 || $[5] !== x) {
76 - t4 = <ValidateMemoization inputs={t3} output={x} />;
77 - $[4] = t3;
72 + let t3;
73 + if ($[4] !== t2 || $[5] !== x) {
74 + t3 = <ValidateMemoization inputs={t2} output={x} />;
75 + $[4] = t2;
76 $[5] = x;
79 - $[6] = t4;
77 + $[6] = t3;
78 } else {
81 - t4 = $[6];
79 + t3 = $[6];
80 }
83 - return t4;
81 + return t3;
82 }
83
84 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/transitivity-phi-assign-or-capture.expect.md
+22 -26
@@ -50,21 +50,19 @@ import {
50 } from "shared-runtime";
51
52 function Component(t0) {
53 - const $ = _c(12);
53 + const $ = _c(11);
54 const { a, b } = t0;
55 let t1;
56 - let t2;
56 if ($[0] !== a) {
58 - t2 = { a };
57 + t1 = { a };
58 $[0] = a;
60 - $[1] = t2;
59 + $[1] = t1;
60 } else {
62 - t2 = $[1];
61 + t1 = $[1];
62 }
63 let x;
65 - if ($[2] !== b || $[3] !== t2) {
66 - t1 = [t2];
67 - x = t1;
64 + if ($[2] !== b || $[3] !== t1) {
65 + x = [t1];
66 let z;
67 if (b) {
68 z = x;
@@ -74,32 +72,30 @@ function Component(t0) {
72
73 typedMutate(z, b);
74 $[2] = b;
77 - $[3] = t2;
75 + $[3] = t1;
76 $[4] = x;
79 - $[5] = t1;
77 } else {
78 x = $[4];
82 - t1 = $[5];
79 }
84 - let t3;
85 - if ($[6] !== a || $[7] !== b) {
86 - t3 = [a, b];
87 - $[6] = a;
88 - $[7] = b;
89 - $[8] = t3;
80 + let t2;
81 + if ($[5] !== a || $[6] !== b) {
82 + t2 = [a, b];
83 + $[5] = a;
84 + $[6] = b;
85 + $[7] = t2;
86 } else {
91 - t3 = $[8];
87 + t2 = $[7];
88 }
93 - let t4;
94 - if ($[9] !== t3 || $[10] !== x) {
95 - t4 = <ValidateMemoization inputs={t3} output={x} />;
96 - $[9] = t3;
97 - $[10] = x;
98 - $[11] = t4;
89 + let t3;
90 + if ($[8] !== t2 || $[9] !== x) {
91 + t3 = <ValidateMemoization inputs={t2} output={x} />;
92 + $[8] = t2;
93 + $[9] = x;
94 + $[10] = t3;
95 } else {
100 - t4 = $[11];
96 + t3 = $[10];
97 }
102 - return t4;
98 + return t3;
99 }
100
101 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/typed-identity-function-frozen-input.expect.md
+14 -16
@@ -63,15 +63,13 @@ function Component(t0) {
63 const $ = _c(7);
64 const { a, b } = t0;
65 let t1;
66 - let t2;
66 if ($[0] !== a) {
68 - t2 = makeObject_Primitives(a);
67 + t1 = makeObject_Primitives(a);
68 $[0] = a;
70 - $[1] = t2;
69 + $[1] = t1;
70 } else {
72 - t2 = $[1];
71 + t1 = $[1];
72 }
74 - t1 = t2;
73 const x = t1;
74
75 useIdentity(x);
@@ -79,24 +77,24 @@ function Component(t0) {
77 const x2 = typedIdentity(x);
78
79 identity(x2, b);
82 - let t3;
80 + let t2;
81 if ($[2] !== a) {
84 - t3 = [a];
82 + t2 = [a];
83 $[2] = a;
86 - $[3] = t3;
84 + $[3] = t2;
85 } else {
88 - t3 = $[3];
86 + t2 = $[3];
87 }
90 - let t4;
91 - if ($[4] !== t3 || $[5] !== x) {
92 - t4 = <ValidateMemoization inputs={t3} output={x} />;
93 - $[4] = t3;
88 + let t3;
89 + if ($[4] !== t2 || $[5] !== x) {
90 + t3 = <ValidateMemoization inputs={t2} output={x} />;
91 + $[4] = t2;
92 $[5] = x;
95 - $[6] = t4;
93 + $[6] = t3;
94 } else {
97 - t4 = $[6];
95 + t3 = $[6];
96 }
99 - return t4;
97 + return t3;
98 }
99
100 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/useMemo-reordering-depslist-assignment.expect.md
+3 -5
@@ -51,15 +51,13 @@ function useFoo(arr1, arr2) {
51 y = $[4];
52 }
53 let t1;
54 - let t2;
54 if ($[5] !== y) {
56 - t2 = { y };
55 + t1 = { y };
56 $[5] = y;
58 - $[6] = t2;
57 + $[6] = t1;
58 } else {
60 - t2 = $[6];
59 + t1 = $[6];
60 }
62 - t1 = t2;
61 return t1;
62 }
63
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-as-memo-dep.expect.md
+17 -19
@@ -42,36 +42,34 @@ function Component(t0) {
42
43 arg?.items.edges?.nodes;
44 let t1;
45 - let t2;
45 if ($[0] !== arg?.items.edges?.nodes) {
47 - t2 = arg?.items.edges?.nodes.map(identity);
46 + t1 = arg?.items.edges?.nodes.map(identity);
47 $[0] = arg?.items.edges?.nodes;
49 - $[1] = t2;
48 + $[1] = t1;
49 } else {
51 - t2 = $[1];
50 + t1 = $[1];
51 }
53 - t1 = t2;
52 const data = t1;
53
56 - const t3 = arg?.items.edges?.nodes;
57 - let t4;
58 - if ($[2] !== t3) {
59 - t4 = [t3];
60 - $[2] = t3;
61 - $[3] = t4;
54 + const t2 = arg?.items.edges?.nodes;
55 + let t3;
56 + if ($[2] !== t2) {
57 + t3 = [t2];
58 + $[2] = t2;
59 + $[3] = t3;
60 } else {
63 - t4 = $[3];
61 + t3 = $[3];
62 }
65 - let t5;
66 - if ($[4] !== data || $[5] !== t4) {
67 - t5 = <ValidateMemoization inputs={t4} output={data} />;
63 + let t4;
64 + if ($[4] !== data || $[5] !== t3) {
65 + t4 = <ValidateMemoization inputs={t3} output={data} />;
66 $[4] = data;
69 - $[5] = t4;
70 - $[6] = t5;
67 + $[5] = t3;
68 + $[6] = t4;
69 } else {
72 - t5 = $[6];
70 + t4 = $[6];
71 }
74 - return t5;
72 + return t4;
73 }
74
75 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-inverted-optionals-parallel-paths.expect.md
+5 -7
@@ -23,21 +23,19 @@ import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMe
23 import { ValidateMemoization } from "shared-runtime";
24 function Component(props) {
25 const $ = _c(2);
26 - let t0;
26
27 const x$0 = [];
28 x$0.push(props?.a.b?.c.d?.e);
29 x$0.push(props.a?.b.c?.d.e);
31 - t0 = x$0;
32 - let t1;
30 + let t0;
31 if ($[0] !== props.a.b.c.d.e) {
34 - t1 = <ValidateMemoization inputs={[props.a.b.c.d.e]} output={x} />;
32 + t0 = <ValidateMemoization inputs={[props.a.b.c.d.e]} output={x} />;
33 $[0] = props.a.b.c.d.e;
36 - $[1] = t1;
34 + $[1] = t0;
35 } else {
38 - t1 = $[1];
36 + t0 = $[1];
37 }
40 - return t1;
38 + return t0;
39 }
40
41 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-single-with-unconditional.expect.md
+12 -14
@@ -23,7 +23,6 @@ import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMe
23 import { ValidateMemoization } from "shared-runtime";
24 function Component(props) {
25 const $ = _c(7);
26 - let t0;
26 let x;
27 if ($[0] !== props.items) {
28 x = [];
@@ -34,26 +33,25 @@ function Component(props) {
33 } else {
34 x = $[1];
35 }
37 - t0 = x;
38 - const data = t0;
39 - let t1;
36 + const data = x;
37 + let t0;
38 if ($[2] !== props.items) {
41 - t1 = [props.items];
39 + t0 = [props.items];
40 $[2] = props.items;
43 - $[3] = t1;
41 + $[3] = t0;
42 } else {
45 - t1 = $[3];
43 + t0 = $[3];
44 }
47 - let t2;
48 - if ($[4] !== data || $[5] !== t1) {
49 - t2 = <ValidateMemoization inputs={t1} output={data} />;
45 + let t1;
46 + if ($[4] !== data || $[5] !== t0) {
47 + t1 = <ValidateMemoization inputs={t0} output={data} />;
48 $[4] = data;
51 - $[5] = t1;
52 - $[6] = t2;
49 + $[5] = t0;
50 + $[6] = t1;
51 } else {
54 - t2 = $[6];
52 + t1 = $[6];
53 }
56 - return t2;
54 + return t1;
55 }
56
57 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-single.expect.md
+15 -17
@@ -38,7 +38,6 @@ function Component(t0) {
38 const { arg } = t0;
39
40 arg?.items;
41 - let t1;
41 let x;
42 if ($[0] !== arg?.items) {
43 x = [];
@@ -48,27 +47,26 @@ function Component(t0) {
47 } else {
48 x = $[1];
49 }
51 - t1 = x;
52 - const data = t1;
53 - const t2 = arg?.items;
54 - let t3;
55 - if ($[2] !== t2) {
56 - t3 = [t2];
57 - $[2] = t2;
58 - $[3] = t3;
50 + const data = x;
51 + const t1 = arg?.items;
52 + let t2;
53 + if ($[2] !== t1) {
54 + t2 = [t1];
55 + $[2] = t1;
56 + $[3] = t2;
57 } else {
60 - t3 = $[3];
58 + t2 = $[3];
59 }
62 - let t4;
63 - if ($[4] !== data || $[5] !== t3) {
64 - t4 = <ValidateMemoization inputs={t3} output={data} />;
60 + let t3;
61 + if ($[4] !== data || $[5] !== t2) {
62 + t3 = <ValidateMemoization inputs={t2} output={data} />;
63 $[4] = data;
66 - $[5] = t3;
67 - $[6] = t4;
64 + $[5] = t2;
65 + $[6] = t3;
66 } else {
69 - t4 = $[6];
67 + t3 = $[6];
68 }
71 - return t4;
69 + return t3;
70 }
71
72 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/maybe-invalid-useMemo-no-memoblock-sideeffect.expect.md
-2
@@ -36,11 +36,9 @@ import { useMemo } from "react";
36 // (i.e. inferred non-mutable or non-escaping values don't get memoized)
37 function useFoo(t0) {
38 const { minWidth, styles, setStyles } = t0;
39 - let t1;
39 if (styles.width > minWidth) {
40 setStyles(styles);
41 }
43 - t1 = undefined;
42 }
43
44 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/prune-nonescaping-useMemo.expect.md
+1 -4
@@ -34,10 +34,7 @@ import { identity } from "shared-runtime";
34 * This is technically a false positive, although it makes sense
35 * to bailout as source code might be doing something sketchy.
36 */
37 -function useFoo(x) {
38 - let t0;
39 - t0 = identity(x);
40 -}
37 +function useFoo(x) {}
38
39 export const FIXTURE_ENTRYPOINT = {
40 fn: useFoo,
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/todo-ensure-constant-prop-decls-get-removed.expect.md
+3 -5
@@ -40,14 +40,12 @@ function useFoo() {
40 const $ = _c(1);
41 const constVal = 0;
42 let t0;
43 - let t1;
43 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
45 - t1 = [0];
46 - $[0] = t1;
44 + t0 = [0];
45 + $[0] = t0;
46 } else {
48 - t1 = $[0];
47 + t0 = $[0];
48 }
50 - t0 = t1;
49 return t0;
50 }
51
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-alias-property-load-dep.expect.md
+3 -5
@@ -32,16 +32,14 @@ function Component(t0) {
32 const { propA, propB } = t0;
33 const x = propB.x.y;
34 let t1;
35 - let t2;
35 if ($[0] !== propA.x || $[1] !== x) {
37 - t2 = sum(propA.x, x);
36 + t1 = sum(propA.x, x);
37 $[0] = propA.x;
38 $[1] = x;
40 - $[2] = t2;
39 + $[2] = t1;
40 } else {
42 - t2 = $[2];
41 + t1 = $[2];
42 }
44 - t1 = t2;
43 return t1;
44 }
45
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-alloc.expect.md
+14 -16
@@ -32,28 +32,26 @@ import { identity } from "shared-runtime";
32 function Component(t0) {
33 const $ = _c(5);
34 const { propA, propB } = t0;
35 - let t1;
35
37 - const t2 = propB?.x.y;
38 - let t3;
39 - if ($[0] !== t2) {
40 - t3 = identity(t2);
41 - $[0] = t2;
42 - $[1] = t3;
36 + const t1 = propB?.x.y;
37 + let t2;
38 + if ($[0] !== t1) {
39 + t2 = identity(t1);
40 + $[0] = t1;
41 + $[1] = t2;
42 } else {
44 - t3 = $[1];
43 + t2 = $[1];
44 }
46 - let t4;
47 - if ($[2] !== propA || $[3] !== t3) {
48 - t4 = { value: t3, other: propA };
45 + let t3;
46 + if ($[2] !== propA || $[3] !== t2) {
47 + t3 = { value: t2, other: propA };
48 $[2] = propA;
50 - $[3] = t3;
51 - $[4] = t4;
49 + $[3] = t2;
50 + $[4] = t3;
51 } else {
53 - t4 = $[4];
52 + t3 = $[4];
53 }
55 - t1 = t4;
56 - return t1;
54 + return t3;
55 }
56
57 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-conditional-access-noAlloc.expect.md
+8 -10
@@ -30,20 +30,18 @@ import { useMemo } from "react";
30 function Component(t0) {
31 const $ = _c(3);
32 const { propA, propB } = t0;
33 - let t1;
33
35 - const t2 = propB?.x.y;
36 - let t3;
37 - if ($[0] !== propA || $[1] !== t2) {
38 - t3 = { value: t2, other: propA };
34 + const t1 = propB?.x.y;
35 + let t2;
36 + if ($[0] !== propA || $[1] !== t1) {
37 + t2 = { value: t1, other: propA };
38 $[0] = propA;
40 - $[1] = t2;
41 - $[2] = t3;
39 + $[1] = t1;
40 + $[2] = t2;
41 } else {
43 - t3 = $[2];
42 + t2 = $[2];
43 }
45 - t1 = t3;
46 - return t1;
44 + return t2;
45 }
46
47 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-constant-prop.expect.md
+13 -17
@@ -37,39 +37,35 @@ function useFoo(cond) {
37 const $ = _c(5);
38 const sourceDep = 0;
39 let t0;
40 - let t1;
40 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
42 - t1 = identity(0);
43 - $[0] = t1;
41 + t0 = identity(0);
42 + $[0] = t0;
43 } else {
45 - t1 = $[0];
44 + t0 = $[0];
45 }
47 - t0 = t1;
46 const derived1 = t0;
47
48 const derived2 = (cond ?? Math.min(0, 1)) ? 1 : 2;
51 - let t2;
52 - let t3;
49 + let t1;
50 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
54 - t3 = identity(0);
55 - $[1] = t3;
51 + t1 = identity(0);
52 + $[1] = t1;
53 } else {
57 - t3 = $[1];
54 + t1 = $[1];
55 }
59 - t2 = t3;
60 - const derived3 = t2;
56 + const derived3 = t1;
57
58 const derived4 = (Math.min(0, -1) ?? cond) ? 1 : 2;
63 - let t4;
59 + let t2;
60 if ($[2] !== derived2 || $[3] !== derived4) {
65 - t4 = [derived1, derived2, derived3, derived4];
61 + t2 = [derived1, derived2, derived3, derived4];
62 $[2] = derived2;
63 $[3] = derived4;
68 - $[4] = t4;
64 + $[4] = t2;
65 } else {
70 - t4 = $[4];
66 + t2 = $[4];
67 }
72 - return t4;
68 + return t2;
69 }
70
71 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-dep-array-literal-access.expect.md
+3 -5
@@ -48,15 +48,13 @@ function Foo(props) {
48 }
49 const x = t0;
50 let t1;
51 - let t2;
51 if ($[2] !== x[0]) {
53 - t2 = [x[0]];
52 + t1 = [x[0]];
53 $[2] = x[0];
55 - $[3] = t2;
54 + $[3] = t1;
55 } else {
57 - t2 = $[3];
56 + t1 = $[3];
57 }
59 - t1 = t2;
58 return t1;
59 }
60
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-in-other-reactive-block.expect.md
+8 -10
@@ -42,19 +42,17 @@ function useFoo(minWidth, otherProp) {
42 let t0;
43 if ($[0] !== minWidth || $[1] !== otherProp || $[2] !== width) {
44 const x = [];
45 - let t1;
45
47 - const t2 = Math.max(minWidth, width);
48 - let t3;
49 - if ($[4] !== t2) {
50 - t3 = { width: t2 };
51 - $[4] = t2;
52 - $[5] = t3;
46 + const t1 = Math.max(minWidth, width);
47 + let t2;
48 + if ($[4] !== t1) {
49 + t2 = { width: t1 };
50 + $[4] = t1;
51 + $[5] = t2;
52 } else {
54 - t3 = $[5];
53 + t2 = $[5];
54 }
56 - t1 = t3;
57 - const style = t1;
55 + const style = t2;
56
57 arrayPush(x, otherProp);
58 t0 = [style, x];
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-fewer-deps.expect.md
+3 -5
@@ -29,15 +29,13 @@ import { useMemo } from "react";
29 function useFoo(a, b) {
30 const $ = _c(2);
31 let t0;
32 - let t1;
32 if ($[0] !== a) {
34 - t1 = [a];
33 + t0 = [a];
34 $[0] = a;
36 - $[1] = t1;
35 + $[1] = t0;
36 } else {
38 - t1 = $[1];
37 + t0 = $[1];
38 }
40 - t0 = t1;
39 return t0;
40 }
41
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-more-specific.expect.md
+3 -5
@@ -37,15 +37,13 @@ import { useMemo } from "react";
37 function useHook(x) {
38 const $ = _c(2);
39 let t0;
40 - let t1;
40 if ($[0] !== x.y.z) {
42 - t1 = [x.y.z];
41 + t0 = [x.y.z];
42 $[0] = x.y.z;
44 - $[1] = t1;
43 + $[1] = t0;
44 } else {
46 - t1 = $[1];
45 + t0 = $[1];
46 }
48 - t0 = t1;
47 return t0;
48 }
49
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-nonallocating.expect.md
+1 -3
@@ -29,9 +29,7 @@ import { useMemo } from "react";
29 // It's correct to infer a useMemo value is non-allocating
30 // and not provide it with a reactive scope
31 function useFoo(num1, num2) {
32 - let t0;
33 - t0 = Math.min(num1, num2);
34 - return t0;
32 + return Math.min(num1, num2);
33 }
34
35 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-infer-scope-global.expect.md
+3 -5
@@ -31,14 +31,12 @@ import { CONST_STRING0 } from "shared-runtime";
31 function useFoo() {
32 const $ = _c(1);
33 let t0;
34 - let t1;
34 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36 - t1 = [CONST_STRING0];
37 - $[0] = t1;
35 + t0 = [CONST_STRING0];
36 + $[0] = t0;
37 } else {
39 - t1 = $[0];
38 + t0 = $[0];
39 }
41 - t0 = t1;
40 return t0;
41 }
42
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-inner-decl.expect.md
+9 -11
@@ -30,25 +30,23 @@ import { identity } from "shared-runtime";
30 function useFoo(data) {
31 const $ = _c(4);
32 let t0;
33 - let t1;
33 if ($[0] !== data.a) {
35 - t1 = identity(data.a);
34 + t0 = identity(data.a);
35 $[0] = data.a;
37 - $[1] = t1;
36 + $[1] = t0;
37 } else {
39 - t1 = $[1];
38 + t0 = $[1];
39 }
41 - const temp = t1;
42 - let t2;
40 + const temp = t0;
41 + let t1;
42 if ($[2] !== temp) {
44 - t2 = { temp };
43 + t1 = { temp };
44 $[2] = temp;
46 - $[3] = t2;
45 + $[3] = t1;
46 } else {
48 - t2 = $[3];
47 + t1 = $[3];
48 }
50 - t0 = t2;
51 - return t0;
49 + return t1;
50 }
51
52 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-invoke-prop.expect.md
+3 -5
@@ -35,15 +35,13 @@ function useFoo(t0) {
35 const $ = _c(2);
36 const { callback } = t0;
37 let t1;
38 - let t2;
38 if ($[0] !== callback) {
40 - t2 = new Array(callback());
39 + t1 = new Array(callback());
40 $[0] = callback;
42 - $[1] = t2;
41 + $[1] = t1;
42 } else {
44 - t2 = $[1];
43 + t1 = $[1];
44 }
46 - t1 = t2;
45 return t1;
46 }
47
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-assignment.expect.md
+3 -5
@@ -50,15 +50,13 @@ function useFoo(arr1, arr2) {
50 y = $[4];
51 }
52 let t1;
53 - let t2;
53 if ($[5] !== y) {
55 - t2 = { y };
54 + t1 = { y };
55 $[5] = y;
57 - $[6] = t2;
56 + $[6] = t1;
57 } else {
59 - t2 = $[6];
58 + t1 = $[6];
59 }
61 - t1 = t2;
60 return t1;
61 }
62
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-reordering-depslist-controlflow.expect.md
+3 -5
@@ -49,14 +49,12 @@ function Foo(t0) {
49
50 let y = [];
51 let t2;
52 - let t3;
52 if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
54 - t3 = { x: 2 };
55 - $[5] = t3;
53 + t2 = { x: 2 };
54 + $[5] = t2;
55 } else {
57 - t3 = $[5];
56 + t2 = $[5];
57 }
59 - t2 = t3;
58 val1 = t2;
59
60 foo ? (y = x.concat(arr2)) : y;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/preserve-memo-validation/useMemo-with-no-depslist.expect.md
+3 -5
@@ -33,15 +33,13 @@ function Component(t0) {
33 const $ = _c(2);
34 const { propA } = t0;
35 let t1;
36 - let t2;
36 if ($[0] !== propA) {
38 - t2 = [propA];
37 + t1 = [propA];
38 $[0] = propA;
40 - $[1] = t2;
39 + $[1] = t1;
40 } else {
42 - t2 = $[1];
41 + t1 = $[1];
42 }
44 - t1 = t2;
43 return t1;
44 }
45
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-as-memo-dep.expect.md
+17 -19
@@ -42,36 +42,34 @@ function Component(t0) {
42
43 arg?.items.edges?.nodes;
44 let t1;
45 - let t2;
45 if ($[0] !== arg?.items.edges?.nodes) {
47 - t2 = arg?.items.edges?.nodes.map(identity);
46 + t1 = arg?.items.edges?.nodes.map(identity);
47 $[0] = arg?.items.edges?.nodes;
49 - $[1] = t2;
48 + $[1] = t1;
49 } else {
51 - t2 = $[1];
50 + t1 = $[1];
51 }
53 - t1 = t2;
52 const data = t1;
53
56 - const t3 = arg?.items.edges?.nodes;
57 - let t4;
58 - if ($[2] !== t3) {
59 - t4 = [t3];
60 - $[2] = t3;
61 - $[3] = t4;
54 + const t2 = arg?.items.edges?.nodes;
55 + let t3;
56 + if ($[2] !== t2) {
57 + t3 = [t2];
58 + $[2] = t2;
59 + $[3] = t3;
60 } else {
63 - t4 = $[3];
61 + t3 = $[3];
62 }
65 - let t5;
66 - if ($[4] !== data || $[5] !== t4) {
67 - t5 = <ValidateMemoization inputs={t4} output={data} />;
63 + let t4;
64 + if ($[4] !== data || $[5] !== t3) {
65 + t4 = <ValidateMemoization inputs={t3} output={data} />;
66 $[4] = data;
69 - $[5] = t4;
70 - $[6] = t5;
67 + $[5] = t3;
68 + $[6] = t4;
69 } else {
72 - t5 = $[6];
70 + t4 = $[6];
71 }
74 - return t5;
72 + return t4;
73 }
74
75 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-inverted-optionals-parallel-paths.expect.md
+5 -7
@@ -23,21 +23,19 @@ import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMe
23 import { ValidateMemoization } from "shared-runtime";
24 function Component(props) {
25 const $ = _c(2);
26 - let t0;
26
27 const x$0 = [];
28 x$0.push(props?.a.b?.c.d?.e);
29 x$0.push(props.a?.b.c?.d.e);
31 - t0 = x$0;
32 - let t1;
30 + let t0;
31 if ($[0] !== props.a.b.c.d.e) {
34 - t1 = <ValidateMemoization inputs={[props.a.b.c.d.e]} output={x} />;
32 + t0 = <ValidateMemoization inputs={[props.a.b.c.d.e]} output={x} />;
33 $[0] = props.a.b.c.d.e;
36 - $[1] = t1;
34 + $[1] = t0;
35 } else {
38 - t1 = $[1];
36 + t0 = $[1];
37 }
40 - return t1;
38 + return t0;
39 }
40
41 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single-with-unconditional.expect.md
+12 -14
@@ -23,7 +23,6 @@ import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMe
23 import { ValidateMemoization } from "shared-runtime";
24 function Component(props) {
25 const $ = _c(7);
26 - let t0;
26 let x;
27 if ($[0] !== props.items) {
28 x = [];
@@ -34,26 +33,25 @@ function Component(props) {
33 } else {
34 x = $[1];
35 }
37 - t0 = x;
38 - const data = t0;
39 - let t1;
36 + const data = x;
37 + let t0;
38 if ($[2] !== props.items) {
41 - t1 = [props.items];
39 + t0 = [props.items];
40 $[2] = props.items;
43 - $[3] = t1;
41 + $[3] = t0;
42 } else {
45 - t1 = $[3];
43 + t0 = $[3];
44 }
47 - let t2;
48 - if ($[4] !== data || $[5] !== t1) {
49 - t2 = <ValidateMemoization inputs={t1} output={data} />;
45 + let t1;
46 + if ($[4] !== data || $[5] !== t0) {
47 + t1 = <ValidateMemoization inputs={t0} output={data} />;
48 $[4] = data;
51 - $[5] = t1;
52 - $[6] = t2;
49 + $[5] = t0;
50 + $[6] = t1;
51 } else {
54 - t2 = $[6];
52 + t1 = $[6];
53 }
56 - return t2;
54 + return t1;
55 }
56
57 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single.expect.md
+15 -17
@@ -38,7 +38,6 @@ function Component(t0) {
38 const { arg } = t0;
39
40 arg?.items;
41 - let t1;
41 let x;
42 if ($[0] !== arg?.items) {
43 x = [];
@@ -48,27 +47,26 @@ function Component(t0) {
47 } else {
48 x = $[1];
49 }
51 - t1 = x;
52 - const data = t1;
53 - const t2 = arg?.items;
54 - let t3;
55 - if ($[2] !== t2) {
56 - t3 = [t2];
57 - $[2] = t2;
58 - $[3] = t3;
50 + const data = x;
51 + const t1 = arg?.items;
52 + let t2;
53 + if ($[2] !== t1) {
54 + t2 = [t1];
55 + $[2] = t1;
56 + $[3] = t2;
57 } else {
60 - t3 = $[3];
58 + t2 = $[3];
59 }
62 - let t4;
63 - if ($[4] !== data || $[5] !== t3) {
64 - t4 = <ValidateMemoization inputs={t3} output={data} />;
60 + let t3;
61 + if ($[4] !== data || $[5] !== t2) {
62 + t3 = <ValidateMemoization inputs={t2} output={data} />;
63 $[4] = data;
66 - $[5] = t3;
67 - $[6] = t4;
64 + $[5] = t2;
65 + $[6] = t3;
66 } else {
69 - t4 = $[6];
67 + t3 = $[6];
68 }
71 - return t4;
69 + return t3;
70 }
71
72 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/props-method-dependency.expect.md
+14 -16
@@ -31,34 +31,32 @@ import { ValidateMemoization } from "shared-runtime";
31 function Component(props) {
32 const $ = _c(7);
33 let t0;
34 - let t1;
34 if ($[0] !== props.x) {
36 - t1 = props.x();
35 + t0 = props.x();
36 $[0] = props.x;
38 - $[1] = t1;
37 + $[1] = t0;
38 } else {
40 - t1 = $[1];
39 + t0 = $[1];
40 }
42 - t0 = t1;
41 const x = t0;
44 - let t2;
42 + let t1;
43 if ($[2] !== props.x) {
46 - t2 = [props.x];
44 + t1 = [props.x];
45 $[2] = props.x;
48 - $[3] = t2;
46 + $[3] = t1;
47 } else {
50 - t2 = $[3];
48 + t1 = $[3];
49 }
52 - let t3;
53 - if ($[4] !== t2 || $[5] !== x) {
54 - t3 = <ValidateMemoization inputs={t2} output={x} />;
55 - $[4] = t2;
50 + let t2;
51 + if ($[4] !== t1 || $[5] !== x) {
52 + t2 = <ValidateMemoization inputs={t1} output={x} />;
53 + $[4] = t1;
54 $[5] = x;
57 - $[6] = t3;
55 + $[6] = t2;
56 } else {
59 - t3 = $[6];
57 + t2 = $[6];
58 }
61 - return t3;
59 + return t2;
60 }
61
62 const f = () => ["React"];
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/recursive-function.expect.md
+1 -3
@@ -23,9 +23,7 @@ function foo(x) {
23 if (x <= 0) {
24 return 0;
25 }
26 - let t0;
27 - t0 = foo(x - 2);
28 - return x + foo(x - 1) + t0;
26 + return x + foo(x - 1) + foo(x - 2);
27 }
28
29 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/reordering-across-blocks.expect.md
+19 -21
@@ -59,48 +59,46 @@ function Component(t0) {
59 const $ = _c(9);
60 const { config } = t0;
61 let t1;
62 - let t2;
62 if ($[0] !== config) {
64 - t2 = (event) => {
63 + t1 = (event) => {
64 config?.onA?.(event);
65 };
66 $[0] = config;
68 - $[1] = t2;
67 + $[1] = t1;
68 } else {
70 - t2 = $[1];
69 + t1 = $[1];
70 }
72 - const a = t2;
73 - let t3;
71 + const a = t1;
72 + let t2;
73 if ($[2] !== config) {
75 - t3 = (event_0) => {
74 + t2 = (event_0) => {
75 config?.onB?.(event_0);
76 };
77 $[2] = config;
79 - $[3] = t3;
78 + $[3] = t2;
79 } else {
81 - t3 = $[3];
80 + t2 = $[3];
81 }
83 - const b = t3;
84 - let t4;
82 + const b = t2;
83 + let t3;
84 if ($[4] !== a || $[5] !== b) {
86 - t4 = { b, a };
85 + t3 = { b, a };
86 $[4] = a;
87 $[5] = b;
89 - $[6] = t4;
88 + $[6] = t3;
89 } else {
91 - t4 = $[6];
90 + t3 = $[6];
91 }
93 - t1 = t4;
94 - const object = t1;
95 - let t5;
92 + const object = t3;
93 + let t4;
94 if ($[7] !== object) {
97 - t5 = <Stringify value={object} />;
95 + t4 = <Stringify value={object} />;
96 $[7] = object;
99 - $[8] = t5;
97 + $[8] = t4;
98 } else {
101 - t5 = $[8];
99 + t4 = $[8];
100 }
103 - return t5;
101 + return t4;
102 }
103
104 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-missing-memoization-lack-of-phi-types-explicit-types.expect.md
+8 -10
@@ -65,20 +65,18 @@ function Component() {
65 }
66 const filtered = t2;
67 let t3;
68 - let t4;
68 if ($[6] !== filtered) {
70 - t4 = filtered.map();
69 + t3 = filtered.map();
70 $[6] = filtered;
72 - $[7] = t4;
71 + $[7] = t3;
72 } else {
74 - t4 = $[7];
73 + t3 = $[7];
74 }
76 - t3 = t4;
75 const map = t3;
76 const index = filtered.findIndex(_temp3);
79 - let t5;
77 + let t4;
78 if ($[8] !== index || $[9] !== map) {
81 - t5 = (
79 + t4 = (
80 <div>
81 {map}
82 {index}
@@ -86,11 +84,11 @@ function Component() {
84 );
85 $[8] = index;
86 $[9] = map;
89 - $[10] = t5;
87 + $[10] = t4;
88 } else {
91 - t5 = $[10];
89 + t4 = $[10];
90 }
93 - return t5;
91 + return t4;
92 }
93 function _temp3(x) {
94 return x === null;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-missing-memoization-lack-of-phi-types.expect.md
+8 -10
@@ -62,20 +62,18 @@ function Component() {
62 }
63 const filtered = t2;
64 let t3;
65 - let t4;
65 if ($[6] !== filtered) {
67 - t4 = filtered.map();
66 + t3 = filtered.map();
67 $[6] = filtered;
69 - $[7] = t4;
68 + $[7] = t3;
69 } else {
71 - t4 = $[7];
70 + t3 = $[7];
71 }
73 - t3 = t4;
72 const map = t3;
73 const index = filtered.findIndex(_temp3);
76 - let t5;
74 + let t4;
75 if ($[8] !== index || $[9] !== map) {
78 - t5 = (
76 + t4 = (
77 <div>
78 {map}
79 {index}
@@ -83,11 +81,11 @@ function Component() {
81 );
82 $[8] = index;
83 $[9] = map;
86 - $[10] = t5;
84 + $[10] = t4;
85 } else {
88 - t5 = $[10];
86 + t4 = $[10];
87 }
90 - return t5;
88 + return t4;
89 }
90 function _temp3(x) {
91 return x === null;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-no-declarations-in-reactive-scope-with-early-return.expect.md
+23 -27
@@ -39,55 +39,51 @@ function Component() {
39 ```javascript
40 import { c as _c } from "react/compiler-runtime"; // @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
41 function Component() {
42 - const $ = _c(7);
42 + const $ = _c(6);
43 const items = useItems();
44 let t0;
45 let t1;
46 - let t2;
46 if ($[0] !== items) {
48 - t2 = Symbol.for("react.early_return_sentinel");
47 + t1 = Symbol.for("react.early_return_sentinel");
48 bb0: {
50 - t0 = items.filter(_temp);
51 - const filteredItems = t0;
49 + const filteredItems = items.filter(_temp);
50 if (filteredItems.length === 0) {
53 - let t3;
54 - if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
55 - t3 = (
51 + let t2;
52 + if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
53 + t2 = (
54 <div>
55 <span />
56 </div>
57 );
60 - $[4] = t3;
58 + $[3] = t2;
59 } else {
62 - t3 = $[4];
60 + t2 = $[3];
61 }
64 - t2 = t3;
62 + t1 = t2;
63 break bb0;
64 }
65
68 - t1 = filteredItems.map(_temp2);
66 + t0 = filteredItems.map(_temp2);
67 }
68 $[0] = items;
71 - $[1] = t1;
72 - $[2] = t2;
73 - $[3] = t0;
69 + $[1] = t0;
70 + $[2] = t1;
71 } else {
75 - t1 = $[1];
76 - t2 = $[2];
77 - t0 = $[3];
72 + t0 = $[1];
73 + t1 = $[2];
74 }
79 - if (t2 !== Symbol.for("react.early_return_sentinel")) {
80 - return t2;
75 + if (t1 !== Symbol.for("react.early_return_sentinel")) {
76 + return t1;
77 }
82 - let t3;
83 - if ($[5] !== t1) {
84 - t3 = <>{t1}</>;
85 - $[5] = t1;
86 - $[6] = t3;
78 + let t2;
79 + if ($[4] !== t0) {
80 + t2 = <>{t0}</>;
81 + $[4] = t0;
82 + $[5] = t2;
83 } else {
88 - t3 = $[6];
84 + t2 = $[5];
85 }
90 - return t3;
86 + return t2;
87 }
88 function _temp2(t0) {
89 const [item_0] = t0;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-renaming-conflicting-decls.expect.md
+39 -43
@@ -45,87 +45,83 @@ import { Stringify, identity, makeArray, toJSON } from "shared-runtime";
45 import { useMemo } from "react";
46
47 function Component(props) {
48 - const $ = _c(13);
48 + const $ = _c(12);
49 let t0;
50 let t1;
51 - let t2;
51 if ($[0] !== props) {
53 - t2 = Symbol.for("react.early_return_sentinel");
52 + t1 = Symbol.for("react.early_return_sentinel");
53 bb0: {
55 - t0 = toJSON(props);
56 - const propsString = t0;
54 + const propsString = toJSON(props);
55 if (propsString.length <= 2) {
58 - t2 = null;
56 + t1 = null;
57 break bb0;
58 }
59
62 - t1 = identity(propsString);
60 + t0 = identity(propsString);
61 }
62 $[0] = props;
65 - $[1] = t1;
66 - $[2] = t2;
67 - $[3] = t0;
63 + $[1] = t0;
64 + $[2] = t1;
65 } else {
69 - t1 = $[1];
70 - t2 = $[2];
71 - t0 = $[3];
66 + t0 = $[1];
67 + t1 = $[2];
68 }
73 - if (t2 !== Symbol.for("react.early_return_sentinel")) {
74 - return t2;
69 + if (t1 !== Symbol.for("react.early_return_sentinel")) {
70 + return t1;
71 }
76 - let t3;
77 - if ($[4] !== t1) {
78 - t3 = { url: t1 };
79 - $[4] = t1;
80 - $[5] = t3;
72 + let t2;
73 + if ($[3] !== t0) {
74 + t2 = { url: t0 };
75 + $[3] = t0;
76 + $[4] = t2;
77 } else {
82 - t3 = $[5];
78 + t2 = $[4];
79 }
84 - const linkProps = t3;
85 - let t4;
86 - if ($[6] !== linkProps) {
80 + const linkProps = t2;
81 + let t3;
82 + if ($[5] !== linkProps) {
83 const x = {};
84 + let t4;
85 let t5;
86 let t6;
87 let t7;
88 let t8;
92 - let t9;
93 - if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
94 - t5 = [1];
95 - t6 = [2];
96 - t7 = [3];
97 - t8 = [4];
98 - t9 = [5];
89 + if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
90 + t4 = [1];
91 + t5 = [2];
92 + t6 = [3];
93 + t7 = [4];
94 + t8 = [5];
95 + $[7] = t4;
96 $[8] = t5;
97 $[9] = t6;
98 $[10] = t7;
99 $[11] = t8;
103 - $[12] = t9;
100 } else {
101 + t4 = $[7];
102 t5 = $[8];
103 t6 = $[9];
104 t7 = $[10];
105 t8 = $[11];
109 - t9 = $[12];
106 }
111 - t4 = (
107 + t3 = (
108 <Stringify
109 link={linkProps}
114 - val1={t5}
115 - val2={t6}
116 - val3={t7}
117 - val4={t8}
118 - val5={t9}
110 + val1={t4}
111 + val2={t5}
112 + val3={t6}
113 + val4={t7}
114 + val5={t8}
115 >
116 {makeArray(x, 2)}
117 </Stringify>
118 );
123 - $[6] = linkProps;
124 - $[7] = t4;
119 + $[5] = linkProps;
120 + $[6] = t3;
121 } else {
126 - t4 = $[7];
122 + t3 = $[6];
123 }
128 - return t4;
124 + return t3;
125 }
126
127 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro.expect.md
+11 -15
@@ -24,10 +24,9 @@ function Component(props) {
24 ```javascript
25 import { c as _c } from "react/compiler-runtime";
26 function Component(props) {
27 - const $ = _c(7);
27 + const $ = _c(6);
28 const item = props.item;
29 let baseVideos;
30 - let t0;
30 let thumbnails;
31 if ($[0] !== item) {
32 thumbnails = [];
@@ -41,24 +40,21 @@ function Component(props) {
40 });
41 $[0] = item;
42 $[1] = baseVideos;
44 - $[2] = t0;
45 - $[3] = thumbnails;
43 + $[2] = thumbnails;
44 } else {
45 baseVideos = $[1];
48 - t0 = $[2];
49 - thumbnails = $[3];
46 + thumbnails = $[2];
47 }
51 - t0 = undefined;
52 - let t1;
53 - if ($[4] !== baseVideos || $[5] !== thumbnails) {
54 - t1 = <FlatList baseVideos={baseVideos} items={thumbnails} />;
55 - $[4] = baseVideos;
56 - $[5] = thumbnails;
57 - $[6] = t1;
48 + let t0;
49 + if ($[3] !== baseVideos || $[4] !== thumbnails) {
50 + t0 = <FlatList baseVideos={baseVideos} items={thumbnails} />;
51 + $[3] = baseVideos;
52 + $[4] = thumbnails;
53 + $[5] = t0;
54 } else {
59 - t1 = $[6];
55 + t0 = $[5];
56 }
61 - return t1;
57 + return t0;
58 }
59
60 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-provider-log-default-import.expect.md
+37 -41
@@ -47,77 +47,73 @@ export function Component(t0) {
47 const $ = _c(17);
48 const { a, b } = t0;
49 let t1;
50 - let t2;
50 if ($[0] !== a) {
52 - t2 = { a };
51 + t1 = { a };
52 $[0] = a;
54 - $[1] = t2;
53 + $[1] = t1;
54 } else {
56 - t2 = $[1];
55 + t1 = $[1];
56 }
58 - t1 = t2;
57 const item1 = t1;
60 - let t3;
61 - let t4;
58 + let t2;
59 if ($[2] !== b) {
63 - t4 = { b };
60 + t2 = { b };
61 $[2] = b;
65 - $[3] = t4;
62 + $[3] = t2;
63 } else {
67 - t4 = $[3];
64 + t2 = $[3];
65 }
69 - t3 = t4;
70 - const item2 = t3;
66 + const item2 = t2;
67 typedLog(item1, item2);
72 - let t5;
68 + let t3;
69 if ($[4] !== a) {
74 - t5 = [a];
70 + t3 = [a];
71 $[4] = a;
76 - $[5] = t5;
72 + $[5] = t3;
73 } else {
78 - t5 = $[5];
74 + t3 = $[5];
75 }
80 - let t6;
81 - if ($[6] !== item1 || $[7] !== t5) {
82 - t6 = <ValidateMemoization inputs={t5} output={item1} />;
76 + let t4;
77 + if ($[6] !== item1 || $[7] !== t3) {
78 + t4 = <ValidateMemoization inputs={t3} output={item1} />;
79 $[6] = item1;
84 - $[7] = t5;
85 - $[8] = t6;
80 + $[7] = t3;
81 + $[8] = t4;
82 } else {
87 - t6 = $[8];
83 + t4 = $[8];
84 }
89 - let t7;
85 + let t5;
86 if ($[9] !== b) {
91 - t7 = [b];
87 + t5 = [b];
88 $[9] = b;
93 - $[10] = t7;
89 + $[10] = t5;
90 } else {
95 - t7 = $[10];
91 + t5 = $[10];
92 }
97 - let t8;
98 - if ($[11] !== item2 || $[12] !== t7) {
99 - t8 = <ValidateMemoization inputs={t7} output={item2} />;
93 + let t6;
94 + if ($[11] !== item2 || $[12] !== t5) {
95 + t6 = <ValidateMemoization inputs={t5} output={item2} />;
96 $[11] = item2;
101 - $[12] = t7;
102 - $[13] = t8;
97 + $[12] = t5;
98 + $[13] = t6;
99 } else {
104 - t8 = $[13];
100 + t6 = $[13];
101 }
106 - let t9;
107 - if ($[14] !== t6 || $[15] !== t8) {
108 - t9 = (
102 + let t7;
103 + if ($[14] !== t4 || $[15] !== t6) {
104 + t7 = (
105 <>
106 + {t4}
107 {t6}
111 - {t8}
108 </>
109 );
114 - $[14] = t6;
115 - $[15] = t8;
116 - $[16] = t9;
110 + $[14] = t4;
111 + $[15] = t6;
112 + $[16] = t7;
113 } else {
118 - t9 = $[16];
114 + t7 = $[16];
115 }
120 - return t9;
116 + return t7;
117 }
118
119 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-provider-log.expect.md
+37 -41
@@ -45,77 +45,73 @@ export function Component(t0) {
45 const $ = _c(17);
46 const { a, b } = t0;
47 let t1;
48 - let t2;
48 if ($[0] !== a) {
50 - t2 = { a };
49 + t1 = { a };
50 $[0] = a;
52 - $[1] = t2;
51 + $[1] = t1;
52 } else {
54 - t2 = $[1];
53 + t1 = $[1];
54 }
56 - t1 = t2;
55 const item1 = t1;
58 - let t3;
59 - let t4;
56 + let t2;
57 if ($[2] !== b) {
61 - t4 = { b };
58 + t2 = { b };
59 $[2] = b;
63 - $[3] = t4;
60 + $[3] = t2;
61 } else {
65 - t4 = $[3];
62 + t2 = $[3];
63 }
67 - t3 = t4;
68 - const item2 = t3;
64 + const item2 = t2;
65 typedLog(item1, item2);
70 - let t5;
66 + let t3;
67 if ($[4] !== a) {
72 - t5 = [a];
68 + t3 = [a];
69 $[4] = a;
74 - $[5] = t5;
70 + $[5] = t3;
71 } else {
76 - t5 = $[5];
72 + t3 = $[5];
73 }
78 - let t6;
79 - if ($[6] !== item1 || $[7] !== t5) {
80 - t6 = <ValidateMemoization inputs={t5} output={item1} />;
74 + let t4;
75 + if ($[6] !== item1 || $[7] !== t3) {
76 + t4 = <ValidateMemoization inputs={t3} output={item1} />;
77 $[6] = item1;
82 - $[7] = t5;
83 - $[8] = t6;
78 + $[7] = t3;
79 + $[8] = t4;
80 } else {
85 - t6 = $[8];
81 + t4 = $[8];
82 }
87 - let t7;
83 + let t5;
84 if ($[9] !== b) {
89 - t7 = [b];
85 + t5 = [b];
86 $[9] = b;
91 - $[10] = t7;
87 + $[10] = t5;
88 } else {
93 - t7 = $[10];
89 + t5 = $[10];
90 }
95 - let t8;
96 - if ($[11] !== item2 || $[12] !== t7) {
97 - t8 = <ValidateMemoization inputs={t7} output={item2} />;
91 + let t6;
92 + if ($[11] !== item2 || $[12] !== t5) {
93 + t6 = <ValidateMemoization inputs={t5} output={item2} />;
94 $[11] = item2;
99 - $[12] = t7;
100 - $[13] = t8;
95 + $[12] = t5;
96 + $[13] = t6;
97 } else {
102 - t8 = $[13];
98 + t6 = $[13];
99 }
104 - let t9;
105 - if ($[14] !== t6 || $[15] !== t8) {
106 - t9 = (
100 + let t7;
101 + if ($[14] !== t4 || $[15] !== t6) {
102 + t7 = (
103 <>
104 + {t4}
105 {t6}
109 - {t8}
106 </>
107 );
112 - $[14] = t6;
113 - $[15] = t8;
114 - $[16] = t9;
108 + $[14] = t4;
109 + $[15] = t6;
110 + $[16] = t7;
111 } else {
116 - t9 = $[16];
112 + t7 = $[16];
113 }
118 - return t9;
114 + return t7;
115 }
116
117 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-provider-store-capture-namespace-import.expect.md
+51 -57
@@ -51,28 +51,23 @@ export function Component(t0) {
51 const $ = _c(27);
52 const { a, b } = t0;
53 let t1;
54 - let t2;
54 if ($[0] !== a) {
56 - t2 = { a };
55 + t1 = { a };
56 $[0] = a;
58 - $[1] = t2;
57 + $[1] = t1;
58 } else {
60 - t2 = $[1];
59 + t1 = $[1];
60 }
62 - t1 = t2;
61 const item1 = t1;
64 - let t3;
65 - let t4;
62 + let t2;
63 if ($[2] !== b) {
67 - t4 = { b };
64 + t2 = { b };
65 $[2] = b;
69 - $[3] = t4;
66 + $[3] = t2;
67 } else {
71 - t4 = $[3];
68 + t2 = $[3];
69 }
73 - t3 = t4;
74 - const item2 = t3;
75 - let t5;
70 + const item2 = t2;
71 let items;
72 if ($[4] !== item1 || $[5] !== item2) {
73 items = [];
@@ -84,77 +79,76 @@ export function Component(t0) {
79 } else {
80 items = $[6];
81 }
87 - t5 = items;
88 - const items_0 = t5;
89 - let t6;
82 + const items_0 = items;
83 + let t3;
84 if ($[7] !== a) {
91 - t6 = [a];
85 + t3 = [a];
86 $[7] = a;
93 - $[8] = t6;
87 + $[8] = t3;
88 } else {
95 - t6 = $[8];
89 + t3 = $[8];
90 }
97 - let t7;
98 - if ($[9] !== items_0[0] || $[10] !== t6) {
99 - t7 = <SharedRuntime.ValidateMemoization inputs={t6} output={items_0[0]} />;
91 + let t4;
92 + if ($[9] !== items_0[0] || $[10] !== t3) {
93 + t4 = <SharedRuntime.ValidateMemoization inputs={t3} output={items_0[0]} />;
94 $[9] = items_0[0];
101 - $[10] = t6;
102 - $[11] = t7;
95 + $[10] = t3;
96 + $[11] = t4;
97 } else {
104 - t7 = $[11];
98 + t4 = $[11];
99 }
106 - let t8;
100 + let t5;
101 if ($[12] !== b) {
108 - t8 = [b];
102 + t5 = [b];
103 $[12] = b;
110 - $[13] = t8;
104 + $[13] = t5;
105 } else {
112 - t8 = $[13];
106 + t5 = $[13];
107 }
114 - let t9;
115 - if ($[14] !== items_0[1] || $[15] !== t8) {
116 - t9 = <SharedRuntime.ValidateMemoization inputs={t8} output={items_0[1]} />;
108 + let t6;
109 + if ($[14] !== items_0[1] || $[15] !== t5) {
110 + t6 = <SharedRuntime.ValidateMemoization inputs={t5} output={items_0[1]} />;
111 $[14] = items_0[1];
118 - $[15] = t8;
119 - $[16] = t9;
112 + $[15] = t5;
113 + $[16] = t6;
114 } else {
121 - t9 = $[16];
115 + t6 = $[16];
116 }
123 - let t10;
117 + let t7;
118 if ($[17] !== a || $[18] !== b) {
125 - t10 = [a, b];
119 + t7 = [a, b];
120 $[17] = a;
121 $[18] = b;
128 - $[19] = t10;
122 + $[19] = t7;
123 } else {
130 - t10 = $[19];
124 + t7 = $[19];
125 }
132 - let t11;
133 - if ($[20] !== items_0 || $[21] !== t10) {
134 - t11 = <SharedRuntime.ValidateMemoization inputs={t10} output={items_0} />;
126 + let t8;
127 + if ($[20] !== items_0 || $[21] !== t7) {
128 + t8 = <SharedRuntime.ValidateMemoization inputs={t7} output={items_0} />;
129 $[20] = items_0;
136 - $[21] = t10;
137 - $[22] = t11;
130 + $[21] = t7;
131 + $[22] = t8;
132 } else {
139 - t11 = $[22];
133 + t8 = $[22];
134 }
141 - let t12;
142 - if ($[23] !== t11 || $[24] !== t7 || $[25] !== t9) {
143 - t12 = (
135 + let t9;
136 + if ($[23] !== t4 || $[24] !== t6 || $[25] !== t8) {
137 + t9 = (
138 <>
145 - {t7}
146 - {t9}
147 - {t11}
139 + {t4}
140 + {t6}
141 + {t8}
142 </>
143 );
150 - $[23] = t11;
151 - $[24] = t7;
152 - $[25] = t9;
153 - $[26] = t12;
144 + $[23] = t4;
145 + $[24] = t6;
146 + $[25] = t8;
147 + $[26] = t9;
148 } else {
155 - t12 = $[26];
149 + t9 = $[26];
150 }
157 - return t12;
151 + return t9;
152 }
153
154 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/type-provider-store-capture.expect.md
+51 -57
@@ -51,28 +51,23 @@ export function Component(t0) {
51 const $ = _c(27);
52 const { a, b } = t0;
53 let t1;
54 - let t2;
54 if ($[0] !== a) {
56 - t2 = { a };
55 + t1 = { a };
56 $[0] = a;
58 - $[1] = t2;
57 + $[1] = t1;
58 } else {
60 - t2 = $[1];
59 + t1 = $[1];
60 }
62 - t1 = t2;
61 const item1 = t1;
64 - let t3;
65 - let t4;
62 + let t2;
63 if ($[2] !== b) {
67 - t4 = { b };
64 + t2 = { b };
65 $[2] = b;
69 - $[3] = t4;
66 + $[3] = t2;
67 } else {
71 - t4 = $[3];
68 + t2 = $[3];
69 }
73 - t3 = t4;
74 - const item2 = t3;
75 - let t5;
70 + const item2 = t2;
71 let items;
72 if ($[4] !== item1 || $[5] !== item2) {
73 items = [];
@@ -84,77 +79,76 @@ export function Component(t0) {
79 } else {
80 items = $[6];
81 }
87 - t5 = items;
88 - const items_0 = t5;
89 - let t6;
82 + const items_0 = items;
83 + let t3;
84 if ($[7] !== a) {
91 - t6 = [a];
85 + t3 = [a];
86 $[7] = a;
93 - $[8] = t6;
87 + $[8] = t3;
88 } else {
95 - t6 = $[8];
89 + t3 = $[8];
90 }
97 - let t7;
98 - if ($[9] !== items_0[0] || $[10] !== t6) {
99 - t7 = <ValidateMemoization inputs={t6} output={items_0[0]} />;
91 + let t4;
92 + if ($[9] !== items_0[0] || $[10] !== t3) {
93 + t4 = <ValidateMemoization inputs={t3} output={items_0[0]} />;
94 $[9] = items_0[0];
101 - $[10] = t6;
102 - $[11] = t7;
95 + $[10] = t3;
96 + $[11] = t4;
97 } else {
104 - t7 = $[11];
98 + t4 = $[11];
99 }
106 - let t8;
100 + let t5;
101 if ($[12] !== b) {
108 - t8 = [b];
102 + t5 = [b];
103 $[12] = b;
110 - $[13] = t8;
104 + $[13] = t5;
105 } else {
112 - t8 = $[13];
106 + t5 = $[13];
107 }
114 - let t9;
115 - if ($[14] !== items_0[1] || $[15] !== t8) {
116 - t9 = <ValidateMemoization inputs={t8} output={items_0[1]} />;
108 + let t6;
109 + if ($[14] !== items_0[1] || $[15] !== t5) {
110 + t6 = <ValidateMemoization inputs={t5} output={items_0[1]} />;
111 $[14] = items_0[1];
118 - $[15] = t8;
119 - $[16] = t9;
112 + $[15] = t5;
113 + $[16] = t6;
114 } else {
121 - t9 = $[16];
115 + t6 = $[16];
116 }
123 - let t10;
117 + let t7;
118 if ($[17] !== a || $[18] !== b) {
125 - t10 = [a, b];
119 + t7 = [a, b];
120 $[17] = a;
121 $[18] = b;
128 - $[19] = t10;
122 + $[19] = t7;
123 } else {
130 - t10 = $[19];
124 + t7 = $[19];
125 }
132 - let t11;
133 - if ($[20] !== items_0 || $[21] !== t10) {
134 - t11 = <ValidateMemoization inputs={t10} output={items_0} />;
126 + let t8;
127 + if ($[20] !== items_0 || $[21] !== t7) {
128 + t8 = <ValidateMemoization inputs={t7} output={items_0} />;
129 $[20] = items_0;
136 - $[21] = t10;
137 - $[22] = t11;
130 + $[21] = t7;
131 + $[22] = t8;
132 } else {
139 - t11 = $[22];
133 + t8 = $[22];
134 }
141 - let t12;
142 - if ($[23] !== t11 || $[24] !== t7 || $[25] !== t9) {
143 - t12 = (
135 + let t9;
136 + if ($[23] !== t4 || $[24] !== t6 || $[25] !== t8) {
137 + t9 = (
138 <>
145 - {t7}
146 - {t9}
147 - {t11}
139 + {t4}
140 + {t6}
141 + {t8}
142 </>
143 );
150 - $[23] = t11;
151 - $[24] = t7;
152 - $[25] = t9;
153 - $[26] = t12;
144 + $[23] = t4;
145 + $[24] = t6;
146 + $[25] = t8;
147 + $[26] = t9;
148 } else {
155 - t12 = $[26];
149 + t9 = $[26];
150 }
157 - return t12;
151 + return t9;
152 }
153
154 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/use-operator-call-expression.expect.md
+14 -16
@@ -70,34 +70,32 @@ function Inner(props) {
70 const $ = _c(7);
71 const input = use(FooContext);
72 let t0;
73 - let t1;
73 if ($[0] !== input) {
75 - t1 = [input];
74 + t0 = [input];
75 $[0] = input;
77 - $[1] = t1;
76 + $[1] = t0;
77 } else {
79 - t1 = $[1];
78 + t0 = $[1];
79 }
81 - t0 = t1;
80 const output = t0;
83 - let t2;
81 + let t1;
82 if ($[2] !== input) {
85 - t2 = [input];
83 + t1 = [input];
84 $[2] = input;
87 - $[3] = t2;
85 + $[3] = t1;
86 } else {
89 - t2 = $[3];
87 + t1 = $[3];
88 }
91 - let t3;
92 - if ($[4] !== output || $[5] !== t2) {
93 - t3 = <ValidateMemoization inputs={t2} output={output} />;
89 + let t2;
90 + if ($[4] !== output || $[5] !== t1) {
91 + t2 = <ValidateMemoization inputs={t1} output={output} />;
92 $[4] = output;
95 - $[5] = t2;
96 - $[6] = t3;
93 + $[5] = t1;
94 + $[6] = t2;
95 } else {
98 - t3 = $[6];
96 + t2 = $[6];
97 }
100 - return t3;
98 + return t2;
99 }
100
101 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/use-operator-conditional.expect.md
+14 -16
@@ -86,34 +86,32 @@ function Inner(props) {
86
87 input;
88 let t0;
89 - let t1;
89 if ($[0] !== input) {
91 - t1 = [input];
90 + t0 = [input];
91 $[0] = input;
93 - $[1] = t1;
92 + $[1] = t0;
93 } else {
95 - t1 = $[1];
94 + t0 = $[1];
95 }
97 - t0 = t1;
96 const output = t0;
99 - let t2;
97 + let t1;
98 if ($[2] !== input) {
101 - t2 = [input];
99 + t1 = [input];
100 $[2] = input;
103 - $[3] = t2;
101 + $[3] = t1;
102 } else {
105 - t2 = $[3];
103 + t1 = $[3];
104 }
107 - let t3;
108 - if ($[4] !== output || $[5] !== t2) {
109 - t3 = <ValidateMemoization inputs={t2} output={output} />;
105 + let t2;
106 + if ($[4] !== output || $[5] !== t1) {
107 + t2 = <ValidateMemoization inputs={t1} output={output} />;
108 $[4] = output;
111 - $[5] = t2;
112 - $[6] = t3;
109 + $[5] = t1;
110 + $[6] = t2;
111 } else {
114 - t3 = $[6];
112 + t2 = $[6];
113 }
116 - return t3;
114 + return t2;
115 }
116
117 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/use-operator-method-call.expect.md
+14 -16
@@ -72,34 +72,32 @@ function Inner(props) {
72 const $ = _c(7);
73 const input = React.use(FooContext);
74 let t0;
75 - let t1;
75 if ($[0] !== input) {
77 - t1 = [input];
76 + t0 = [input];
77 $[0] = input;
79 - $[1] = t1;
78 + $[1] = t0;
79 } else {
81 - t1 = $[1];
80 + t0 = $[1];
81 }
83 - t0 = t1;
82 const output = t0;
85 - let t2;
83 + let t1;
84 if ($[2] !== input) {
87 - t2 = [input];
85 + t1 = [input];
86 $[2] = input;
89 - $[3] = t2;
87 + $[3] = t1;
88 } else {
91 - t2 = $[3];
89 + t1 = $[3];
90 }
93 - let t3;
94 - if ($[4] !== output || $[5] !== t2) {
95 - t3 = <ValidateMemoization inputs={t2} output={output} />;
91 + let t2;
92 + if ($[4] !== output || $[5] !== t1) {
93 + t2 = <ValidateMemoization inputs={t1} output={output} />;
94 $[4] = output;
97 - $[5] = t2;
98 - $[6] = t3;
95 + $[5] = t1;
96 + $[6] = t2;
97 } else {
100 - t3 = $[6];
98 + t2 = $[6];
99 }
102 - return t3;
100 + return t2;
101 }
102
103 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useEffect-global-pruned.expect.md
+8 -10
@@ -37,23 +37,21 @@ import { useEffect } from "react";
37 function someGlobal() {}
38 function useFoo() {
39 const $ = _c(2);
40 + const fn = _temp;
41 let t0;
41 - t0 = _temp;
42 - const fn = t0;
42 let t1;
44 - let t2;
43 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
46 - t1 = () => {
44 + t0 = () => {
45 fn();
46 };
49 - t2 = [fn];
50 - $[0] = t1;
51 - $[1] = t2;
47 + t1 = [fn];
48 + $[0] = t0;
49 + $[1] = t1;
50 } else {
53 - t1 = $[0];
54 - t2 = $[1];
51 + t0 = $[0];
52 + t1 = $[1];
53 }
56 - useEffect(t1, t2);
54 + useEffect(t0, t1);
55 return null;
56 }
57 function _temp() {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useEffect-namespace-pruned.expect.md
+8 -10
@@ -37,23 +37,21 @@ import * as React from "react";
37 function someGlobal() {}
38 function useFoo() {
39 const $ = _c(2);
40 + const fn = _temp;
41 let t0;
41 - t0 = _temp;
42 - const fn = t0;
42 let t1;
44 - let t2;
43 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
46 - t1 = () => {
44 + t0 = () => {
45 fn();
46 };
49 - t2 = [fn];
50 - $[0] = t1;
51 - $[1] = t2;
47 + t1 = [fn];
48 + $[0] = t0;
49 + $[1] = t1;
50 } else {
53 - t1 = $[0];
54 - t2 = $[1];
51 + t0 = $[0];
52 + t1 = $[1];
53 }
56 - React.useEffect(t1, t2);
54 + React.useEffect(t0, t1);
55 return null;
56 }
57 function _temp() {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-independently-memoizeable.expect.md
+19 -21
@@ -21,45 +21,43 @@ import { c as _c } from "react/compiler-runtime";
21 function Component(props) {
22 const $ = _c(10);
23 let t0;
24 - let t1;
24 if ($[0] !== props.a) {
26 - t1 = makeObject(props.a);
25 + t0 = makeObject(props.a);
26 $[0] = props.a;
28 - $[1] = t1;
27 + $[1] = t0;
28 } else {
30 - t1 = $[1];
29 + t0 = $[1];
30 }
32 - const a = t1;
33 - let t2;
31 + const a = t0;
32 + let t1;
33 if ($[2] !== props.b) {
35 - t2 = makeObject(props.b);
34 + t1 = makeObject(props.b);
35 $[2] = props.b;
37 - $[3] = t2;
36 + $[3] = t1;
37 } else {
39 - t2 = $[3];
38 + t1 = $[3];
39 }
41 - const b = t2;
42 - let t3;
40 + const b = t1;
41 + let t2;
42 if ($[4] !== a || $[5] !== b) {
44 - t3 = [a, b];
43 + t2 = [a, b];
44 $[4] = a;
45 $[5] = b;
47 - $[6] = t3;
46 + $[6] = t2;
47 } else {
49 - t3 = $[6];
48 + t2 = $[6];
49 }
51 - t0 = t3;
52 - const [a_0, b_0] = t0;
53 - let t4;
50 + const [a_0, b_0] = t2;
51 + let t3;
52 if ($[7] !== a_0 || $[8] !== b_0) {
55 - t4 = [a_0, b_0];
53 + t3 = [a_0, b_0];
54 $[7] = a_0;
55 $[8] = b_0;
58 - $[9] = t4;
56 + $[9] = t3;
57 } else {
60 - t4 = $[9];
58 + t3 = $[9];
59 }
62 - return t4;
60 + return t3;
61 }
62
63 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-labeled-statement-unconditional-return.expect.md
+1 -4
@@ -23,10 +23,7 @@ export const FIXTURE_ENTRYPOINT = {
23
24 ```javascript
25 function Component(props) {
26 - let t0;
27 -
28 - t0 = props.value;
29 - const x = t0;
26 + const x = props.value;
27 return x;
28 }
29
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-logical.expect.md
+1 -3
@@ -19,9 +19,7 @@ export const FIXTURE_ENTRYPOINT = {
19
20 ```javascript
21 function Component(props) {
22 - let t0;
23 - t0 = props.a && props.b;
24 - const x = t0;
22 + const x = props.a && props.b;
23 return x;
24 }
25
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-mabye-modified-free-variable-dont-preserve-memoization-guarantees.expect.md
+1 -3
@@ -51,13 +51,11 @@ function Component(props) {
51 const part = free2.part;
52
53 useHook();
54 - let t0;
54
55 const x = makeObject_Primitives();
56 x.value = props.value;
57 mutate(x, free, part);
59 - t0 = x;
60 - const object = t0;
58 + const object = x;
59
60 identity(free);
61 identity(part);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-mabye-modified-free-variable-preserve-memoization-guarantees.expect.md
+1 -3
@@ -71,7 +71,6 @@ function Component(props) {
71 const part = free2.part;
72
73 useHook();
74 - let t2;
74 let x;
75 if ($[2] !== props.value) {
76 x = makeObject_Primitives();
@@ -82,8 +81,7 @@ function Component(props) {
81 } else {
82 x = $[3];
83 }
85 - t2 = x;
86 - const object = t2;
84 + const object = x;
85
86 identity(free);
87 identity(part);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-maybe-modified-later-dont-preserve-memoization-guarantees.expect.md
+2 -6
@@ -27,18 +27,14 @@ import { useMemo } from "react";
27 import { identity, makeObject_Primitives, mutate } from "shared-runtime";
28
29 function Component(props) {
30 - const $ = _c(2);
31 - let t0;
30 + const $ = _c(1);
31 let object;
32 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
34 - t0 = makeObject_Primitives();
35 - object = t0;
33 + object = makeObject_Primitives();
34 identity(object);
35 $[0] = object;
38 - $[1] = t0;
36 } else {
37 object = $[0];
41 - t0 = $[1];
38 }
39 return object;
40 }
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-maybe-modified-later-preserve-memoization-guarantees.expect.md
+3 -5
@@ -29,14 +29,12 @@ import { identity, makeObject_Primitives, mutate } from "shared-runtime";
29 function Component(props) {
30 const $ = _c(1);
31 let t0;
32 - let t1;
32 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
34 - t1 = makeObject_Primitives();
35 - $[0] = t1;
33 + t0 = makeObject_Primitives();
34 + $[0] = t0;
35 } else {
37 - t1 = $[0];
36 + t0 = $[0];
37 }
39 - t0 = t1;
38 const object = t0;
39 identity(object);
40 return object;
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-nested-ifs.expect.md
-2
@@ -24,12 +24,10 @@ export const FIXTURE_ENTRYPOINT = {
24
25 ```javascript
26 function Component(props) {
27 - let t0;
27 if (props.cond) {
28 if (props.cond) {
29 }
30 }
32 - t0 = undefined;
31 }
32
33 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-return-empty.expect.md
-3
@@ -15,10 +15,7 @@ function component(a) {
15
16 ```javascript
17 function component(a) {
18 - let t0;
19 -
18 mutate(a);
21 - t0 = undefined;
19 }
20
21 ```
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/useMemo-simple.expect.md
+8 -10
@@ -16,25 +16,23 @@ import { c as _c } from "react/compiler-runtime";
16 function component(a) {
17 const $ = _c(4);
18 let t0;
19 - let t1;
19 if ($[0] !== a) {
21 - t1 = [a];
20 + t0 = [a];
21 $[0] = a;
23 - $[1] = t1;
22 + $[1] = t0;
23 } else {
25 - t1 = $[1];
24 + t0 = $[1];
25 }
27 - t0 = t1;
26 const x = t0;
29 - let t2;
27 + let t1;
28 if ($[2] !== x) {
31 - t2 = <Foo x={x} />;
29 + t1 = <Foo x={x} />;
30 $[2] = x;
33 - $[3] = t2;
31 + $[3] = t1;
32 } else {
35 - t2 = $[3];
33 + t1 = $[3];
34 }
37 - return t2;
35 + return t1;
36 }
37
38 ```