@samitouri / QOS-React-1 / commits / 0d3f3884b8

Fix for IIFE return values mutated later

Fixes for the previous PR. What was happening is that our inference was inferring the correct mutable ranges and reactive scopes, but the inlining process left the instructions from the IIFEs inside a separate block, with a 'label' terminal preceding it. When we converted to ReactiveFunction this was preserved as a ReactiveLabelTerminal, which meant that the first instruction for the mutable range could be nested inside one LabelTerminal, while more would be in a subsequent LabelTerminal. But we close blocks based on the block scope! This meant that we'd have leftover instructions (in the second LabelTerminal) that got left out of the block. Furthermore, because inlining was happening after EnterSSA we weren't creating phis correctly. This PR fixes a bunch of these issues, and a subsequent PR handles the remaining cases: * We move DropManualMemo and InlineIIFEs before EnterSSA. This means we lose the ability to use type information, but we ensure that we create proper SSA ids and phis for any reassignments within the IIFE * We also update PruneUnusedLabels to not just remove the unused labels, but to actually remove LabelTerminals that don't need them.

Joe Savona committed Nov 6, 2023 at 08:33 UTC 0d3f3884b871088c92a76822dd221d06bad40df6
28 files changed +194 -150
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Pipeline.ts
+12 -12
@@ -115,6 +115,18 @@ function* runWithEnvironment(
115 pruneMaybeThrows(hir);
116 yield log({ kind: "hir", name: "PruneMaybeThrows", value: hir });
117
118 + validateUseMemo(hir);
119 +
120 + dropManualMemoization(hir);
121 + yield log({ kind: "hir", name: "DropManualMemoization", value: hir });
122 +
123 + inlineImmediatelyInvokedFunctionExpressions(hir);
124 + yield log({
125 + kind: "hir",
126 + name: "InlineImmediatelyInvokedFunctionExpressions",
127 + value: hir,
128 + });
129 +
130 mergeConsecutiveBlocks(hir);
131 yield log({ kind: "hir", name: "MergeConsecutiveBlocks", value: hir });
132
@@ -135,8 +147,6 @@ function* runWithEnvironment(
147 inferTypes(hir);
148 yield log({ kind: "hir", name: "InferTypes", value: hir });
149
138 - validateUseMemo(hir);
139 -
150 if (env.config.validateHooksUsage) {
151 validateHooksUsage(hir);
152 const conditionalHooksResult = validateUnconditionalHooks(hir).unwrap();
@@ -147,16 +157,6 @@ function* runWithEnvironment(
157 });
158 }
159
150 - dropManualMemoization(hir);
151 - yield log({ kind: "hir", name: "DropManualMemoization", value: hir });
152 -
153 - inlineImmediatelyInvokedFunctionExpressions(hir);
154 - yield log({
155 - kind: "hir",
156 - name: "InlineImmediatelyInvokedFunctionExpressions",
157 - value: hir,
158 - });
159 -
160 analyseFunctions(hir);
161 yield log({ kind: "hir", name: "AnalyseFunctions", value: hir });
162
compiler/packages/babel-plugin-react-forget/src/Inference/DropManualMemoization.ts
+38 -4
@@ -5,18 +5,52 @@
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 -import { Effect, HIRFunction, getHookKind } from "../HIR";
8 +import { Effect, HIRFunction, IdentifierId } from "../HIR";
9 +import { HookKind } from "../HIR/ObjectShape";
10
11 +/**
12 + * Removes manual memoization using the `useMemo` and `useCallback` APIs. This pass is designed
13 + * to compose with InlineImmediatelyInvokedFunctionExpressions, and needs to run prior to entering
14 + * SSA form (alternatively we could refactor and re-EnterSSA after inlining). Therefore it cannot
15 + * rely on type inference to find useMemo/useCallback invocations, and instead does basic tracking
16 + * of globals and property loads to find both direct calls as well as usage via the React namespace,
17 + * eg `React.useMemo()`.
18 + */
19 export function dropManualMemoization(func: HIRFunction): void {
20 + const hooks = new Map<IdentifierId, HookKind>();
21 + const react = new Set<IdentifierId>();
22 for (const [_, block] of func.body.blocks) {
23 for (const instr of block.instructions) {
24 switch (instr.value.kind) {
25 + case "LoadGlobal": {
26 + if (
27 + instr.value.name === "useMemo" ||
28 + instr.value.name === "useCallback"
29 + ) {
30 + hooks.set(instr.lvalue.identifier.id, instr.value.name);
31 + } else if (instr.value.name === "React") {
32 + react.add(instr.lvalue.identifier.id);
33 + }
34 + break;
35 + }
36 + case "PropertyLoad": {
37 + if (react.has(instr.value.object.identifier.id)) {
38 + if (
39 + instr.value.property === "useMemo" ||
40 + instr.value.property === "useCallback"
41 + ) {
42 + hooks.set(instr.lvalue.identifier.id, instr.value.property);
43 + }
44 + }
45 + break;
46 + }
47 case "MethodCall":
48 case "CallExpression": {
16 - const hookKind =
49 + const id =
50 instr.value.kind === "CallExpression"
18 - ? getHookKind(func.env, instr.value.callee.identifier)
19 - : getHookKind(func.env, instr.value.property.identifier);
51 + ? instr.value.callee.identifier.id
52 + : instr.value.property.identifier.id;
53 + const hookKind = hooks.get(id);
54 if (hookKind != null) {
55 if (hookKind === "useMemo") {
56 const [fn] = instr.value.args;
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PruneUnusedLabels.ts
+23 -10
@@ -8,26 +8,31 @@
8 import {
9 BlockId,
10 ReactiveFunction,
11 - ReactiveTerminal,
11 + ReactiveStatement,
12 ReactiveTerminalStatement,
13 } from "../HIR/HIR";
14 -import { ReactiveFunctionVisitor, visitReactiveFunction } from "./visitors";
14 +import {
15 + ReactiveFunctionTransform,
16 + Transformed,
17 + visitReactiveFunction,
18 +} from "./visitors";
19
20 /**
17 - * Prunes terminal labels that are never explicitly jumped to.
21 + * Flattens labeled terminals where the label is not reachable, and
22 + * nulls out labels for other terminals where the label is unused.
23 */
24 export function pruneUnusedLabels(fn: ReactiveFunction): void {
25 const labels: Labels = new Set();
21 - visitReactiveFunction(fn, new Visitor(), labels);
26 + visitReactiveFunction(fn, new Transform(), labels);
27 }
28
29 type Labels = Set<BlockId>;
30
26 -class Visitor extends ReactiveFunctionVisitor<Labels> {
27 - override visitTerminal(
28 - stmt: ReactiveTerminalStatement<ReactiveTerminal>,
31 +class Transform extends ReactiveFunctionTransform<Labels> {
32 + override transformTerminal(
33 + stmt: ReactiveTerminalStatement,
34 state: Labels
30 - ): void {
35 + ): Transformed<ReactiveStatement> {
36 this.traverseTerminal(stmt, state);
37 const { terminal } = stmt;
38 if (
@@ -36,8 +41,16 @@ class Visitor extends ReactiveFunctionVisitor<Labels> {
41 ) {
42 state.add(terminal.label);
43 }
39 - if (stmt.label !== null && !state.has(stmt.label)) {
40 - stmt.label = null;
44 + // Is this terminal reachable via a break/continue to its label?
45 + const isReachableLabel = stmt.label !== null && state.has(stmt.label);
46 + if (stmt.terminal.kind === "label" && !isReachableLabel) {
47 + // Flatten labeled terminals where the label isn't necessary
48 + return { kind: "replace-many", value: stmt.terminal.block };
49 + } else {
50 + if (!isReachableLabel) {
51 + stmt.label = null;
52 + }
53 + return { kind: "keep" };
54 }
55 }
56 }
compiler/packages/babel-plugin-react-forget/src/Validation/ValidateUseMemo.ts
+12 -10
@@ -6,18 +6,20 @@
6 */
7
8 import { CompilerError } from "..";
9 -import {
10 - FunctionExpression,
11 - HIRFunction,
12 - IdentifierId,
13 - getHookKind,
14 -} from "../HIR";
9 +import { FunctionExpression, HIRFunction, IdentifierId } from "../HIR";
10
11 export function validateUseMemo(fn: HIRFunction): void {
12 + const useMemos = new Set<IdentifierId>();
13 const functions = new Map<IdentifierId, FunctionExpression>();
14 for (const [, block] of fn.body.blocks) {
15 for (const { lvalue, value } of block.instructions) {
16 switch (value.kind) {
17 + case "LoadGlobal": {
18 + if (value.name === "useMemo") {
19 + useMemos.add(lvalue.identifier.id);
20 + }
21 + break;
22 + }
23 case "FunctionExpression": {
24 functions.set(lvalue.identifier.id, value);
25 break;
@@ -27,10 +29,10 @@ export function validateUseMemo(fn: HIRFunction): void {
29 // Is the function being called useMemo, with at least 1 argument?
30 const callee =
31 value.kind === "CallExpression"
30 - ? value.callee.identifier
31 - : value.property.identifier;
32 - const hookKind = getHookKind(fn.env, callee);
33 - if (hookKind !== "useMemo" || value.args.length === 0) {
32 + ? value.callee.identifier.id
33 + : value.property.identifier.id;
34 + const isUseMemo = useMemos.has(callee);
35 + if (!isUseMemo || value.args.length === 0) {
36 continue;
37 }
38
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/babel-existing-react-import.expect.md
+6 -6
@@ -32,7 +32,7 @@ import {
32 function Component(props) {
33 const $ = useMemoCache(4);
34 const [x] = useState(0);
35 - let t35;
35 + let t15;
36 let t0;
37 if ($[0] !== x) {
38 t0 = calculateExpensiveNumber(x);
@@ -41,8 +41,8 @@ function Component(props) {
41 } else {
42 t0 = $[1];
43 }
44 - t35 = t0;
45 - const expensiveNumber = t35;
44 + t15 = t0;
45 + const expensiveNumber = t15;
46 let t1;
47 if ($[2] !== expensiveNumber) {
48 t1 = <div>{expensiveNumber}</div>;
@@ -57,7 +57,7 @@ function Component(props) {
57 function Component2(props) {
58 const $ = useMemoCache(4);
59 const [x] = useState(0);
60 - let t35;
60 + let t15;
61 let t0;
62 if ($[0] !== x) {
63 t0 = calculateExpensiveNumber(x);
@@ -66,8 +66,8 @@ function Component2(props) {
66 } else {
67 t0 = $[1];
68 }
69 - t35 = t0;
70 - const expensiveNumber = t35;
69 + t15 = t0;
70 + const expensiveNumber = t15;
71 let t1;
72 if ($[2] !== expensiveNumber) {
73 t1 = <div>{expensiveNumber}</div>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/babel-existing-react-kitchensink-import.expect.md
+6 -6
@@ -34,7 +34,7 @@ import {
34 function Component(props) {
35 const $ = useMemoCache(4);
36 const [x] = useState(0);
37 - let t35;
37 + let t15;
38 let t0;
39 if ($[0] !== x) {
40 t0 = calculateExpensiveNumber(x);
@@ -43,8 +43,8 @@ function Component(props) {
43 } else {
44 t0 = $[1];
45 }
46 - t35 = t0;
47 - const expensiveNumber = t35;
46 + t15 = t0;
47 + const expensiveNumber = t15;
48 let t1;
49 if ($[2] !== expensiveNumber) {
50 t1 = <div>{expensiveNumber}</div>;
@@ -59,7 +59,7 @@ function Component(props) {
59 function Component2(props) {
60 const $ = useMemoCache(4);
61 const [x] = useState(0);
62 - let t35;
62 + let t15;
63 let t0;
64 if ($[0] !== x) {
65 t0 = calculateExpensiveNumber(x);
@@ -68,8 +68,8 @@ function Component2(props) {
68 } else {
69 t0 = $[1];
70 }
71 - t35 = t0;
72 - const expensiveNumber = t35;
71 + t15 = t0;
72 + const expensiveNumber = t15;
73 let t1;
74 if ($[2] !== expensiveNumber) {
75 t1 = <div>{expensiveNumber}</div>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/babel-existing-react-namespace-import.expect.md
+3 -3
@@ -29,9 +29,9 @@ import { calculateExpensiveNumber } from "shared-runtime";
29 function Component(props) {
30 const $ = useMemoCache(2);
31 const [x] = React.useState(0);
32 - let t39;
33 - t39 = calculateExpensiveNumber(x);
34 - const expensiveNumber = t39;
32 + let t17;
33 + t17 = calculateExpensiveNumber(x);
34 + const expensiveNumber = t17;
35 let t0;
36 if ($[0] !== expensiveNumber) {
37 t0 = <div>{expensiveNumber}</div>;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug.useMemo-deps-array-not-cleared.expect.md
+5 -5
@@ -24,12 +24,12 @@ export const FIXTURE_ENTRYPOINT = {
24
25 ```javascript
26 import { unstable_useMemoCache as useMemoCache } from "react";
27 -function App(t23) {
27 +function App(t25) {
28 const $ = useMemoCache(2);
29 - const { text, hasDeps } = t23;
29 + const { text, hasDeps } = t25;
30
31 hasDeps ? null : [text];
32 - let t44;
32 + let t18;
33 let t0;
34 if ($[0] !== text) {
35 t0 = text.toUpperCase();
@@ -38,8 +38,8 @@ function App(t23) {
38 } else {
39 t0 = $[1];
40 }
41 - t44 = t0;
42 - const resolvedText = t44;
41 + t18 = t0;
42 + const resolvedText = t18;
43 return resolvedText;
44 }
45
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/drop-methodcall-usememo.expect.md
+3 -3
@@ -28,7 +28,7 @@ import * as React from "react";
28
29 function Component(props) {
30 const $ = useMemoCache(2);
31 - let t42;
31 + let t19;
32 let x;
33 if ($[0] !== props.value) {
34 x = [];
@@ -38,8 +38,8 @@ function Component(props) {
38 } else {
39 x = $[1];
40 }
41 - t42 = x;
42 - const x_0 = t42;
41 + t19 = x;
42 + const x_0 = t19;
43 return x_0;
44 }
45
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/iife-return-modified-later-phi.expect.md renamed
+14 -11
@@ -26,21 +26,24 @@ export const FIXTURE_ENTRYPOINT = {
26 ```javascript
27 import { unstable_useMemoCache as useMemoCache } from "react";
28 function Component(props) {
29 - const $ = useMemoCache(1);
30 - let t27;
31 - if (props.cond) {
32 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
33 - t27 = [];
34 - $[0] = t27;
29 + const $ = useMemoCache(3);
30 + let items;
31 + if ($[0] !== props.cond || $[1] !== props.a) {
32 + let t9;
33 + if (props.cond) {
34 + t9 = [];
35 } else {
36 - t27 = $[0];
36 + t9 = null;
37 }
38 + items = t9;
39 +
40 + items.push(props.a);
41 + $[0] = props.cond;
42 + $[1] = props.a;
43 + $[2] = items;
44 } else {
39 - t27 = null;
45 + items = $[2];
46 }
41 - const items = t27;
42 -
43 - items.push(props.a);
47 return items;
48 }
49
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/iife-return-modified-later-phi.js renamed
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/iife-return-modified-later.expect.md renamed
+13 -9
@@ -22,17 +22,21 @@ export const FIXTURE_ENTRYPOINT = {
22 ```javascript
23 import { unstable_useMemoCache as useMemoCache } from "react";
24 function Component(props) {
25 - const $ = useMemoCache(1);
26 - let t17;
27 - if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
28 - t17 = [];
29 - $[0] = t17;
25 + const $ = useMemoCache(3);
26 + let t4;
27 + let items;
28 + if ($[0] !== props.a) {
29 + t4 = [];
30 + items = t4;
31 +
32 + items.push(props.a);
33 + $[0] = props.a;
34 + $[1] = items;
35 + $[2] = t4;
36 } else {
31 - t17 = $[0];
37 + items = $[1];
38 + t4 = $[2];
39 }
33 - const items = t17;
34 -
35 - items.push(props.a);
40 return items;
41 }
42
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/iife-return-modified-later.js renamed
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/nested-function-with-param-as-captured-dep.expect.md
+5 -5
@@ -25,19 +25,19 @@ export const FIXTURE_ENTRYPOINT = {
25 import { unstable_useMemoCache as useMemoCache } from "react";
26 function Foo() {
27 const $ = useMemoCache(1);
28 - let t38;
28 + let t18;
29 let t0;
30 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
31 - t0 = function a(t25) {
32 - const x_0 = t25 === undefined ? () => {} : t25;
31 + t0 = function a(t28) {
32 + const x_0 = t28 === undefined ? () => {} : t28;
33 return x_0;
34 };
35 $[0] = t0;
36 } else {
37 t0 = $[0];
38 }
39 - t38 = t0;
40 - return t38;
39 + t18 = t0;
40 + return t18;
41 }
42
43 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/remove-memoization-kitchen-sink.expect.md
+3 -3
@@ -28,11 +28,11 @@ function Component(props) {
28 };
29
30 const object = { x, onChange };
31 - let t86;
31 + let t43;
32
33 const { x: x_0, onChange: onChange_0 } = object;
34 - t86 = <input value={x_0} onChange={onChange_0} />;
35 - return t86;
34 + t43 = <input value={x_0} onChange={onChange_0} />;
35 + return t43;
36 }
37
38 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-duplicate-instruction-from-merge-consecutive-scopes.expect.md
+1 -4
@@ -27,12 +27,9 @@ export const FIXTURE_ENTRYPOINT = {
27 import { unstable_useMemoCache as useMemoCache } from "react"; // @enableMergeConsecutiveScopes
28 function Component(id) {
29 const $ = useMemoCache(3);
30 - let t22;
31 - t22 = undefined;
32 - const bar = t22;
30 let t0;
31 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
35 - t0 = <Bar title={bar} />;
32 + t0 = <Bar title={undefined} />;
33 $[0] = t0;
34 } else {
35 t0 = $[0];
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-if-else-multiple-return.expect.md
+6 -6
@@ -20,8 +20,8 @@ function Component(props) {
20 import { unstable_useMemoCache as useMemoCache } from "react";
21 function Component(props) {
22 const $ = useMemoCache(4);
23 - let t44;
24 - bb8: {
23 + let t20;
24 + bb7: {
25 if (props.cond) {
26 let t0;
27 if ($[0] !== props.a) {
@@ -31,8 +31,8 @@ function Component(props) {
31 } else {
32 t0 = $[1];
33 }
34 - t44 = t0;
35 - break bb8;
34 + t20 = t0;
35 + break bb7;
36 }
37 let t1;
38 if ($[2] !== props.b) {
@@ -42,9 +42,9 @@ function Component(props) {
42 } else {
43 t1 = $[3];
44 }
45 - t44 = t1;
45 + t20 = t1;
46 }
47 - const x = t44;
47 + const x = t20;
48 return x;
49 }
50
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-independently-memoizeable.expect.md
+3 -3
@@ -20,7 +20,7 @@ function Component(props) {
20 import { unstable_useMemoCache as useMemoCache } from "react";
21 function Component(props) {
22 const $ = useMemoCache(10);
23 - let t59;
23 + let t26;
24 let t0;
25 if ($[0] !== props.a) {
26 t0 = makeObject(props.a);
@@ -48,8 +48,8 @@ function Component(props) {
48 } else {
49 t2 = $[6];
50 }
51 - t59 = t2;
52 - const [a_0, b_0] = t59;
51 + t26 = t2;
52 + const [a_0, b_0] = t26;
53 let t3;
54 if ($[7] !== a_0 || $[8] !== b_0) {
55 t3 = [a_0, b_0];
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-inlining-block-return.expect.md
+6 -6
@@ -25,8 +25,8 @@ export const FIXTURE_ENTRYPOINT = {
25 import { unstable_useMemoCache as useMemoCache } from "react";
26 function component(a, b) {
27 const $ = useMemoCache(2);
28 - let t31;
29 - bb7: {
28 + let t13;
29 + bb6: {
30 if (a) {
31 let t0;
32 if ($[0] !== b) {
@@ -36,12 +36,12 @@ function component(a, b) {
36 } else {
37 t0 = $[1];
38 }
39 - t31 = t0;
40 - break bb7;
39 + t13 = t0;
40 + break bb6;
41 }
42 - t31 = undefined;
42 + t13 = undefined;
43 }
44 - const x = t31;
44 + const x = t13;
45 return x;
46 }
47
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-inverted-if.expect.md
+6 -6
@@ -27,20 +27,20 @@ export const FIXTURE_ENTRYPOINT = {
27
28 ```javascript
29 function Component(props) {
30 - let t36;
31 - bb11: {
30 + let t16;
31 + bb10: {
32 bb5: {
33 if (props.cond) {
34 break bb5;
35 }
36
37 - t36 = props.a;
38 - break bb11;
37 + t16 = props.a;
38 + break bb10;
39 }
40
41 - t36 = props.b;
41 + t16 = props.b;
42 }
43 - const x = t36;
43 + const x = t16;
44 return x;
45 }
46
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-labeled-statement-unconditional-return.expect.md
+3 -3
@@ -23,10 +23,10 @@ export const FIXTURE_ENTRYPOINT = {
23
24 ```javascript
25 function Component(props) {
26 - let t20;
26 + let t8;
27
28 - t20 = props.value;
29 - const x = t20;
28 + t8 = props.value;
29 + const x = t8;
30 return x;
31 }
32
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-logical.expect.md
+3 -3
@@ -19,9 +19,9 @@ export const FIXTURE_ENTRYPOINT = {
19
20 ```javascript
21 function Component(props) {
22 - let t38;
23 - t38 = props.a && props.b;
24 - const x = t38;
22 + let t16;
23 + t16 = props.a && props.b;
24 + const x = t16;
25 return x;
26 }
27
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-multiple-if-else.expect.md
+8 -8
@@ -33,8 +33,8 @@ import { useMemo, unstable_useMemoCache as useMemoCache } from "react";
33
34 function Component(props) {
35 const $ = useMemoCache(3);
36 - let t68;
37 - bb10: {
36 + let t31;
37 + bb9: {
38 let y;
39 if ($[0] !== props) {
40 y = [];
@@ -42,21 +42,21 @@ function Component(props) {
42 y.push(props.a);
43 }
44 if (props.cond2) {
45 - t68 = y;
46 - break bb10;
45 + t31 = y;
46 + break bb9;
47 }
48
49 y.push(props.b);
50 $[0] = props;
51 $[1] = y;
52 - $[2] = t68;
52 + $[2] = t31;
53 } else {
54 y = $[1];
55 - t68 = $[2];
55 + t31 = $[2];
56 }
57 - t68 = y;
57 + t31 = y;
58 }
59 - const x = t68;
59 + const x = t31;
60 return x;
61 }
62
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-nested-ifs.expect.md
-4
@@ -24,14 +24,10 @@ export const FIXTURE_ENTRYPOINT = {
24
25 ```javascript
26 function Component(props) {
27 - let t31;
27 if (props.cond) {
28 if (props.cond) {
29 }
30 }
32 - t31 = undefined;
33 - const x = t31;
34 - return x;
31 }
32
33 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-return-empty.expect.md
-5
@@ -15,12 +15,7 @@ function component(a) {
15
16 ```javascript
17 function component(a) {
18 - let t23;
19 -
18 mutate(a);
21 - t23 = undefined;
22 - const x = t23;
23 - return x;
19 }
20
21 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-simple.expect.md
+3 -3
@@ -15,7 +15,7 @@ function component(a) {
15 import { unstable_useMemoCache as useMemoCache } from "react";
16 function component(a) {
17 const $ = useMemoCache(4);
18 - let t24;
18 + let t9;
19 let t0;
20 if ($[0] !== a) {
21 t0 = [a];
@@ -24,8 +24,8 @@ function component(a) {
24 } else {
25 t0 = $[1];
26 }
27 - t24 = t0;
28 - const x = t24;
27 + t9 = t0;
28 + const x = t9;
29 let t1;
30 if ($[2] !== x) {
31 t1 = <Foo x={x} />;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-switch-no-fallthrough.expect.md
+6 -6
@@ -28,17 +28,17 @@ export const FIXTURE_ENTRYPOINT = {
28
29 ```javascript
30 function Component(props) {
31 - let t38;
32 - bb9: switch (props.key) {
31 + let t17;
32 + bb8: switch (props.key) {
33 case "key": {
34 - t38 = props.value;
35 - break bb9;
34 + t17 = props.value;
35 + break bb8;
36 }
37 default: {
38 - t38 = props.defaultValue;
38 + t17 = props.defaultValue;
39 }
40 }
41 - const x = t38;
41 + const x = t17;
42 return x;
43 }
44
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useMemo-switch-return.expect.md
+6 -6
@@ -34,13 +34,13 @@ export const FIXTURE_ENTRYPOINT = {
34
35 ```javascript
36 function Component(props) {
37 - let t49;
38 - bb11: {
37 + let t21;
38 + bb10: {
39 let y;
40 bb2: switch (props.switch) {
41 case "foo": {
42 - t49 = "foo";
43 - break bb11;
42 + t21 = "foo";
43 + break bb10;
44 }
45 case "bar": {
46 y = "bar";
@@ -51,9 +51,9 @@ function Component(props) {
51 }
52 }
53
54 - t49 = y;
54 + t21 = y;
55 }
56 - const x = t49;
56 + const x = t21;
57 return x;
58 }
59