Add missing return statements to fixtures
Joe Savona committed
Feb 6, 2023 at 14:09 UTC
382226ab3154967af30dd94ed61846eae5e2fe6b
38 files changed
+320
-81
compiler/forget/src/__tests__/fixtures/hir/_bug_invalid-scope.expect.md
deleted
-21
@@ -1,21 +0,0 @@
1
-
2
-## Input
3
-
4
-```javascript
5
-function g(a) {
6
- a.b.c = a.b.c + 1;
7
- a.b.c *= 2;
8
-}
9
-
10
-```
11
-
12
-## Code
13
-
14
-```javascript
15
-function g(a) {
16
- a.b.c = a.b.c + 1;
17
- a.b.c = a.b.c * 2;
18
-}
19
-
20
-```
21
-
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/_bug_invalid-scope.js
deleted
-4
@@ -1,4 +0,0 @@
1
-function g(a) {
2
- a.b.c = a.b.c + 1;
3
- a.b.c *= 2;
4
-}
compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.expect.md
+17
-8
@@ -9,6 +9,7 @@ function component() {
9
let x = {};
10
x.y = y;
11
mutate(x.y.z);
12
+ return x;
13
}
14
15
```
@@ -17,14 +18,22 @@ function component() {
18
19
```javascript
20
function component() {
20
- const z = [];
21
- const y = {};
22
- y.z = z;
23
-
24
- const x = {};
25
- x.y = y;
26
-
27
- mutate(x.y.z);
21
+ const $ = React.useMemoCache();
22
+ let x;
23
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
24
+ const z = [];
25
+ const y = {};
26
+ y.z = z;
27
+
28
+ x = {};
29
+ x.y = y;
30
+
31
+ mutate(x.y.z);
32
+ $[0] = x;
33
+ } else {
34
+ x = $[0];
35
+ }
36
+ return x;
37
}
38
39
```
compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.js
+1
@@ -5,4 +5,5 @@ function component() {
5
let x = {};
6
x.y = y;
7
mutate(x.y.z);
8
+ return x;
9
}
compiler/forget/src/__tests__/fixtures/hir/array-access-assignment.expect.md
+47
-4
@@ -3,8 +3,12 @@
3
4
```javascript
5
function foo(a, b, c) {
6
- a[0] = b[1];
7
- c[0][0] = a[0];
6
+ const x = [a];
7
+ const y = [null, b];
8
+ const z = [[], [], [c]];
9
+ x[0] = y[1];
10
+ z[0][0] = x[0];
11
+ return [x, z];
12
}
13
14
```
@@ -13,8 +17,47 @@ function foo(a, b, c) {
17
18
```javascript
19
function foo(a, b, c) {
16
- a[0] = b[1];
17
- c[0][0] = a[0];
20
+ const $ = React.useMemoCache();
21
+ const c_0 = $[0] !== a;
22
+ const c_1 = $[1] !== b;
23
+ const c_2 = $[2] !== c;
24
+ let x;
25
+ let z;
26
+ if (c_0 || c_1 || c_2) {
27
+ x = [a];
28
+ const c_5 = $[5] !== b;
29
+ let y;
30
+ if (c_5) {
31
+ y = [null, b];
32
+ $[5] = b;
33
+ $[6] = y;
34
+ } else {
35
+ y = $[6];
36
+ }
37
+ z = [[], [], [c]];
38
+ x[0] = y[1];
39
+ z[0][0] = x[0];
40
+ $[0] = a;
41
+ $[1] = b;
42
+ $[2] = c;
43
+ $[3] = x;
44
+ $[4] = z;
45
+ } else {
46
+ x = $[3];
47
+ z = $[4];
48
+ }
49
+ const c_7 = $[7] !== x;
50
+ const c_8 = $[8] !== z;
51
+ let t0;
52
+ if (c_7 || c_8) {
53
+ t0 = [x, z];
54
+ $[7] = x;
55
+ $[8] = z;
56
+ $[9] = t0;
57
+ } else {
58
+ t0 = $[9];
59
+ }
60
+ return t0;
61
}
62
63
```
compiler/forget/src/__tests__/fixtures/hir/array-access-assignment.js
+6
-2
@@ -1,4 +1,8 @@
1
function foo(a, b, c) {
2
- a[0] = b[1];
3
- c[0][0] = a[0];
2
+ const x = [a];
3
+ const y = [null, b];
4
+ const z = [[], [], [c]];
5
+ x[0] = y[1];
6
+ z[0][0] = x[0];
7
+ return [x, z];
8
}
compiler/forget/src/__tests__/fixtures/hir/assignment-expression-nested-path.expect.md
new
+34
@@ -0,0 +1,34 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function g(props) {
6
+ const a = { b: { c: props.c } };
7
+ a.b.c = a.b.c + 1;
8
+ a.b.c *= 2;
9
+ return a;
10
+}
11
+
12
+```
13
+
14
+## Code
15
+
16
+```javascript
17
+function g(props) {
18
+ const $ = React.useMemoCache();
19
+ const c_0 = $[0] !== props.c;
20
+ let a;
21
+ if (c_0) {
22
+ a = { b: { c: props.c } };
23
+ a.b.c = a.b.c + 1;
24
+ a.b.c = a.b.c * 2;
25
+ $[0] = props.c;
26
+ $[1] = a;
27
+ } else {
28
+ a = $[1];
29
+ }
30
+ return a;
31
+}
32
+
33
+```
34
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/assignment-expression-nested-path.js
new
+6
@@ -0,0 +1,6 @@
1
+function g(props) {
2
+ const a = { b: { c: props.c } };
3
+ a.b.c = a.b.c + 1;
4
+ a.b.c *= 2;
5
+ return a;
6
+}
compiler/forget/src/__tests__/fixtures/hir/assignment-variations.expect.md
+6
-1
@@ -7,6 +7,7 @@ function f() {
7
x = x + 1;
8
x += 1;
9
x >>>= 1;
10
+ return x;
11
}
12
13
```
@@ -14,7 +15,11 @@ function f() {
15
## Code
16
17
```javascript
17
-function f() {}
18
+function f() {
19
+ const x = 3;
20
+ const x$0 = x >>> 1;
21
+ return x$0;
22
+}
23
24
```
25
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/assignment-variations.js
+1
@@ -3,4 +3,5 @@ function f() {
3
x = x + 1;
4
x += 1;
5
x >>>= 1;
6
+ return x;
7
}
compiler/forget/src/__tests__/fixtures/hir/complex-while.expect.md
+3
-1
@@ -6,10 +6,11 @@ function foo(a, b, c) {
6
label: if (a) {
7
while (b) {
8
if (c) {
9
- break;
9
+ break label;
10
}
11
}
12
}
13
+ return c;
14
}
15
16
```
@@ -25,6 +26,7 @@ function foo(a, b, c) {
26
}
27
}
28
}
29
+ return c;
30
}
31
32
```
compiler/forget/src/__tests__/fixtures/hir/complex-while.js
+2
-1
@@ -2,8 +2,9 @@ function foo(a, b, c) {
2
label: if (a) {
3
while (b) {
4
if (c) {
5
- break;
5
+ break label;
6
}
7
}
8
}
9
+ return c;
10
}
compiler/forget/src/__tests__/fixtures/hir/dce-loop.expect.md
+14
-3
@@ -9,6 +9,7 @@ function foo(props) {
9
x++;
10
y++;
11
}
12
+ return y;
13
}
14
15
```
@@ -17,10 +18,20 @@ function foo(props) {
18
19
```javascript
20
function foo(props) {
20
- let y = 0;
21
- while (y < props.max) {
22
- y = y + 1;
21
+ const $ = React.useMemoCache();
22
+ const c_0 = $[0] !== props.max;
23
+ let y;
24
+ if (c_0) {
25
+ y = 0;
26
+ while (y < props.max) {
27
+ y = y + 1;
28
+ }
29
+ $[0] = props.max;
30
+ $[1] = y;
31
+ } else {
32
+ y = $[1];
33
}
34
+ return y;
35
}
36
37
```
compiler/forget/src/__tests__/fixtures/hir/dce-loop.js
+1
@@ -5,4 +5,5 @@ function foo(props) {
5
x++;
6
y++;
7
}
8
+ return y;
9
}
compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md
+18
-7
@@ -14,6 +14,7 @@ function foo(a, b) {
14
if (b) {
15
y.push(b);
16
}
17
+ return y;
18
}
19
20
```
@@ -33,14 +34,24 @@ function foo(a, b) {
34
} else {
35
x = $[1];
36
}
36
-
37
- const y = [];
38
- if (x.length) {
39
- y.push(x);
40
- }
41
- if (b) {
42
- y.push(b);
37
+ const c_2 = $[2] !== x;
38
+ const c_3 = $[3] !== b;
39
+ let y;
40
+ if (c_2 || c_3) {
41
+ y = [];
42
+ if (x.length) {
43
+ y.push(x);
44
+ }
45
+ if (b) {
46
+ y.push(b);
47
+ }
48
+ $[2] = x;
49
+ $[3] = b;
50
+ $[4] = y;
51
+ } else {
52
+ y = $[4];
53
}
54
+ return y;
55
}
56
57
```
compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.js
+1
@@ -10,4 +10,5 @@ function foo(a, b) {
10
if (b) {
11
y.push(b);
12
}
13
+ return y;
14
}
compiler/forget/src/__tests__/fixtures/hir/destructuring-assignment.expect.md
+23
-1
@@ -18,6 +18,7 @@ function foo(a, b, c) {
18
},
19
o,
20
} = b);
21
+ return { e, g, n, o };
22
}
23
24
```
@@ -25,7 +26,28 @@ function foo(a, b, c) {
26
## Code
27
28
```javascript
28
-function foo(a, b, c) {}
29
+function foo(a, b, c) {
30
+ const $ = React.useMemoCache();
31
+
32
+ const g = a[1][0].e.f;
33
+
34
+ const n = b.l.m[0][0];
35
+ const o = b.o;
36
+ const c_0 = $[0] !== g;
37
+ const c_1 = $[1] !== n;
38
+ const c_2 = $[2] !== o;
39
+ let t0;
40
+ if (c_0 || c_1 || c_2) {
41
+ t0 = { e: e, g: g, n: n, o: o };
42
+ $[0] = g;
43
+ $[1] = n;
44
+ $[2] = o;
45
+ $[3] = t0;
46
+ } else {
47
+ t0 = $[3];
48
+ }
49
+ return t0;
50
+}
51
52
```
53
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/destructuring-assignment.js
+1
@@ -14,4 +14,5 @@ function foo(a, b, c) {
14
},
15
o,
16
} = b);
17
+ return { e, g, n, o };
18
}
compiler/forget/src/__tests__/fixtures/hir/destructuring.expect.md
+25
-1
@@ -17,6 +17,7 @@ function foo(a, b, c) {
17
},
18
o,
19
} = b;
20
+ return [d, f, n, o];
21
}
22
23
```
@@ -24,7 +25,30 @@ function foo(a, b, c) {
25
## Code
26
27
```javascript
27
-function foo(a, b, c) {}
28
+function foo(a, b, c) {
29
+ const $ = React.useMemoCache();
30
+ const d = a[0];
31
+ const f = a[1][0].e.f;
32
+
33
+ const n = b.l.m[0][0];
34
+ const o = b.o;
35
+ const c_0 = $[0] !== d;
36
+ const c_1 = $[1] !== f;
37
+ const c_2 = $[2] !== n;
38
+ const c_3 = $[3] !== o;
39
+ let t0;
40
+ if (c_0 || c_1 || c_2 || c_3) {
41
+ t0 = [d, f, n, o];
42
+ $[0] = d;
43
+ $[1] = f;
44
+ $[2] = n;
45
+ $[3] = o;
46
+ $[4] = t0;
47
+ } else {
48
+ t0 = $[4];
49
+ }
50
+ return t0;
51
+}
52
53
```
54
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/destructuring.js
+1
@@ -13,4 +13,5 @@ function foo(a, b, c) {
13
},
14
o,
15
} = b;
16
+ return [d, f, n, o];
17
}
compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md
+22
-9
@@ -11,8 +11,8 @@ function foo(a, b, c) {
11
}
12
}
13
}
14
- if (a.length) {
15
- return a;
14
+ if (x.length) {
15
+ return x;
16
}
17
return null;
18
}
@@ -23,16 +23,29 @@ function foo(a, b, c) {
23
24
```javascript
25
function foo(a, b, c) {
26
- const x = [];
27
- if (a) {
28
- if (b) {
29
- if (c) {
30
- x.push(0);
26
+ const $ = React.useMemoCache();
27
+ const c_0 = $[0] !== a;
28
+ const c_1 = $[1] !== b;
29
+ const c_2 = $[2] !== c;
30
+ let x;
31
+ if (c_0 || c_1 || c_2) {
32
+ x = [];
33
+ if (a) {
34
+ if (b) {
35
+ if (c) {
36
+ x.push(0);
37
+ }
38
}
39
}
40
+ $[0] = a;
41
+ $[1] = b;
42
+ $[2] = c;
43
+ $[3] = x;
44
+ } else {
45
+ x = $[3];
46
}
34
- if (a.length) {
35
- return a;
47
+ if (x.length) {
48
+ return x;
49
}
50
return null;
51
}
compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.js
+2
-2
@@ -7,8 +7,8 @@ function foo(a, b, c) {
7
}
8
}
9
}
10
- if (a.length) {
11
- return a;
10
+ if (x.length) {
11
+ return x;
12
}
13
return null;
14
}
compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md
+2
@@ -7,6 +7,7 @@ function Component() {
7
const b = a;
8
useFreeze(a);
9
foo(b); // should be readonly, value is guaranteed frozen via alias
10
+ return b;
11
}
12
13
function useFreeze() {}
@@ -29,6 +30,7 @@ function Component() {
30
const b = a;
31
useFreeze(a);
32
foo(b);
33
+ return b;
34
}
35
36
function useFreeze() {}
compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.js
+1
@@ -3,6 +3,7 @@ function Component() {
3
const b = a;
4
useFreeze(a);
5
foo(b); // should be readonly, value is guaranteed frozen via alias
6
+ return b;
7
}
8
9
function useFreeze() {}
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md
+17
-2
@@ -8,7 +8,8 @@ function foo(a, b, c) {
8
if (c) {
9
x = c;
10
}
11
- x;
11
+ // TODO: move the return to the end of the function
12
+ return x;
13
}
14
}
15
@@ -18,9 +19,23 @@ function foo(a, b, c) {
19
20
```javascript
21
function foo(a, b, c) {
22
+ const $ = React.useMemoCache();
23
+ const x = a;
24
if (b) {
22
- if (c) {
25
+ const c_0 = $[0] !== c;
26
+ let x$0;
27
+ if (c_0) {
28
+ x$0 = x;
29
+ if (c) {
30
+ const x$1 = c;
31
+ x$0 = x$1;
32
+ }
33
+ $[0] = c;
34
+ $[1] = x$0;
35
+ } else {
36
+ x$0 = $[1];
37
}
38
+ return x$0;
39
}
40
}
41
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.js
+2
-1
@@ -4,6 +4,7 @@ function foo(a, b, c) {
4
if (c) {
5
x = c;
6
}
7
- x;
7
+ // TODO: move the return to the end of the function
8
+ return x;
9
}
10
}
compiler/forget/src/__tests__/fixtures/hir/type-field-load.expect.md
+13
-1
@@ -5,6 +5,7 @@
5
function component() {
6
let x = { t: 1 };
7
let p = x.t;
8
+ return p;
9
}
10
11
```
@@ -12,7 +13,18 @@ function component() {
13
## Code
14
15
```javascript
15
-function component() {}
16
+function component() {
17
+ const $ = React.useMemoCache();
18
+ let x;
19
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
20
+ x = { t: 1 };
21
+ $[0] = x;
22
+ } else {
23
+ x = $[0];
24
+ }
25
+ const p = x.t;
26
+ return p;
27
+}
28
29
```
30
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/type-field-load.js
+1
@@ -1,4 +1,5 @@
1
function component() {
2
let x = { t: 1 };
3
let p = x.t;
4
+ return p;
5
}
compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md
+4
@@ -11,6 +11,7 @@ function component() {
11
12
let y = x.u;
13
let z = x.v;
14
+ return z;
15
}
16
17
```
@@ -45,6 +46,9 @@ function component() {
46
const v = x.v;
47
if (u > v) {
48
}
49
+
50
+ const z = x.v;
51
+ return z;
52
}
53
54
```
compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.js
+1
@@ -7,4 +7,5 @@ function component() {
7
8
let y = x.u;
9
let z = x.v;
10
+ return z;
11
}
compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.expect.md
+16
-6
@@ -7,6 +7,7 @@ function component() {
7
let q = {};
8
x.t = q;
9
let z = x.t;
10
+ return z;
11
}
12
13
```
@@ -16,15 +17,24 @@ function component() {
17
```javascript
18
function component() {
19
const $ = React.useMemoCache();
19
- const x = {};
20
- let q;
20
+ let x;
21
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
22
- q = {};
23
- $[0] = q;
22
+ x = {};
23
+ let q;
24
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
25
+ q = {};
26
+ $[1] = q;
27
+ } else {
28
+ q = $[1];
29
+ }
30
+ x.t = q;
31
+ $[0] = x;
32
} else {
25
- q = $[0];
33
+ x = $[0];
34
}
27
- x.t = q;
35
+
36
+ const z = x.t;
37
+ return z;
38
}
39
40
```
compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.js
+1
@@ -3,4 +3,5 @@ function component() {
3
let q = {};
4
x.t = q;
5
let z = x.t;
6
+ return z;
7
}
compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.expect.md
+12
-3
@@ -14,6 +14,7 @@ function component() {
14
15
x.t = o; // generalize x.t
16
let y = x.t;
17
+ return y;
18
}
19
20
```
@@ -37,10 +38,18 @@ function component() {
38
} else {
39
o = $[1];
40
}
41
+ let x;
42
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
43
+ x = {};
44
+ x.t = p;
45
+ x.t = o;
46
+ $[2] = x;
47
+ } else {
48
+ x = $[2];
49
+ }
50
41
- const x = {};
42
- x.t = p;
43
- x.t = o;
51
+ const y = x.t;
52
+ return y;
53
}
54
55
```
compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.js
+1
@@ -10,4 +10,5 @@ function component() {
10
11
x.t = o; // generalize x.t
12
let y = x.t;
13
+ return y;
14
}
compiler/forget/src/__tests__/fixtures/hir/type-test-primitive.expect.md
+6
-1
@@ -5,6 +5,8 @@
5
function component() {
6
let x = 1;
7
let y = 2;
8
+
9
+ return y;
10
}
11
12
```
@@ -12,7 +14,10 @@ function component() {
14
## Code
15
16
```javascript
15
-function component() {}
17
+function component() {
18
+ const y = 2;
19
+ return y;
20
+}
21
22
```
23
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/type-test-primitive.js
+2
@@ -1,4 +1,6 @@
1
function component() {
2
let x = 1;
3
let y = 2;
4
+
5
+ return y;
6
}
compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md
+9
-2
@@ -10,6 +10,7 @@ function component() {
10
}
11
12
let z = foo();
13
+ return z;
14
}
15
16
```
@@ -35,8 +36,14 @@ function component() {
36
}
37
if (x > y) {
38
}
38
-
39
- const z_0 = foo();
39
+ let z_0;
40
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
41
+ z_0 = foo();
42
+ $[2] = z_0;
43
+ } else {
44
+ z_0 = $[2];
45
+ }
46
+ return z_0;
47
}
48
49
```
compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.js
+1
@@ -6,4 +6,5 @@ function component() {
6
}
7
8
let z = foo();
9
+ return z;
10
}