@samitouri / QOS-React-2 / commits / 42459f579f

[hir] Return undefined explicitly if there's no return value

Future passes like inlineUseMemo assume there's a return value so let's create one instead of implicitly returning undefined.

Sathya Gunasekaran committed Apr 17, 2023 at 21:11 UTC 42459f579f37c6adcdd84ab6277722856817b4b8
68 files changed +236 -111
compiler/forget/src/HIR/BuildHIR.ts
+18 -8
@@ -157,7 +157,11 @@ export function lower(
157 {
158 kind: "return",
159 loc: GeneratedSource,
160 - value: null,
160 + value: lowerValueToTemporary(builder, {
161 + kind: "Primitive",
162 + value: undefined,
163 + loc: GeneratedSource,
164 + }),
165 id: makeInstructionId(0),
166 },
167 null
@@ -200,13 +204,19 @@ function lowerStatement(
204 case "ReturnStatement": {
205 const stmt = stmtPath as NodePath<t.ReturnStatement>;
206 const argument = stmt.get("argument");
203 - const value =
204 - argument.node != null
205 - ? lowerExpressionToTemporary(
206 - builder,
207 - argument as NodePath<t.Expression>
208 - )
209 - : null;
207 + let value;
208 + if (argument.node === null) {
209 + value = lowerValueToTemporary(builder, {
210 + kind: "Primitive",
211 + value: undefined,
212 + loc: GeneratedSource,
213 + });
214 + } else {
215 + value = lowerExpressionToTemporary(
216 + builder,
217 + argument as NodePath<t.Expression>
218 + );
219 + }
220 const terminal: ReturnTerminal = {
221 kind: "return",
222 loc: stmt.node.loc ?? GeneratedSource,
compiler/forget/src/__tests__/fixtures/compiler/_bug.computed-call-evaluation-order.expect.md
+1
@@ -26,6 +26,7 @@ function Component() {
26 // Should print A, B, arg, original
27 function changeF(o) {
28 o.f = () => console.log("new");
29 + return undefined;
30 }
31
32 function Component() {
compiler/forget/src/__tests__/fixtures/compiler/_bug.property-call-evaluation-order.expect.md
+1
@@ -26,6 +26,7 @@ function Component() {
26
27 function changeF(o) {
28 o.f = () => console.log("new");
29 + return undefined;
30 }
31
32 function Component() {
compiler/forget/src/__tests__/fixtures/compiler/alias-while.expect.md
+3 -1
@@ -49,7 +49,9 @@ function foo(cond) {
49 return a;
50 }
51
52 -function mutate(x, y) {}
52 +function mutate(x, y) {
53 + return undefined;
54 +}
55
56 ```
57
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/array-pattern-params.expect.md
+2 -2
@@ -13,9 +13,9 @@ function component([a, b]) {
13 ## Code
14
15 ```javascript
16 -function component(t16) {
16 +function component(t17) {
17 const $ = React.unstable_useMemoCache(7);
18 - const [a, b] = t16;
18 + const [a, b] = t17;
19 const c_0 = $[0] !== a;
20 let t0;
21 if (c_0) {
compiler/forget/src/__tests__/fixtures/compiler/call.expect.md
+3 -1
@@ -18,7 +18,9 @@ function Component(props) {
18 ## Code
19
20 ```javascript
21 -function foo() {}
21 +function foo() {
22 + return undefined;
23 +}
24
25 function Component(props) {
26 const $ = React.unstable_useMemoCache(3);
compiler/forget/src/__tests__/fixtures/compiler/capturing-function-member-expr-call.expect.md
+2 -2
@@ -19,9 +19,9 @@ function component({ mutator }) {
19 ## Code
20
21 ```javascript
22 -function component(t24) {
22 +function component(t27) {
23 const $ = React.unstable_useMemoCache(7);
24 - const { mutator } = t24;
24 + const { mutator } = t27;
25 const c_0 = $[0] !== mutator;
26 let t0;
27 if (c_0) {
compiler/forget/src/__tests__/fixtures/compiler/conditional-on-mutable.expect.md
+6 -2
@@ -104,8 +104,12 @@ function ComponentB(props) {
104 return t0;
105 }
106
107 -function Foo() {}
108 -function mayMutate() {}
107 +function Foo() {
108 + return undefined;
109 +}
110 +function mayMutate() {
111 + return undefined;
112 +}
113
114 ```
115
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/constructor.expect.md
+3 -1
@@ -18,7 +18,9 @@ function Component(props) {
18 ## Code
19
20 ```javascript
21 -function Foo() {}
21 +function Foo() {
22 + return undefined;
23 +}
24
25 function Component(props) {
26 const $ = React.unstable_useMemoCache(3);
compiler/forget/src/__tests__/fixtures/compiler/destructuring-array-param-default.expect.md
+3 -3
@@ -11,9 +11,9 @@ function Component([a = 2]) {
11 ## Code
12
13 ```javascript
14 -function Component(t13) {
15 - const [t14] = t13;
16 - const a = t14 === undefined ? 2 : t14;
14 +function Component(t14) {
15 + const [t15] = t14;
16 + const a = t15 === undefined ? 2 : t15;
17 return a;
18 }
19
compiler/forget/src/__tests__/fixtures/compiler/destructuring-assignment.expect.md
+8 -8
@@ -29,14 +29,14 @@ function foo(a, b, c) {
29 function foo(a, b, c) {
30 const $ = React.unstable_useMemoCache(5);
31
32 - const [d, t46] = a;
33 - const [t48] = t46;
34 - const { e: t50 } = t48;
35 - const { f: g } = t50;
36 - const { l: t55, o } = b;
37 - const { m: t58 } = t55;
38 - const [t60] = t58;
39 - const [n] = t60;
32 + const [d, t47] = a;
33 + const [t49] = t47;
34 + const { e: t51 } = t49;
35 + const { f: g } = t51;
36 + const { l: t56, o } = b;
37 + const { m: t59 } = t56;
38 + const [t61] = t59;
39 + const [n] = t61;
40 const c_0 = $[0] !== d;
41 const c_1 = $[1] !== g;
42 const c_2 = $[2] !== n;
compiler/forget/src/__tests__/fixtures/compiler/destructuring-object-param-default.expect.md
+3 -3
@@ -11,9 +11,9 @@ function Component({ a = 2 }) {
11 ## Code
12
13 ```javascript
14 -function Component(t13) {
15 - const { a: t14 } = t13;
16 - const a = t14 === undefined ? 2 : t14;
14 +function Component(t14) {
15 + const { a: t15 } = t14;
16 + const a = t15 === undefined ? 2 : t15;
17 return a;
18 }
19
compiler/forget/src/__tests__/fixtures/compiler/destructuring.expect.md
+2 -2
@@ -58,8 +58,8 @@ function foo(a, b, c) {
58 g = $[6];
59 }
60 const { f } = t2;
61 - const { l: t51, p } = b;
62 - const { m: t3 } = t51;
61 + const { l: t52, p } = b;
62 + const { m: t3 } = t52;
63 const c_7 = $[7] !== t3;
64 let t4;
65 let o;
compiler/forget/src/__tests__/fixtures/compiler/early-return.expect.md
+2 -2
@@ -18,9 +18,9 @@ function MyApp(props) {
18 ```javascript
19 function MyApp(props) {
20 if (props.cond) {
21 - return;
21 + return undefined;
22 } else {
23 - return;
23 + return undefined;
24 }
25 }
26
compiler/forget/src/__tests__/fixtures/compiler/error.mutate-after-aliased-freeze.expect.md
+1 -1
@@ -25,7 +25,7 @@ function Component(props) {
25 ## Error
26
27 ```
28 -[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $42:TObject<BuiltInArray> (frozen) (13:13)
28 +[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $43:TObject<BuiltInArray> (frozen) (13:13)
29 ```
30
31
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/error.mutate-after-freeze.expect.md
+1 -1
@@ -19,7 +19,7 @@ function Component(props) {
19 ## Error
20
21 ```
22 -[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $25:TObject<BuiltInArray> (frozen) (7:7)
22 +[ReactForget] InvalidInput: InferReferenceEffects: inferred mutation of known immutable value. Found mutation of $26:TObject<BuiltInArray> (frozen) (7:7)
23 ```
24
25
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/for-return.expect.md
+2 -1
@@ -15,8 +15,9 @@ function Component(props) {
15 ```javascript
16 function Component(props) {
17 for (const i = 0; 0 < props.count; ) {
18 - return;
18 + return undefined;
19 }
20 + return undefined;
21 }
22
23 ```
compiler/forget/src/__tests__/fixtures/compiler/frozen-after-alias.expect.md
+6 -2
@@ -34,8 +34,12 @@ function Component() {
34 return b;
35 }
36
37 -function useFreeze() {}
38 -function foo(x) {}
37 +function useFreeze() {
38 + return undefined;
39 +}
40 +function foo(x) {
41 + return undefined;
42 +}
43
44 ```
45
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/function-param-assignment-pattern.expect.md
+2 -2
@@ -11,9 +11,9 @@ function Component(x = "default", y = [{}]) {
11 ## Code
12
13 ```javascript
14 -function Component(t23, t0) {
14 +function Component(t24, t0) {
15 const $ = React.unstable_useMemoCache(5);
16 - const x = t23 === undefined ? "default" : t23;
16 + const x = t24 === undefined ? "default" : t24;
17 const c_0 = $[0] !== t0;
18 let t1;
19 if (c_0) {
compiler/forget/src/__tests__/fixtures/compiler/hook-call.expect.md
+6 -2
@@ -22,8 +22,12 @@ function Component(props) {
22 ## Code
23
24 ```javascript
25 -function useFreeze() {}
26 -function foo() {}
25 +function useFreeze() {
26 + return undefined;
27 +}
28 +function foo() {
29 + return undefined;
30 +}
31
32 function Component(props) {
33 const $ = React.unstable_useMemoCache(3);
compiler/forget/src/__tests__/fixtures/compiler/hooks-freeze-arguments.expect.md
+6 -2
@@ -34,8 +34,12 @@ function Component() {
34 return a;
35 }
36
37 -function useFreeze(x) {}
38 -function call(x) {}
37 +function useFreeze(x) {
38 + return undefined;
39 +}
40 +function call(x) {
41 + return undefined;
42 +}
43
44 ```
45
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/hooks-freeze-possibly-mutable-arguments.expect.md
+6 -2
@@ -49,8 +49,12 @@ function Component(props) {
49 return a;
50 }
51
52 -function useFreeze(x) {}
53 -function call(x) {}
52 +function useFreeze(x) {
53 + return undefined;
54 +}
55 +function call(x) {
56 + return undefined;
57 +}
58
59 ```
60
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/independent-across-if.expect.md
+12 -4
@@ -36,10 +36,18 @@ function Component(props) {
36 ## Code
37
38 ```javascript
39 -function compute() {}
40 -function mutate() {}
41 -function foo() {}
42 -function Foo() {}
39 +function compute() {
40 + return undefined;
41 +}
42 +function mutate() {
43 + return undefined;
44 +}
45 +function foo() {
46 + return undefined;
47 +}
48 +function Foo() {
49 + return undefined;
50 +}
51
52 /**
53 * Should produce 3 scopes:
compiler/forget/src/__tests__/fixtures/compiler/independent.expect.md
+9 -3
@@ -73,9 +73,15 @@ function Component(props) {
73 return t2;
74 }
75
76 -function compute() {}
77 -function foo() {}
78 -function Foo() {}
76 +function compute() {
77 + return undefined;
78 +}
79 +function foo() {
80 + return undefined;
81 +}
82 +function Foo() {
83 + return undefined;
84 +}
85
86 ```
87
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/interdependent-across-if.expect.md
+9 -3
@@ -30,9 +30,15 @@ function Component(props) {
30 ## Code
31
32 ```javascript
33 -function compute() {}
34 -function foo() {}
35 -function Foo() {}
33 +function compute() {
34 + return undefined;
35 +}
36 +function foo() {
37 + return undefined;
38 +}
39 +function Foo() {
40 + return undefined;
41 +}
42
43 /**
44 * Should produce 1 scope:
compiler/forget/src/__tests__/fixtures/compiler/interdependent.expect.md
+9 -3
@@ -68,9 +68,15 @@ function Component(props) {
68 return t0;
69 }
70
71 -function compute() {}
72 -function foo() {}
73 -function Foo() {}
71 +function compute() {
72 + return undefined;
73 +}
74 +function foo() {
75 + return undefined;
76 +}
77 +function Foo() {
78 + return undefined;
79 +}
80
81 ```
82
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/issue852.expect.md
+1
@@ -17,6 +17,7 @@ function Component(c) {
17 function Component(c) {
18 const x = { c };
19 mutate(x);
20 + return undefined;
21 }
22
23 ```
compiler/forget/src/__tests__/fixtures/compiler/mutable-lifetime-loops.expect.md
+7 -2
@@ -42,8 +42,12 @@ function Component(props) {
42 ## Code
43
44 ```javascript
45 -function mutate(x, y) {}
46 -function cond(x) {}
45 +function mutate(x, y) {
46 + return undefined;
47 +}
48 +function cond(x) {
49 + return undefined;
50 +}
51
52 function Component(props) {
53 let a = {};
@@ -71,6 +75,7 @@ function Component(props) {
75 }
76
77 mutate(d, null);
78 + return undefined;
79 }
80
81 ```
compiler/forget/src/__tests__/fixtures/compiler/mutable-lifetime-with-aliasing.expect.md
+4 -1
@@ -38,7 +38,9 @@ function Component(props) {
38 ## Code
39
40 ```javascript
41 -function mutate(x, y) {}
41 +function mutate(x, y) {
42 + return undefined;
43 +}
44
45 function Component(props) {
46 const a = {};
@@ -61,6 +63,7 @@ function Component(props) {
63 }
64
65 mutate(x, null);
66 + return undefined;
67 }
68
69 ```
compiler/forget/src/__tests__/fixtures/compiler/mutable-liverange-loop.expect.md
+7 -2
@@ -37,8 +37,12 @@ function Component(props) {
37 ## Code
38
39 ```javascript
40 -function mutate() {}
41 -function cond() {}
40 +function mutate() {
41 + return undefined;
42 +}
43 +function cond() {
44 + return undefined;
45 +}
46
47 function Component(props) {
48 const a = {};
@@ -61,6 +65,7 @@ function Component(props) {
65 }
66
67 mutate(d, null);
68 + return undefined;
69 }
70
71 ```
compiler/forget/src/__tests__/fixtures/compiler/object-computed-access-assignment.expect.md
+1
@@ -15,6 +15,7 @@ function foo(a, b, c) {
15 function foo(a, b, c) {
16 a[b] = c[b];
17 a[3] = c[b * 4];
18 + return undefined;
19 }
20
21 ```
compiler/forget/src/__tests__/fixtures/compiler/object-pattern-params.expect.md
+2 -2
@@ -13,9 +13,9 @@ function component({ a, b }) {
13 ## Code
14
15 ```javascript
16 -function component(t16) {
16 +function component(t17) {
17 const $ = React.unstable_useMemoCache(7);
18 - const { a, b } = t16;
18 + const { a, b } = t17;
19 const c_0 = $[0] !== a;
20 let t0;
21 if (c_0) {
compiler/forget/src/__tests__/fixtures/compiler/object-properties.expect.md
+1
@@ -19,6 +19,7 @@ function foo(a, b, c) {
19 const y = b.c.d;
20 y.z = c.d.e;
21 foo(a.b.c);
22 + return undefined;
23 }
24
25 ```
compiler/forget/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved-by-terminal.expect.md
+1
@@ -26,6 +26,7 @@ function foo(a, b, c) {
26
27 y.push(a);
28 x.push(b);
29 + return undefined;
30 }
31
32 ```
compiler/forget/src/__tests__/fixtures/compiler/overlapping-scopes-interleaved.expect.md
+1
@@ -19,6 +19,7 @@ function foo(a, b) {
19 const y = [];
20 x.push(a);
21 y.push(b);
22 + return undefined;
23 }
24
25 ```
compiler/forget/src/__tests__/fixtures/compiler/overlapping-scopes-shadowed.expect.md
+1
@@ -19,6 +19,7 @@ function foo(a, b) {
19 const y = [];
20 y.push(b);
21 x.push(a);
22 + return undefined;
23 }
24
25 ```
compiler/forget/src/__tests__/fixtures/compiler/overlapping-scopes-while.expect.md
+1
@@ -23,6 +23,7 @@ function foo(a, b, c) {
23 y.push(b);
24 x.push(a);
25 }
26 + return undefined;
27 }
28
29 ```
compiler/forget/src/__tests__/fixtures/compiler/reverse-postorder.expect.md
+1
@@ -54,6 +54,7 @@ function Component(props) {
54 } else {
55 }
56 }
57 + return undefined;
58 }
59
60 ```
compiler/forget/src/__tests__/fixtures/compiler/sequence-expression.expect.md
+3 -1
@@ -41,7 +41,9 @@ function sequence(props) {
41 return x;
42 }
43
44 -function foo() {}
44 +function foo() {
45 + return undefined;
46 +}
47
48 ```
49
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/simple-alias.expect.md
+3 -1
@@ -19,7 +19,9 @@ function foo() {
19 ## Code
20
21 ```javascript
22 -function mutate() {}
22 +function mutate() {
23 + return undefined;
24 +}
25 function foo() {
26 const $ = React.unstable_useMemoCache(1);
27 let c;
compiler/forget/src/__tests__/fixtures/compiler/ssa-call-jsx-2.expect.md
+3 -1
@@ -22,7 +22,9 @@ function Component(props) {
22
23 ```javascript
24 // @Pass runMutableRangeAnalysis
25 -function foo() {}
25 +function foo() {
26 + return undefined;
27 +}
28
29 function Component(props) {
30 const $ = React.unstable_useMemoCache(3);
compiler/forget/src/__tests__/fixtures/compiler/ssa-call-jsx.expect.md
+3 -1
@@ -18,7 +18,9 @@ function Component(props) {
18 ## Code
19
20 ```javascript
21 -function foo() {}
21 +function foo() {
22 + return undefined;
23 +}
24
25 function Component(props) {
26 const $ = React.unstable_useMemoCache(3);
compiler/forget/src/__tests__/fixtures/compiler/ssa-complex-multiple-if.expect.md
+3 -1
@@ -20,7 +20,9 @@ function foo() {
20 ## Code
21
22 ```javascript
23 -function foo() {}
23 +function foo() {
24 + return undefined;
25 +}
26
27 ```
28
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/ssa-complex-single-if.expect.md
+3 -1
@@ -17,7 +17,9 @@ function foo() {
17 ## Code
18
19 ```javascript
20 -function foo() {}
20 +function foo() {
21 + return undefined;
22 +}
23
24 ```
25
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/ssa-if-else.expect.md
+3 -1
@@ -18,7 +18,9 @@ function foo() {
18 ## Code
19
20 ```javascript
21 -function foo() {}
21 +function foo() {
22 + return undefined;
23 +}
24
25 ```
26
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/ssa-nested-partial-phi.expect.md
+1
@@ -26,6 +26,7 @@ function foo(a, b, c) {
26 }
27 return x;
28 }
29 + return undefined;
30 }
31
32 ```
compiler/forget/src/__tests__/fixtures/compiler/ssa-newexpression.expect.md
+3 -1
@@ -16,7 +16,9 @@ function Component(props) {
16 ## Code
17
18 ```javascript
19 -function Foo() {}
19 +function Foo() {
20 + return undefined;
21 +}
22
23 function Component(props) {
24 const $ = React.unstable_useMemoCache(1);
compiler/forget/src/__tests__/fixtures/compiler/ssa-shadowing.expect.md
+4 -1
@@ -20,7 +20,9 @@ function Foo(cond) {
20 ## Code
21
22 ```javascript
23 -function log() {}
23 +function log() {
24 + return undefined;
25 +}
26
27 function Foo(cond) {
28 let str = "";
@@ -31,6 +33,7 @@ function Foo(cond) {
33 }
34
35 log(str);
36 + return undefined;
37 }
38
39 ```
compiler/forget/src/__tests__/fixtures/compiler/ssa-sibling-phis.expect.md
+3 -1
@@ -27,7 +27,9 @@ function foo(a, b, c, d) {
27 ## Code
28
29 ```javascript
30 -function foo(a, b, c, d) {}
30 +function foo(a, b, c, d) {
31 + return undefined;
32 +}
33
34 ```
35
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/ssa-simple-phi.expect.md
+3 -1
@@ -19,7 +19,9 @@ function foo() {
19 ## Code
20
21 ```javascript
22 -function foo() {}
22 +function foo() {
23 + return undefined;
24 +}
25
26 ```
27
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/ssa-simple.expect.md
+3 -1
@@ -12,7 +12,9 @@ function foo() {
12 ## Code
13
14 ```javascript
15 -function foo() {}
15 +function foo() {
16 + return undefined;
17 +}
18
19 ```
20
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/ssa-single-if.expect.md
+3 -1
@@ -16,7 +16,9 @@ function foo() {
16 ## Code
17
18 ```javascript
19 -function foo() {}
19 +function foo() {
20 + return undefined;
21 +}
22
23 ```
24
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/ssa-switch.expect.md
+1
@@ -38,6 +38,7 @@ function foo() {
38 default: {
39 }
40 }
41 + return undefined;
42 }
43
44 ```
compiler/forget/src/__tests__/fixtures/compiler/switch-with-fallthrough.expect.md
+1
@@ -55,6 +55,7 @@ function foo(x) {
55 default: {
56 }
57 }
58 + return undefined;
59 }
60
61 ```
compiler/forget/src/__tests__/fixtures/compiler/transitive-alias-fields.expect.md
+1
@@ -31,6 +31,7 @@ function component() {
31 q.y = p.y;
32
33 mutate(q);
34 + return undefined;
35 }
36
37 ```
compiler/forget/src/__tests__/fixtures/compiler/type-args-test-binary-operator.expect.md
+1
@@ -16,6 +16,7 @@ function component(a, b) {
16 function component(a, b) {
17 if (a > b) {
18 }
19 + return undefined;
20 }
21
22 ```
compiler/forget/src/__tests__/fixtures/compiler/type-binary-operator.expect.md
+1
@@ -20,6 +20,7 @@ function component() {
20 const b = someOther();
21 if (a > b) {
22 }
23 + return undefined;
24 }
25
26 ```
compiler/forget/src/__tests__/fixtures/compiler/useMemo-if-else-multiple-return.expect.md
+4 -4
@@ -21,7 +21,7 @@ function Component(props) {
21 // @inlineUseMemo
22 function Component(props) {
23 const $ = React.unstable_useMemoCache(4);
24 - let t16 = undefined;
24 + let t17 = undefined;
25 if (props.cond) {
26 const c_0 = $[0] !== props.a;
27 let t0;
@@ -32,7 +32,7 @@ function Component(props) {
32 } else {
33 t0 = $[1];
34 }
35 - t16 = t0;
35 + t17 = t0;
36 } else {
37 const c_2 = $[2] !== props.b;
38 let t1;
@@ -43,9 +43,9 @@ function Component(props) {
43 } else {
44 t1 = $[3];
45 }
46 - t16 = t1;
46 + t17 = t1;
47 }
48 - const x = t16;
48 + const x = t17;
49 return x;
50 }
51
compiler/forget/src/__tests__/fixtures/compiler/useMemo-independently-memoizeable.expect.md
+2 -2
@@ -52,8 +52,8 @@ function Component(props) {
52 } else {
53 t2 = $[6];
54 }
55 - const t24 = t2;
56 - const [a_0, b_0] = t24;
55 + const t25 = t2;
56 + const [a_0, b_0] = t25;
57 const c_7 = $[7] !== a_0;
58 const c_8 = $[8] !== b_0;
59 let t3;
compiler/forget/src/__tests__/fixtures/compiler/useMemo-inlining-block-return.expect.md
+5 -3
@@ -20,7 +20,7 @@ function component(a, b) {
20 // @inlineUseMemo
21 function component(a, b) {
22 const $ = React.unstable_useMemoCache(2);
23 - let t13;
23 + let t14 = undefined;
24 if (a) {
25 const c_0 = $[0] !== b;
26 let t0;
@@ -31,9 +31,11 @@ function component(a, b) {
31 } else {
32 t0 = $[1];
33 }
34 - t13 = t0;
34 + t14 = t0;
35 + } else {
36 + t14 = undefined;
37 }
36 - const x = t13;
38 + const x = t14;
39 return x;
40 }
41
compiler/forget/src/__tests__/fixtures/compiler/useMemo-labeled-statement-unconditional-return.expect.md
+2 -2
@@ -19,8 +19,8 @@ function Component(props) {
19 ```javascript
20 // @inlineUseMemo
21 function Component(props) {
22 - const t8 = props.value;
23 - const x = t8;
22 + const t9 = props.value;
23 + const x = t9;
24 return x;
25 }
26
compiler/forget/src/__tests__/fixtures/compiler/useMemo-logical.expect.md
+2 -2
@@ -15,8 +15,8 @@ function Component(props) {
15 ```javascript
16 // @inlineUseMemo
17 function Component(props) {
18 - const t14 = props.a && props.b;
19 - const x = t14;
18 + const t15 = props.a && props.b;
19 + const x = t15;
20 return x;
21 }
22
compiler/forget/src/__tests__/fixtures/compiler/useMemo-multiple-if-else.expect.md
+7 -7
@@ -27,25 +27,25 @@ function Component(props) {
27 function Component(props) {
28 const $ = React.unstable_useMemoCache(2);
29 const c_0 = $[0] !== props;
30 - let t25;
30 + let t26;
31 if (c_0) {
32 const y = [];
33 if (props.cond) {
34 y.push(props.a);
35 }
36 - t25 = undefined;
36 + t26 = undefined;
37 if (props.cond2) {
38 - t25 = y;
38 + t26 = y;
39 } else {
40 y.push(props.b);
41 - t25 = y;
41 + t26 = y;
42 }
43 $[0] = props;
44 - $[1] = t25;
44 + $[1] = t26;
45 } else {
46 - t25 = $[1];
46 + t26 = $[1];
47 }
48 - const x = t25;
48 + const x = t26;
49 return x;
50 }
51
compiler/forget/src/__tests__/fixtures/compiler/useMemo-return-empty.expect.md renamed
+7 -4
@@ -12,11 +12,14 @@ function component(a) {
12
13 ```
14
15 +## Code
16
16 -## Error
17 +```javascript
18 +// @inlineUseMemo
19 +function component(a) {
20 + mutate(a);
21 + return undefined;
22 +}
23
24 ```
19 -Expected value for identifier `9` to be initialized.
20 -```
21 -
25
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/useMemo-return-empty.js renamed
compiler/forget/src/__tests__/fixtures/compiler/useMemo-simple.expect.md
+2 -2
@@ -25,8 +25,8 @@ function component(a) {
25 } else {
26 t0 = $[1];
27 }
28 - const t9 = t0;
29 - const x = t9;
28 + const t10 = t0;
29 + const x = t10;
30 const c_2 = $[2] !== x;
31 let t1;
32 if (c_2) {
compiler/forget/src/__tests__/fixtures/compiler/useMemo-switch-no-fallthrough.expect.md
+4 -4
@@ -24,17 +24,17 @@ function Component(props) {
24 ```javascript
25 // @inlineUseMemo
26 function Component(props) {
27 - let t13 = undefined;
27 + let t14 = undefined;
28 bb8: switch (props.key) {
29 case "key": {
30 - t13 = props.value;
30 + t14 = props.value;
31 break bb8;
32 }
33 default: {
34 - t13 = props.defaultValue;
34 + t14 = props.defaultValue;
35 }
36 }
37 - const x = t13;
37 + const x = t14;
38 return x;
39 }
40
compiler/forget/src/__tests__/fixtures/compiler/while-conditional-continue.expect.md
+1
@@ -28,6 +28,7 @@ function foo(a, b, c, d) {
28 }
29
30 d();
31 + return undefined;
32 }
33
34 ```