Use BabelPlugin in hir-test
Lauren Tan committed
Jan 19, 2023 at 11:37 UTC
b98e87aa633944d3b28ba2f4ad1fd18b13c93b0f
124 files changed
+188
-742
compiler/forget/src/Babel/BabelPlugin.ts
+5
-4
@@ -8,22 +8,23 @@
8
/// <reference path="./plugin-syntax-jsx.d.ts" />
9
10
import type * as BabelCore from "@babel/core";
11
-import type { PluginObj } from "@babel/core";
11
import jsx from "@babel/plugin-syntax-jsx";
12
import { compile } from "../CompilerPipeline";
13
14
/**
15
* The React Forget Babel Plugin
17
- * @param {*} babel
16
+ * @param {*} _babel
17
* @returns
18
*/
20
-export default function (babel: typeof BabelCore): PluginObj {
19
+export default function ReactForgetBabelPlugin(
20
+ _babel: typeof BabelCore
21
+): BabelCore.PluginObj {
22
return {
23
name: "react-forget",
24
inherits: jsx,
25
visitor: {
26
FunctionDeclaration: {
26
- enter(fn, pass) {
27
+ enter(fn, _pass) {
28
if (fn.scope.getProgramParent() !== fn.scope.parent) {
29
return;
30
}
compiler/forget/src/Babel/RunReactForgetBabelPlugin.ts
new
+40
@@ -0,0 +1,40 @@
1
+import type * as BabelCore from "@babel/core";
2
+import { transformFromAstSync } from "@babel/core";
3
+import * as parser from "@babel/parser";
4
+import invariant from "invariant";
5
+import prettier from "prettier";
6
+import ReactForgetBabelPlugin from "./BabelPlugin";
7
+
8
+type ReactForgetBabelPluginResult = {
9
+ ast: BabelCore.BabelFileResult["ast"];
10
+ code: string;
11
+ map: BabelCore.BabelFileResult["map"];
12
+};
13
+
14
+export default function runReactForgetBabelPlugin(
15
+ text: string,
16
+ file: string
17
+): ReactForgetBabelPluginResult {
18
+ const ast = parser.parse(text, {
19
+ sourceFilename: file,
20
+ plugins: ["typescript", "jsx"],
21
+ });
22
+ const result = transformFromAstSync(ast, text, {
23
+ filename: file,
24
+ highlightCode: false,
25
+ retainLines: true,
26
+ plugins: [ReactForgetBabelPlugin],
27
+ });
28
+ invariant(
29
+ result?.code != null,
30
+ `Expected BabelPluginReactForget to codegen successfully, got: ${result}`
31
+ );
32
+ return {
33
+ ast: result.ast,
34
+ code: prettier.format(result.code, {
35
+ semi: true,
36
+ parser: "babel-ts",
37
+ }),
38
+ map: result.map,
39
+ };
40
+}
compiler/forget/src/__tests__/fixtures/hir/_bug_expression-with-assignment.expect.md
+1
@@ -16,6 +16,7 @@ function f() {
16
```javascript
17
function f() {
18
const x = 1;
19
+
20
const x$0 = 2;
21
4;
22
return 6;
compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path-mutate.expect.md
+2
@@ -20,8 +20,10 @@ 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);
28
}
29
compiler/forget/src/__tests__/fixtures/hir/alias-nested-member-path.expect.md
-5
@@ -25,10 +25,8 @@ function component() {
25
} else {
26
z = $[0];
27
}
28
-
28
const c_1 = $[1] !== z;
29
let y;
31
-
30
if (c_1) {
31
y = {};
32
y.z = z;
@@ -37,10 +35,8 @@ function component() {
35
} else {
36
y = $[2];
37
}
40
-
38
const c_3 = $[3] !== y;
39
let x;
43
-
40
if (c_3) {
41
x = {};
42
x.y = y;
@@ -49,7 +45,6 @@ function component() {
45
} else {
46
x = $[4];
47
}
52
-
48
return x;
49
}
50
compiler/forget/src/__tests__/fixtures/hir/alias-while.expect.md
-7
@@ -36,7 +36,6 @@ function foo(cond) {
36
a = {};
37
b = {};
38
c = {};
39
-
39
while (cond) {
40
const z = a;
41
a = b;
@@ -44,7 +43,6 @@ function foo(cond) {
43
c = z;
44
mutate(a, b);
45
}
47
-
46
$[0] = cond;
47
$[1] = a;
48
$[2] = b;
@@ -54,17 +52,12 @@ function foo(cond) {
52
b = $[2];
53
c = $[3];
54
}
57
-
55
a;
56
b;
57
c;
58
return a;
59
}
60
64
-```
65
-## Code
66
-
67
-```javascript
61
function mutate(x, y) {}
62
63
```
compiler/forget/src/__tests__/fixtures/hir/assignment-variations-complex-lvalue-array.expect.md
-1
@@ -25,7 +25,6 @@ function foo() {
25
} else {
26
a = $[0];
27
}
28
-
28
return a;
29
}
30
compiler/forget/src/__tests__/fixtures/hir/assignment-variations-complex-lvalue.expect.md
+1
-6
@@ -18,18 +18,13 @@ function g() {
18
const $ = React.useMemoCache();
19
let x;
20
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
21
- x = {
22
- y: {
23
- z: 1,
24
- },
25
- };
21
+ x = { y: { z: 1 } };
22
x.y.z = x.y.z + 1;
23
x.y.z = x.y.z * 2;
24
$[0] = x;
25
} else {
26
x = $[0];
27
}
32
-
28
return x;
29
}
30
compiler/forget/src/__tests__/fixtures/hir/call.expect.md
-9
@@ -20,10 +20,6 @@ function Component(props) {
20
```javascript
21
function foo() {}
22
23
-```
24
-## Code
25
-
26
-```javascript
23
function Component(props) {
24
const $ = React.useMemoCache();
25
let a;
@@ -32,9 +28,7 @@ function Component(props) {
28
a = [];
29
b = {};
30
foo(a, b);
35
-
31
const _ = <div a={a}></div>;
37
-
32
foo(b);
33
$[0] = a;
34
$[1] = b;
@@ -42,11 +36,9 @@ function Component(props) {
36
a = $[0];
37
b = $[1];
38
}
45
-
39
const c_2 = $[2] !== a;
40
const c_3 = $[3] !== b;
41
let t4;
49
-
42
if (c_2 || c_3) {
43
t4 = <div a={a} b={b}></div>;
44
$[2] = a;
@@ -55,7 +47,6 @@ function Component(props) {
47
} else {
48
t4 = $[4];
49
}
58
-
50
return t4;
51
}
52
compiler/forget/src/__tests__/fixtures/hir/capturing-function-1.expect.md
+1
-7
@@ -20,29 +20,23 @@ function component(a) {
20
const c_0 = $[0] !== a;
21
let z;
22
if (c_0) {
23
- z = {
24
- a: a,
25
- };
23
+ z = { a: a };
24
$[0] = a;
25
$[1] = z;
26
} else {
27
z = $[1];
28
}
31
-
29
const c_2 = $[2] !== z;
30
let x;
34
-
31
if (c_2) {
32
x = function () {
33
z;
34
};
39
-
35
$[2] = z;
36
$[3] = x;
37
} else {
38
x = $[3];
39
}
45
-
40
return x;
41
}
42
compiler/forget/src/__tests__/fixtures/hir/capturing-function-within-block.expect.md
+1
-7
@@ -23,30 +23,24 @@ function component(a) {
23
const c_0 = $[0] !== a;
24
let z;
25
if (c_0) {
26
- z = {
27
- a: a,
28
- };
26
+ z = { a: a };
27
$[0] = a;
28
$[1] = z;
29
} else {
30
z = $[1];
31
}
34
-
32
const x = undefined;
33
const c_2 = $[2] !== z;
34
let x$0;
38
-
35
if (c_2) {
36
x$0 = function () {
37
z;
38
};
43
-
39
$[2] = z;
40
$[3] = x$0;
41
} else {
42
x$0 = $[3];
43
}
49
-
44
return x$0;
45
}
46
compiler/forget/src/__tests__/fixtures/hir/capturing-member-expr.expect.md
+1
-7
@@ -20,29 +20,23 @@ function component(a) {
20
const c_0 = $[0] !== a;
21
let z;
22
if (c_0) {
23
- z = {
24
- a: a,
25
- };
23
+ z = { a: a };
24
$[0] = a;
25
$[1] = z;
26
} else {
27
z = $[1];
28
}
31
-
29
const c_2 = $[2] !== z.a;
30
let x;
34
-
31
if (c_2) {
32
x = function () {
33
z.a;
34
};
39
-
35
$[2] = z.a;
36
$[3] = x;
37
} else {
38
x = $[3];
39
}
45
-
40
return x;
41
}
42
compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-call.expect.md
+2
-12
@@ -20,42 +20,32 @@ function component(a) {
20
const c_0 = $[0] !== a;
21
let t1;
22
if (c_0) {
23
- t1 = {
24
- a: a,
25
- };
23
+ t1 = { a: a };
24
$[0] = a;
25
$[1] = t1;
26
} else {
27
t1 = $[1];
28
}
31
-
29
const c_2 = $[2] !== t1;
30
let z;
34
-
31
if (c_2) {
36
- z = {
37
- a: t1,
38
- };
32
+ z = { a: t1 };
33
$[2] = t1;
34
$[3] = z;
35
} else {
36
z = $[3];
37
}
44
-
38
const c_4 = $[4] !== z.a.a;
39
let x;
47
-
40
if (c_4) {
41
x = function () {
42
z.a.a();
43
};
52
-
44
$[4] = z.a.a;
45
$[5] = x;
46
} else {
47
x = $[5];
48
}
58
-
49
return x;
50
}
51
compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr-in-nested-func.expect.md
+2
-12
@@ -22,44 +22,34 @@ function component(a) {
22
const c_0 = $[0] !== a;
23
let t1;
24
if (c_0) {
25
- t1 = {
26
- a: a,
27
- };
25
+ t1 = { a: a };
26
$[0] = a;
27
$[1] = t1;
28
} else {
29
t1 = $[1];
30
}
33
-
31
const c_2 = $[2] !== t1;
32
let z;
36
-
33
if (c_2) {
38
- z = {
39
- a: t1,
40
- };
34
+ z = { a: t1 };
35
$[2] = t1;
36
$[3] = z;
37
} else {
38
z = $[3];
39
}
46
-
40
const c_4 = $[4] !== z.a.a;
41
let x;
49
-
42
if (c_4) {
43
x = function () {
44
(function () {
45
z.a.a;
46
})();
47
};
56
-
48
$[4] = z.a.a;
49
$[5] = x;
50
} else {
51
x = $[5];
52
}
62
-
53
return x;
54
}
55
compiler/forget/src/__tests__/fixtures/hir/capturing-nested-member-expr.expect.md
+2
-12
@@ -20,42 +20,32 @@ function component(a) {
20
const c_0 = $[0] !== a;
21
let t1;
22
if (c_0) {
23
- t1 = {
24
- a: a,
25
- };
23
+ t1 = { a: a };
24
$[0] = a;
25
$[1] = t1;
26
} else {
27
t1 = $[1];
28
}
31
-
29
const c_2 = $[2] !== t1;
30
let z;
34
-
31
if (c_2) {
36
- z = {
37
- a: t1,
38
- };
32
+ z = { a: t1 };
33
$[2] = t1;
34
$[3] = z;
35
} else {
36
z = $[3];
37
}
44
-
38
const c_4 = $[4] !== z.a.a;
39
let x;
47
-
40
if (c_4) {
41
x = function () {
42
z.a.a;
43
};
52
-
44
$[4] = z.a.a;
45
$[5] = x;
46
} else {
47
x = $[5];
48
}
58
-
49
return x;
50
}
51
compiler/forget/src/__tests__/fixtures/hir/capturing-var-in-nested-func-decl.expect.md
+1
-8
@@ -23,33 +23,26 @@ function component(a) {
23
const c_0 = $[0] !== a;
24
let z;
25
if (c_0) {
26
- z = {
27
- a: a,
28
- };
26
+ z = { a: a };
27
$[0] = a;
28
$[1] = z;
29
} else {
30
z = $[1];
31
}
34
-
32
const c_2 = $[2] !== z;
33
let x;
37
-
34
if (c_2) {
35
x = function () {
36
function t() {
37
z;
38
}
43
-
39
t();
40
};
46
-
41
$[2] = z;
42
$[3] = x;
43
} else {
44
x = $[3];
45
}
52
-
46
return x;
47
}
48
compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-block.expect.md
+1
-7
@@ -22,31 +22,25 @@ function component(a) {
22
const c_0 = $[0] !== a;
23
let z;
24
if (c_0) {
25
- z = {
26
- a: a,
27
- };
25
+ z = { a: a };
26
$[0] = a;
27
$[1] = z;
28
} else {
29
z = $[1];
30
}
33
-
31
const c_2 = $[2] !== z;
32
let x;
36
-
33
if (c_2) {
34
x = function () {
35
{
36
z;
37
}
38
};
43
-
39
$[2] = z;
40
$[3] = x;
41
} else {
42
x = $[3];
43
}
49
-
44
return x;
45
}
46
compiler/forget/src/__tests__/fixtures/hir/capturing-variable-in-nested-function.expect.md
+1
-7
@@ -22,31 +22,25 @@ function component(a) {
22
const c_0 = $[0] !== a;
23
let z;
24
if (c_0) {
25
- z = {
26
- a: a,
27
- };
25
+ z = { a: a };
26
$[0] = a;
27
$[1] = z;
28
} else {
29
z = $[1];
30
}
33
-
31
const c_2 = $[2] !== z;
32
let x;
36
-
33
if (c_2) {
34
x = function () {
35
(function () {
36
z;
37
})();
38
};
43
-
39
$[2] = z;
40
$[3] = x;
41
} else {
42
x = $[3];
43
}
49
-
44
return x;
45
}
46
compiler/forget/src/__tests__/fixtures/hir/chained-assignment-expressions.expect.md
+3
-9
@@ -17,15 +17,9 @@ function foo() {
17
18
```javascript
19
function foo() {
20
- const x = {
21
- x: 0,
22
- };
23
- const y = {
24
- z: 0,
25
- };
26
- const z = {
27
- z: 0,
28
- };
20
+ const x = { x: 0 };
21
+ const y = { z: 0 };
22
+ const z = { z: 0 };
23
x.x = x.x + (y.y = y.y * 1);
24
z.z = z.z + (y.y = y.y * (x.x = x.x & 3));
25
return z;
compiler/forget/src/__tests__/fixtures/hir/component.expect.md
-10
@@ -46,7 +46,6 @@ function Component(props) {
46
const seen = new Set();
47
const c_3 = $[3] !== maxItems;
48
let max;
49
-
49
if (c_3) {
50
max = Math.max(0, maxItems);
51
$[3] = maxItems;
@@ -54,26 +53,21 @@ function Component(props) {
53
} else {
54
max = $[4];
55
}
57
-
56
for (let i = 0; i < items.length; i = i + 1, i) {
57
const item = items.at(i);
60
-
58
if (item == null) {
59
} else {
60
}
64
-
61
if (seen.has(item)) {
62
continue;
63
}
64
65
seen.add(item);
66
renderedItems.push(<div>{item}</div>);
71
-
67
if (renderedItems.length >= max) {
68
break;
69
}
70
}
76
-
71
$[0] = maxItems;
72
$[1] = items;
73
$[2] = renderedItems;
@@ -84,7 +78,6 @@ function Component(props) {
78
const count = renderedItems.length;
79
const c_5 = $[5] !== count;
80
let t6;
87
-
81
if (c_5) {
82
t6 = <h1>{count} Items</h1>;
83
$[5] = count;
@@ -92,11 +85,9 @@ function Component(props) {
85
} else {
86
t6 = $[6];
87
}
95
-
88
const c_7 = $[7] !== t6;
89
const c_8 = $[8] !== renderedItems;
90
let t9;
99
-
91
if (c_7 || c_8) {
92
t9 = (
93
<div>
@@ -110,7 +101,6 @@ function Component(props) {
101
} else {
102
t9 = $[9];
103
}
113
-
104
return t9;
105
}
106
compiler/forget/src/__tests__/fixtures/hir/conditional-break.expect.md
+12
-20
@@ -61,6 +61,9 @@ function Component(props) {
61
## Code
62
63
```javascript
64
+/**
65
+ * props.b does *not* influence `a`
66
+ */
67
function Component(props) {
68
const $ = React.useMemoCache();
69
const c_0 = $[0] !== props.a;
@@ -70,7 +73,6 @@ function Component(props) {
73
if (c_0 || c_1 || c_2) {
74
a_DEBUG = [];
75
a_DEBUG.push(props.a);
73
-
76
if (props.b) {
77
return null;
78
}
@@ -83,14 +85,12 @@ function Component(props) {
85
} else {
86
a_DEBUG = $[3];
87
}
86
-
88
return a_DEBUG;
89
}
90
90
-```
91
-## Code
92
-
93
-```javascript
91
+/**
92
+ * props.b *does* influence `a`
93
+ */
94
function Component(props) {
95
const $ = React.useMemoCache();
96
const c_0 = $[0] !== props.a;
@@ -101,7 +101,6 @@ function Component(props) {
101
if (c_0 || c_1 || c_2 || c_3) {
102
a = [];
103
a.push(props.a);
104
-
104
if (props.b) {
105
a.push(props.c);
106
}
@@ -115,14 +114,12 @@ function Component(props) {
114
} else {
115
a = $[4];
116
}
118
-
117
return a;
118
}
119
122
-```
123
-## Code
124
-
125
-```javascript
120
+/**
121
+ * props.b *does* influence `a`, but only in a way that is never observable
122
+ */
123
function Component(props) {
124
const $ = React.useMemoCache();
125
const c_0 = $[0] !== props.a;
@@ -133,7 +130,6 @@ function Component(props) {
130
if (c_0 || c_1 || c_2 || c_3) {
131
a = [];
132
a.push(props.a);
136
-
133
if (props.b) {
134
a.push(props.c);
135
return null;
@@ -148,14 +144,12 @@ function Component(props) {
144
} else {
145
a = $[4];
146
}
151
-
147
return a;
148
}
149
155
-```
156
-## Code
157
-
158
-```javascript
150
+/**
151
+ * props.b *does* influence `a`
152
+ */
153
function Component(props) {
154
const $ = React.useMemoCache();
155
const c_0 = $[0] !== props.a;
@@ -166,7 +160,6 @@ function Component(props) {
160
if (c_0 || c_1 || c_2 || c_3) {
161
a = [];
162
a.push(props.a);
169
-
163
if (props.b) {
164
a.push(props.c);
165
return a;
@@ -181,7 +174,6 @@ function Component(props) {
174
} else {
175
a = $[4];
176
}
184
-
177
return a;
178
}
179
compiler/forget/src/__tests__/fixtures/hir/conditional-on-mutable.expect.md
-25
@@ -43,15 +43,12 @@ function Component(props) {
43
if (c_0 || c_1 || c_2) {
44
a = [];
45
const b = [];
46
-
46
if (b) {
47
a.push(props.p0);
48
}
50
-
49
if (props.p1) {
50
b.push(props.p2);
51
}
54
-
52
$[0] = props.p0;
53
$[1] = props.p1;
54
$[2] = props.p2;
@@ -59,11 +56,9 @@ function Component(props) {
56
} else {
57
a = $[3];
58
}
62
-
59
const c_4 = $[4] !== a;
60
const c_5 = $[5] !== b;
61
let t6;
66
-
62
if (c_4 || c_5) {
63
t6 = <Foo a={a} b={b}></Foo>;
64
$[4] = a;
@@ -72,14 +67,9 @@ function Component(props) {
67
} else {
68
t6 = $[6];
69
}
75
-
70
return t6;
71
}
72
79
-```
80
-## Code
81
-
82
-```javascript
73
function Component(props) {
74
const $ = React.useMemoCache();
75
const c_0 = $[0] !== props.p0;
@@ -89,15 +79,12 @@ function Component(props) {
79
if (c_0 || c_1 || c_2) {
80
a = [];
81
const b = [];
92
-
82
if (mayMutate(b)) {
83
a.push(props.p0);
84
}
96
-
85
if (props.p1) {
86
b.push(props.p2);
87
}
100
-
88
$[0] = props.p0;
89
$[1] = props.p1;
90
$[2] = props.p2;
@@ -105,11 +92,9 @@ function Component(props) {
92
} else {
93
a = $[3];
94
}
108
-
95
const c_4 = $[4] !== a;
96
const c_5 = $[5] !== b;
97
let t6;
112
-
98
if (c_4 || c_5) {
99
t6 = <Foo a={a} b={b}></Foo>;
100
$[4] = a;
@@ -118,20 +103,10 @@ function Component(props) {
103
} else {
104
t6 = $[6];
105
}
121
-
106
return t6;
107
}
108
125
-```
126
-## Code
127
-
128
-```javascript
109
function Foo() {}
130
-
131
-```
132
-## Code
133
-
134
-```javascript
110
function mayMutate() {}
111
112
```
compiler/forget/src/__tests__/fixtures/hir/constant-propagation-for.expect.md
-3
@@ -20,16 +20,13 @@ function foo() {
20
let y;
21
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
22
y = 0;
23
-
23
for (const x = 100; 10, false; 100) {
24
y = y + 1;
25
}
27
-
26
$[0] = y;
27
} else {
28
y = $[0];
29
}
32
-
30
return y;
31
}
32
compiler/forget/src/__tests__/fixtures/hir/constant-propagation-phi.expect.md
+2
-1
@@ -27,15 +27,16 @@ function foo(a, b, c) {
27
if (a) {
28
2;
29
1;
30
+
31
const x$1 = 1;
32
x$0 = x$1;
33
} else {
34
0;
35
1;
36
+
37
const x$2 = 1;
38
x$0 = x$2;
39
}
38
-
40
1;
41
true;
42
return b;
compiler/forget/src/__tests__/fixtures/hir/constant-propagation-while.expect.md
-3
@@ -22,16 +22,13 @@ function foo() {
22
let y;
23
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
24
y = 0;
25
-
25
while ((10, false)) {
26
y = y + 1;
27
}
29
-
28
$[0] = y;
29
} else {
30
y = $[0];
31
}
34
-
32
return y;
33
}
34
compiler/forget/src/__tests__/fixtures/hir/constant-propagation.expect.md
+2
@@ -34,7 +34,9 @@ function foo() {
34
const e = 9;
35
const f = 3;
36
const g = -6;
37
+
38
console.log("foo");
39
+
40
const h = -6;
41
const i = -6;
42
const j = -6;
compiler/forget/src/__tests__/fixtures/hir/constructor.expect.md
-8
@@ -20,10 +20,6 @@ function Component(props) {
20
```javascript
21
function Foo() {}
22
23
-```
24
-## Code
25
-
26
-```javascript
23
function Component(props) {
24
const $ = React.useMemoCache();
25
let a;
@@ -34,7 +30,6 @@ function Component(props) {
30
new Foo(a, b);
31
32
const _ = <div a={a}></div>;
37
-
33
new Foo(b);
34
$[0] = a;
35
$[1] = b;
@@ -42,11 +37,9 @@ function Component(props) {
37
a = $[0];
38
b = $[1];
39
}
45
-
40
const c_2 = $[2] !== a;
41
const c_3 = $[3] !== b;
42
let t4;
49
-
43
if (c_2 || c_3) {
44
t4 = <div a={a} b={b}></div>;
45
$[2] = a;
@@ -55,7 +48,6 @@ function Component(props) {
48
} else {
49
t4 = $[4];
50
}
58
-
51
return t4;
52
}
53
compiler/forget/src/__tests__/fixtures/hir/dependencies-outputs.expect.md
+1
-3
@@ -33,14 +33,12 @@ function foo(a, b) {
33
} else {
34
x = $[1];
35
}
36
-
36
<div>{x}</div>;
38
- const y = [];
37
38
+ const y = [];
39
if (x.length) {
40
y.push(x);
41
}
43
-
42
if (b) {
43
y.push(b);
44
}
compiler/forget/src/__tests__/fixtures/hir/dependencies.expect.md
-4
@@ -32,22 +32,18 @@ function foo(x, y, z) {
32
let items2;
33
if (c_0 || c_1) {
34
items2 = [];
35
-
35
if (x) {
36
items2.push(y);
37
}
39
-
38
$[0] = x;
39
$[1] = y;
40
$[2] = items2;
41
} else {
42
items2 = $[2];
43
}
46
-
44
if (y) {
45
items.push(x);
46
}
50
-
47
return items2;
48
}
49
compiler/forget/src/__tests__/fixtures/hir/destructuring-assignment.expect.md
+1
@@ -32,6 +32,7 @@ function foo(a, b, c) {
32
const o = undefined;
33
const d$0 = a[0];
34
const g$1 = a[1][0].e.f;
35
+
36
const n$2 = b.l.m[0][0];
37
const o$3 = b.o;
38
}
compiler/forget/src/__tests__/fixtures/hir/destructuring.expect.md
+1
@@ -27,6 +27,7 @@ function foo(a, b, c) {
27
function foo(a, b, c) {
28
const d = a[0];
29
const f = a[1][0].e.f;
30
+
31
const n = b.l.m[0][0];
32
const o = b.o;
33
}
compiler/forget/src/__tests__/fixtures/hir/extend-scopes-if.expect.md
-2
@@ -31,11 +31,9 @@ function foo(a, b, c) {
31
}
32
}
33
}
34
-
34
if (a.length) {
35
return a;
36
}
38
-
37
return null;
38
}
39
compiler/forget/src/__tests__/fixtures/hir/frozen-after-alias.expect.md
-10
@@ -26,22 +26,12 @@ function Component() {
26
} else {
27
a = $[0];
28
}
29
-
29
const b = a;
30
useFreeze(a);
31
foo(b);
32
}
33
35
-```
36
-## Code
37
-
38
-```javascript
34
function useFreeze() {}
40
-
41
-```
42
-## Code
43
-
44
-```javascript
35
function foo(x) {}
36
37
```
compiler/forget/src/__tests__/fixtures/hir/hook-call.expect.md
-14
@@ -23,17 +23,8 @@ function Component(props) {
23
24
```javascript
25
function useFreeze() {}
26
-
27
-```
28
-## Code
29
-
30
-```javascript
26
function foo() {}
27
33
-```
34
-## Code
35
-
36
-```javascript
28
function Component(props) {
29
const $ = React.useMemoCache();
30
let x;
@@ -43,10 +34,8 @@ function Component(props) {
34
} else {
35
x = $[0];
36
}
46
-
37
const c_1 = $[1] !== x;
38
let y;
49
-
39
if (c_1) {
40
y = useFreeze(x);
41
$[1] = x;
@@ -54,12 +43,10 @@ function Component(props) {
43
} else {
44
y = $[2];
45
}
57
-
46
foo(y, x);
47
const c_3 = $[3] !== x;
48
const c_4 = $[4] !== y;
49
let t5;
62
-
50
if (c_3 || c_4) {
51
t5 = (
52
<Component>
@@ -73,7 +60,6 @@ function Component(props) {
60
} else {
61
t5 = $[5];
62
}
76
-
63
return t5;
64
}
65
compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-arguments.expect.md
-10
@@ -27,23 +27,13 @@ function Component() {
27
} else {
28
a = $[0];
29
}
30
-
30
useFreeze(a);
31
useFreeze(a);
32
call(a);
33
return a;
34
}
35
37
-```
38
-## Code
39
-
40
-```javascript
36
function useFreeze(x) {}
42
-
43
-```
44
-## Code
45
-
46
-```javascript
37
function call(x) {}
38
39
```
compiler/forget/src/__tests__/fixtures/hir/hooks-freeze-possibly-mutable-arguments.expect.md
-13
@@ -35,23 +35,19 @@ function Component(props) {
35
let a$0;
36
if (c_0 || c_1) {
37
a$0 = undefined;
38
-
38
if (cond) {
39
const a$1 = x;
40
a$0 = a$1;
41
} else {
42
let a$2;
44
-
43
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
44
a$2 = [];
45
$[3] = a$2;
46
} else {
47
a$2 = $[3];
48
}
51
-
49
a$0 = a$2;
50
}
54
-
51
$[0] = cond;
52
$[1] = x;
53
$[2] = a$0;
@@ -65,16 +61,7 @@ function Component(props) {
61
return a$0;
62
}
63
68
-```
69
-## Code
70
-
71
-```javascript
64
function useFreeze(x) {}
73
-
74
-```
75
-## Code
76
-
77
-```javascript
65
function call(x) {}
66
67
```
compiler/forget/src/__tests__/fixtures/hir/independent-across-if.expect.md
+14
-24
@@ -37,29 +37,24 @@ function Component(props) {
37
38
```javascript
39
function compute() {}
40
-
41
-```
42
-## Code
43
-
44
-```javascript
40
function mutate() {}
46
-
47
-```
48
-## Code
49
-
50
-```javascript
41
function foo() {}
52
-
53
-```
54
-## Code
55
-
56
-```javascript
42
function Foo() {}
43
59
-```
60
-## Code
61
-
62
-```javascript
44
+/**
45
+ * Should produce 3 scopes:
46
+ *
47
+ * a: inputs=props.a & props.c; outputs=a
48
+ * a = compute(props.a);
49
+ * if (props.c)
50
+ * mutate(a)
51
+ * b: inputs=props.b & props.c; outputs=b
52
+ * b = compute(props.b);
53
+ * if (props.c)
54
+ * mutate(b)
55
+ * return: inputs=a, b outputs=return
56
+ * return = <Foo a={a} b={b} />
57
+ */
58
function Component(props) {
59
const $ = React.useMemoCache();
60
const c_0 = $[0] !== props.a;
@@ -69,12 +64,10 @@ function Component(props) {
64
if (c_0 || c_1 || c_2) {
65
a = compute(props.a);
66
const b = compute(props.b);
72
-
67
if (props.c) {
68
mutate(a);
69
mutate(b);
70
}
77
-
71
$[0] = props.a;
72
$[1] = props.b;
73
$[2] = props.c;
@@ -82,11 +75,9 @@ function Component(props) {
75
} else {
76
a = $[3];
77
}
85
-
78
const c_4 = $[4] !== a;
79
const c_5 = $[5] !== b;
80
let t6;
89
-
81
if (c_4 || c_5) {
82
t6 = <Foo a={a} b={b}></Foo>;
83
$[4] = a;
@@ -95,7 +86,6 @@ function Component(props) {
86
} else {
87
t6 = $[6];
88
}
98
-
89
return t6;
90
}
91
compiler/forget/src/__tests__/fixtures/hir/independent.expect.md
+10
-19
@@ -27,6 +27,16 @@ function Foo() {}
27
## Code
28
29
```javascript
30
+/**
31
+ * Should produce 3 scopes:
32
+ *
33
+ * a: inputs=props.a, outputs=a
34
+ * a = compute(props.a);
35
+ * b: inputs=props.b, outputs=b
36
+ * b = compute(props.b);
37
+ * return: inputs=a, b outputs=return
38
+ * return = <Foo a={a} b={b} />
39
+ */
40
function Component(props) {
41
const $ = React.useMemoCache();
42
const c_0 = $[0] !== props.a;
@@ -38,10 +48,8 @@ function Component(props) {
48
} else {
49
a = $[1];
50
}
41
-
51
const c_2 = $[2] !== props.b;
52
let b;
44
-
53
if (c_2) {
54
b = compute(props.b);
55
$[2] = props.b;
@@ -49,11 +57,9 @@ function Component(props) {
57
} else {
58
b = $[3];
59
}
52
-
60
const c_4 = $[4] !== a;
61
const c_5 = $[5] !== b;
62
let t6;
56
-
63
if (c_4 || c_5) {
64
t6 = <Foo a={a} b={b}></Foo>;
65
$[4] = a;
@@ -62,26 +68,11 @@ function Component(props) {
68
} else {
69
t6 = $[6];
70
}
65
-
71
return t6;
72
}
73
69
-```
70
-## Code
71
-
72
-```javascript
74
function compute() {}
74
-
75
-```
76
-## Code
77
-
78
-```javascript
75
function foo() {}
80
-
81
-```
82
-## Code
83
-
84
-```javascript
76
function Foo() {}
77
78
```
compiler/forget/src/__tests__/fixtures/hir/independently-memoize-object-property.expect.md
+1
-6
@@ -22,13 +22,10 @@ function foo(a, b, c) {
22
const c_2 = $[2] !== c;
23
let x;
24
if (c_0 || c_1 || c_2) {
25
- x = {
26
- a: a,
27
- };
25
+ x = { a: a };
26
const c_4 = $[4] !== b;
27
const c_5 = $[5] !== c;
28
let t6;
31
-
29
if (c_4 || c_5) {
30
t6 = [b, c];
31
$[4] = b;
@@ -37,7 +34,6 @@ function foo(a, b, c) {
34
} else {
35
t6 = $[6];
36
}
40
-
37
x.y = t6;
38
$[0] = a;
39
$[1] = b;
@@ -46,7 +42,6 @@ function foo(a, b, c) {
42
} else {
43
x = $[3];
44
}
49
-
45
return x;
46
}
47
compiler/forget/src/__tests__/fixtures/hir/infer-phi-primitive.expect.md
-2
@@ -26,7 +26,6 @@ function foo(a, b) {
26
let x$0;
27
if (c_0) {
28
x$0 = undefined;
29
-
29
if (a) {
30
const x$1 = 1;
31
x$0 = x$1;
@@ -34,7 +33,6 @@ function foo(a, b) {
33
const x$2 = 2;
34
x$0 = x$2;
35
}
37
-
36
$[0] = a;
37
$[1] = x$0;
38
} else {
compiler/forget/src/__tests__/fixtures/hir/interdependent-across-if.expect.md
+10
-19
@@ -31,23 +31,19 @@ function Component(props) {
31
32
```javascript
33
function compute() {}
34
-
35
-```
36
-## Code
37
-
38
-```javascript
34
function foo() {}
40
-
41
-```
42
-## Code
43
-
44
-```javascript
35
function Foo() {}
36
47
-```
48
-## Code
49
-
50
-```javascript
37
+/**
38
+ * Should produce 1 scope:
39
+ *
40
+ * return: inputs=props.a & props.b & props.c; outputs=return
41
+ * const a = compute(props.a);
42
+ * const b = compute(props.b);
43
+ * if (props.c)
44
+ * foo(a, b);
45
+ * return = <Foo a={a} b={b} />
46
+ */
47
function Component(props) {
48
const $ = React.useMemoCache();
49
const c_0 = $[0] !== props.a;
@@ -58,11 +54,9 @@ function Component(props) {
54
if (c_0 || c_1 || c_2) {
55
a = compute(props.a);
56
b = compute(props.b);
61
-
57
if (props.c) {
58
foo(a, b);
59
}
65
-
60
$[0] = props.a;
61
$[1] = props.b;
62
$[2] = props.c;
@@ -72,11 +66,9 @@ function Component(props) {
66
a = $[3];
67
b = $[4];
68
}
75
-
69
const c_5 = $[5] !== a;
70
const c_6 = $[6] !== b;
71
let t7;
79
-
72
if (c_5 || c_6) {
73
t7 = <Foo a={a} b={b}></Foo>;
74
$[5] = a;
@@ -85,7 +77,6 @@ function Component(props) {
77
} else {
78
t7 = $[7];
79
}
88
-
80
return t7;
81
}
82
compiler/forget/src/__tests__/fixtures/hir/interdependent.expect.md
+9
-17
@@ -27,6 +27,15 @@ function Foo() {}
27
## Code
28
29
```javascript
30
+/**
31
+ * Should produce 1 scope:
32
+ *
33
+ * return: inputs=props.a & props.b; outputs=return
34
+ * const a = compute(props.a);
35
+ * const b = compute(props.b);
36
+ * foo(a, b);
37
+ * return = <Foo a={a} b={b} />
38
+ */
39
function Component(props) {
40
const $ = React.useMemoCache();
41
const c_0 = $[0] !== props.a;
@@ -45,11 +54,9 @@ function Component(props) {
54
a = $[2];
55
b = $[3];
56
}
48
-
57
const c_4 = $[4] !== a;
58
const c_5 = $[5] !== b;
59
let t6;
52
-
60
if (c_4 || c_5) {
61
t6 = <Foo a={a} b={b}></Foo>;
62
$[4] = a;
@@ -58,26 +65,11 @@ function Component(props) {
65
} else {
66
t6 = $[6];
67
}
61
-
68
return t6;
69
}
70
65
-```
66
-## Code
67
-
68
-```javascript
71
function compute() {}
70
-
71
-```
72
-## Code
73
-
74
-```javascript
72
function foo() {}
76
-
77
-```
78
-## Code
79
-
80
-```javascript
73
function Foo() {}
74
75
```
compiler/forget/src/__tests__/fixtures/hir/inverted-if.expect.md
-3
@@ -28,7 +28,6 @@ function foo(a, b, c, d) {
28
let y;
29
if (c_0 || c_1 || c_2 || c_3) {
30
y = [];
31
-
31
bb1: if (a) {
32
if (b) {
33
y.push(c);
@@ -37,7 +36,6 @@ function foo(a, b, c, d) {
36
37
y.push(d);
38
}
40
-
39
$[0] = a;
40
$[1] = b;
41
$[2] = c;
@@ -46,7 +44,6 @@ function foo(a, b, c, d) {
44
} else {
45
y = $[4];
46
}
49
-
47
return y;
48
}
49
compiler/forget/src/__tests__/fixtures/hir/issue852.expect.md
+1
-4
@@ -19,16 +19,13 @@ function Component(c) {
19
const c_0 = $[0] !== c;
20
let x;
21
if (c_0) {
22
- x = {
23
- c: c,
24
- };
22
+ x = { c: c };
23
mutate(x);
24
$[0] = c;
25
$[1] = x;
26
} else {
27
x = $[1];
28
}
31
-
29
const a = x;
30
const b = a;
31
}
compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.expect.md
+1
-1
@@ -16,6 +16,7 @@ function MyApp(props) {
16
## Code
17
18
```javascript
19
+// This caused an infinite loop in the compiler
20
function MyApp(props) {
21
const $ = React.useMemoCache();
22
let y;
@@ -28,7 +29,6 @@ function MyApp(props) {
29
} else {
30
y = $[0];
31
}
31
-
32
return y;
33
}
34
compiler/forget/src/__tests__/fixtures/hir/jsx-fragment.expect.md
-5
@@ -27,10 +27,8 @@ function Foo(props) {
27
} else {
28
t0 = $[0];
29
}
30
-
30
const c_1 = $[1] !== t0;
31
let t2;
33
-
32
if (c_1) {
33
t2 = <div>{t0}</div>;
34
$[1] = t0;
@@ -38,11 +36,9 @@ function Foo(props) {
36
} else {
37
t2 = $[2];
38
}
41
-
39
const c_3 = $[3] !== props.greeting;
40
const c_4 = $[4] !== t2;
41
let t5;
45
-
42
if (c_3 || c_4) {
43
t5 = (
44
<>
@@ -56,7 +52,6 @@ function Foo(props) {
52
} else {
53
t5 = $[5];
54
}
59
-
55
return t5;
56
}
57
compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md
-38
@@ -31,41 +31,30 @@ function And() {
31
} else {
32
t0 = $[0];
33
}
34
-
34
const c_1 = $[1] !== t0;
35
let t2;
37
-
36
if (c_1) {
37
t2 = undefined;
40
-
38
if (t0) {
39
let t3;
43
-
40
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
41
t3 = g();
42
$[3] = t3;
43
} else {
44
t3 = $[3];
45
}
50
-
46
t2 = t3;
47
} else {
48
t2 = t0;
49
}
55
-
50
$[1] = t0;
51
$[2] = t2;
52
} else {
53
t2 = $[2];
54
}
61
-
55
return t2;
56
}
57
65
-```
66
-## Code
67
-
68
-```javascript
58
function Or() {
59
const $ = React.useMemoCache();
60
let t0;
@@ -75,41 +64,30 @@ function Or() {
64
} else {
65
t0 = $[0];
66
}
78
-
67
const c_1 = $[1] !== t0;
68
let t2;
81
-
69
if (c_1) {
70
t2 = undefined;
84
-
71
if (t0) {
72
t2 = t0;
73
} else {
74
let t3;
89
-
75
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
76
t3 = g();
77
$[3] = t3;
78
} else {
79
t3 = $[3];
80
}
96
-
81
t2 = t3;
82
}
99
-
83
$[1] = t0;
84
$[2] = t2;
85
} else {
86
t2 = $[2];
87
}
105
-
88
return t2;
89
}
90
109
-```
110
-## Code
111
-
112
-```javascript
91
function QuestionQuestion(props) {
92
const $ = React.useMemoCache();
93
let t0;
@@ -119,47 +97,31 @@ function QuestionQuestion(props) {
97
} else {
98
t0 = $[0];
99
}
122
-
100
const c_1 = $[1] !== t0;
101
let t2;
125
-
102
if (c_1) {
103
t2 = undefined;
128
-
104
if (t0 != null) {
105
t2 = t0;
106
} else {
107
let t3;
133
-
108
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
109
t3 = g();
110
$[3] = t3;
111
} else {
112
t3 = $[3];
113
}
140
-
114
t2 = t3;
115
}
143
-
116
$[1] = t0;
117
$[2] = t2;
118
} else {
119
t2 = $[2];
120
}
149
-
121
return t2;
122
}
123
153
-```
154
-## Code
155
-
156
-```javascript
124
function f() {}
158
-
159
-```
160
-## Code
161
-
162
-```javascript
125
function g() {}
126
127
```
compiler/forget/src/__tests__/fixtures/hir/method-call-computed.expect.md
-5
@@ -32,10 +32,8 @@ function foo(a, b, c) {
32
} else {
33
x = $[1];
34
}
35
-
35
const c_2 = $[2] !== a;
36
let y;
38
-
37
if (c_2) {
38
y = makeObject(a);
39
$[2] = a;
@@ -43,7 +41,6 @@ function foo(a, b, c) {
41
} else {
42
y = $[3];
43
}
46
-
44
<div>
45
{x}
46
{y}
@@ -52,7 +49,6 @@ function foo(a, b, c) {
49
const c_5 = $[5] !== y.method;
50
const c_6 = $[6] !== b;
51
let z;
55
-
52
if (c_4 || c_5 || c_6) {
53
z = x[y.method](b);
54
$[4] = x;
@@ -62,7 +58,6 @@ function foo(a, b, c) {
58
} else {
59
z = $[7];
60
}
65
-
61
return z;
62
}
63
compiler/forget/src/__tests__/fixtures/hir/method-call-fn-call.expect.md
+1
-3
@@ -29,14 +29,13 @@ function foo(a, b, c) {
29
} else {
30
x = $[1];
31
}
32
-
32
<div>{x}</div>;
33
+
34
const method = x.method;
35
const c_2 = $[2] !== method;
36
const c_3 = $[3] !== x;
37
const c_4 = $[4] !== b;
38
let y;
39
-
39
if (c_2 || c_3 || c_4) {
40
y = method.call(x, b);
41
$[2] = method;
@@ -46,7 +45,6 @@ function foo(a, b, c) {
45
} else {
46
y = $[5];
47
}
49
-
48
return y;
49
}
50
compiler/forget/src/__tests__/fixtures/hir/method-call.expect.md
-3
@@ -28,12 +28,10 @@ function foo(a, b, c) {
28
} else {
29
x = $[1];
30
}
31
-
31
<div>{x}</div>;
32
const c_2 = $[2] !== x;
33
const c_3 = $[3] !== b;
34
let y;
36
-
35
if (c_2 || c_3) {
36
y = x.foo(b);
37
$[2] = x;
@@ -42,7 +40,6 @@ function foo(a, b, c) {
40
} else {
41
y = $[4];
42
}
45
-
43
return y;
44
}
45
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-loops.expect.md
-14
@@ -43,17 +43,8 @@ function Component(props) {
43
44
```javascript
45
function mutate(x, y) {}
46
-
47
-```
48
-## Code
49
-
50
-```javascript
46
function cond(x) {}
47
53
-```
54
-## Code
55
-
56
-```javascript
48
function Component(props) {
49
let a = {};
50
let b = {};
@@ -74,21 +65,16 @@ function Component(props) {
65
b$1 = b;
66
c$2 = c;
67
d$3 = d;
77
-
68
if (cond(a)) {
69
break;
70
}
71
}
82
-
72
if (a$0) {
73
}
85
-
74
if (b$1) {
75
}
88
-
76
if (c$2) {
77
}
91
-
78
if (d$3) {
79
}
80
compiler/forget/src/__tests__/fixtures/hir/mutable-lifetime-with-aliasing.expect.md
+3
-11
@@ -40,32 +40,24 @@ function Component(props) {
40
```javascript
41
function mutate(x, y) {}
42
43
-```
44
-## Code
45
-
46
-```javascript
43
function Component(props) {
44
const a = {};
45
const b = [a];
46
const c = {};
51
- const d = {
52
- c: c,
53
- };
47
+ const d = { c: c };
48
+
49
const x = {};
50
x.b = b;
51
+
52
const y = mutate(x, d);
53
if (a) {
54
}
59
-
55
if (b) {
56
}
62
-
57
if (c) {
58
}
65
-
59
if (d) {
60
}
68
-
61
if (y) {
62
}
63
compiler/forget/src/__tests__/fixtures/hir/mutable-liverange-loop.expect.md
-16
@@ -38,17 +38,8 @@ function Component(props) {
38
39
```javascript
40
function mutate() {}
41
-
42
-```
43
-## Code
44
-
45
-```javascript
41
function cond() {}
42
48
-```
49
-## Code
50
-
51
-```javascript
43
function Component(props) {
44
const $ = React.useMemoCache();
45
const a = {};
@@ -60,26 +51,19 @@ function Component(props) {
51
} else {
52
c = $[0];
53
}
63
-
54
const d = {};
65
-
55
while (true) {
56
mutate(a, b);
68
-
57
if (cond(a)) {
58
break;
59
}
60
}
73
-
61
if (a) {
62
}
76
-
63
if (b) {
64
}
79
-
65
if (c) {
66
}
82
-
67
if (d) {
68
}
69
compiler/forget/src/__tests__/fixtures/hir/obj-literal-cached-in-if-else.expect.md
+2
-13
@@ -26,46 +26,35 @@ function foo(a, b, c, d) {
26
let x$0;
27
if (c_0 || c_1) {
28
x$0 = undefined;
29
-
29
if (someVal) {
30
const c_3 = $[3] !== b;
31
let x$1;
33
-
32
if (c_3) {
35
- x$1 = {
36
- b: b,
37
- };
33
+ x$1 = { b: b };
34
$[3] = b;
35
$[4] = x$1;
36
} else {
37
x$1 = $[4];
38
}
43
-
39
x$0 = x$1;
40
} else {
41
const c_5 = $[5] !== c;
42
let x$2;
48
-
43
if (c_5) {
50
- x$2 = {
51
- c: c,
52
- };
44
+ x$2 = { c: c };
45
$[5] = c;
46
$[6] = x$2;
47
} else {
48
x$2 = $[6];
49
}
58
-
50
x$0 = x$2;
51
}
61
-
52
$[0] = b;
53
$[1] = c;
54
$[2] = x$0;
55
} else {
56
x$0 = $[2];
57
}
68
-
58
return x$0;
59
}
60
compiler/forget/src/__tests__/fixtures/hir/obj-literal-mutated-after-if-else.expect.md
+2
-9
@@ -27,19 +27,13 @@ function foo(a, b, c, d) {
27
let x$0;
28
if (c_0 || c_1) {
29
x$0 = undefined;
30
-
30
if (someVal) {
32
- const x$1 = {
33
- b: b,
34
- };
31
+ const x$1 = { b: b };
32
x$0 = x$1;
33
} else {
37
- const x$2 = {
38
- c: c,
39
- };
34
+ const x$2 = { c: c };
35
x$0 = x$2;
36
}
42
-
37
x$0.f = 1;
38
$[0] = b;
39
$[1] = c;
@@ -47,7 +41,6 @@ function foo(a, b, c, d) {
41
} else {
42
x$0 = $[2];
43
}
50
-
44
return x$0;
45
}
46
compiler/forget/src/__tests__/fixtures/hir/obj-mutated-after-if-else.expect.md
-3
@@ -26,7 +26,6 @@ function foo(a, b, c, d) {
26
let x$0;
27
if (c_0) {
28
x$0 = undefined;
29
-
29
if (a) {
30
const x$1 = someObj();
31
x$0 = x$1;
@@ -34,14 +33,12 @@ function foo(a, b, c, d) {
33
const x$2 = someObj();
34
x$0 = x$2;
35
}
37
-
36
x$0.f = 1;
37
$[0] = a;
38
$[1] = x$0;
39
} else {
40
x$0 = $[1];
41
}
44
-
42
return x$0;
43
}
44
compiler/forget/src/__tests__/fixtures/hir/object-properties.expect.md
+1
@@ -19,6 +19,7 @@ function foo(a, b, c) {
19
const x = a.x;
20
const y = b.c.d;
21
y.z = c.d.e;
22
+
23
foo(a.b.c);
24
[a.b.c];
25
}
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-shadowing-within-block.expect.md
-9
@@ -28,29 +28,23 @@ function foo(a, b, c) {
28
let x;
29
if (c_0 || c_1 || c_2) {
30
x = [];
31
-
31
if (a) {
32
const c_4 = $[4] !== b;
33
const c_5 = $[5] !== c;
34
let y;
36
-
35
if (c_4 || c_5) {
36
y = [];
39
-
37
if (b) {
38
y.push(c);
39
}
43
-
40
$[4] = b;
41
$[5] = c;
42
$[6] = y;
43
} else {
44
y = $[6];
45
}
50
-
46
const c_7 = $[7] !== y;
47
let t8;
53
-
48
if (c_7) {
49
t8 = <div>{y}</div>;
50
$[7] = y;
@@ -58,10 +52,8 @@ function foo(a, b, c) {
52
} else {
53
t8 = $[8];
54
}
61
-
55
x.push(t8);
56
}
64
-
57
$[0] = a;
58
$[1] = b;
59
$[2] = c;
@@ -69,7 +61,6 @@ function foo(a, b, c) {
61
} else {
62
x = $[3];
63
}
72
-
64
return x;
65
}
66
compiler/forget/src/__tests__/fixtures/hir/overlapping-scopes-within-block.expect.md
-4
@@ -28,17 +28,14 @@ function foo(a, b, c) {
28
let x;
29
if (c_0 || c_1 || c_2) {
30
x = [];
31
-
31
if (a) {
32
const y = [];
34
-
33
if (b) {
34
y.push(c);
35
}
36
37
x.push(y);
38
}
41
-
39
$[0] = a;
40
$[1] = b;
41
$[2] = c;
@@ -46,7 +43,6 @@ function foo(a, b, c) {
43
} else {
44
x = $[3];
45
}
49
-
46
return x;
47
}
48
compiler/forget/src/__tests__/fixtures/hir/primitive-alias-mutate.expect.md
-2
@@ -26,7 +26,6 @@ function component(a) {
26
let x$0;
27
if (c_0) {
28
x$0 = undefined;
29
-
29
if (a) {
30
const x$1 = "bar";
31
x$0 = x$1;
@@ -34,7 +33,6 @@ function component(a) {
33
const x$2 = "baz";
34
x$0 = x$2;
35
}
37
-
36
$[0] = a;
37
$[1] = x$0;
38
} else {
compiler/forget/src/__tests__/fixtures/hir/prop-capturing-function-1.expect.md
+1
-8
@@ -21,31 +21,24 @@ function component(a, b) {
21
const c_1 = $[1] !== b;
22
let z;
23
if (c_0 || c_1) {
24
- z = {
25
- a: a,
26
- b: b,
27
- };
24
+ z = { a: a, b: b };
25
$[0] = a;
26
$[1] = b;
27
$[2] = z;
28
} else {
29
z = $[2];
30
}
34
-
31
const c_3 = $[3] !== z;
32
let x;
37
-
33
if (c_3) {
34
x = function () {
35
z;
36
};
42
-
37
$[3] = z;
38
$[4] = x;
39
} else {
40
x = $[4];
41
}
48
-
42
return x;
43
}
44
compiler/forget/src/__tests__/fixtures/hir/property-assignment.expect.md
+1
-3
@@ -25,6 +25,7 @@ function Component(props) {
25
x = {};
26
const y = [];
27
x.y = y;
28
+
29
child = <Component data={y}></Component>;
30
x.y.push(props.p0);
31
$[0] = props.p0;
@@ -34,11 +35,9 @@ function Component(props) {
35
x = $[1];
36
child = $[2];
37
}
37
-
38
const c_3 = $[3] !== x;
39
const c_4 = $[4] !== child;
40
let t5;
41
-
41
if (c_3 || c_4) {
42
t5 = <Component data={x}>{child}</Component>;
43
$[3] = x;
@@ -47,7 +46,6 @@ function Component(props) {
46
} else {
47
t5 = $[5];
48
}
50
-
49
return t5;
50
}
51
compiler/forget/src/__tests__/fixtures/hir/reactive-scope-grouping.expect.md
-3
@@ -23,7 +23,6 @@ function foo() {
23
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
24
x = {};
25
let y;
26
-
26
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
27
y = [];
28
const z = {};
@@ -32,13 +31,11 @@ function foo() {
31
} else {
32
y = $[1];
33
}
35
-
34
x.y = y;
35
$[0] = x;
36
} else {
37
x = $[0];
38
}
41
-
39
return x;
40
}
41
compiler/forget/src/__tests__/fixtures/hir/reactive-scopes-if.expect.md
-7
@@ -27,11 +27,9 @@ function foo(a, b, c) {
27
let x;
28
if (c_0 || c_1 || c_2) {
29
x = [];
30
-
30
if (a) {
31
const c_4 = $[4] !== b;
32
let y;
34
-
33
if (c_4) {
34
y = [];
35
y.push(b);
@@ -40,10 +38,8 @@ function foo(a, b, c) {
38
} else {
39
y = $[5];
40
}
43
-
41
const c_6 = $[6] !== y;
42
let t7;
46
-
43
if (c_6) {
44
t7 = <div>{y}</div>;
45
$[6] = y;
@@ -51,12 +47,10 @@ function foo(a, b, c) {
47
} else {
48
t7 = $[7];
49
}
54
-
50
x.push(t7);
51
} else {
52
x.push(c);
53
}
59
-
54
$[0] = a;
55
$[1] = b;
56
$[2] = c;
@@ -64,7 +58,6 @@ function foo(a, b, c) {
58
} else {
59
x = $[3];
60
}
67
-
61
return x;
62
}
63
compiler/forget/src/__tests__/fixtures/hir/reactive-scopes.expect.md
-5
@@ -25,23 +25,19 @@ function f(a, b) {
25
let x;
26
if (c_0 || c_1) {
27
x = [];
28
-
28
if (a.length === 1) {
29
if (b) {
30
x.push(b);
31
}
32
}
34
-
33
$[0] = a.length;
34
$[1] = b;
35
$[2] = x;
36
} else {
37
x = $[2];
38
}
41
-
39
const c_3 = $[3] !== x;
40
let t4;
44
-
41
if (c_3) {
42
t4 = <div>{x}</div>;
43
$[3] = x;
@@ -49,7 +45,6 @@ function f(a, b) {
45
} else {
46
t4 = $[4];
47
}
52
-
48
return t4;
49
}
50
compiler/forget/src/__tests__/fixtures/hir/reassignment-conditional.expect.md
-9
@@ -34,27 +34,21 @@ function Component(props) {
34
} else {
35
x = $[1];
36
}
37
-
37
const y = x;
38
const c_2 = $[2] !== props.p1;
39
let x$0;
41
-
40
if (c_2) {
41
x$0 = x;
44
-
42
if (props.p1) {
43
let x$1;
47
-
44
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
45
x$1 = [];
46
$[4] = x$1;
47
} else {
48
x$1 = $[4];
49
}
54
-
50
x$0 = x$1;
51
}
57
-
52
$[2] = props.p1;
53
$[3] = x$0;
54
} else {
@@ -62,12 +56,10 @@ function Component(props) {
56
}
57
58
const _ = <Component x={x$0}></Component>;
65
-
59
y.push(props.p2);
60
const c_5 = $[5] !== x$0;
61
const c_6 = $[6] !== y;
62
let t7;
70
-
63
if (c_5 || c_6) {
64
t7 = <Component x={x$0} y={y}></Component>;
65
$[5] = x$0;
@@ -76,7 +68,6 @@ function Component(props) {
68
} else {
69
t7 = $[7];
70
}
79
-
71
return t7;
72
}
73
compiler/forget/src/__tests__/fixtures/hir/reassignment-separate-scopes.expect.md
-16
@@ -39,20 +39,16 @@ function foo(a, b, c) {
39
let x;
40
if (c_0) {
41
x = [];
42
-
42
if (a) {
43
x.push(a);
44
}
46
-
45
$[0] = a;
46
$[1] = x;
47
} else {
48
x = $[1];
49
}
52
-
50
const c_2 = $[2] !== x;
51
let y;
55
-
52
if (c_2) {
53
y = <div>{x}</div>;
54
$[2] = x;
@@ -60,19 +56,15 @@ function foo(a, b, c) {
56
} else {
57
y = $[3];
58
}
63
-
59
const c_4 = $[4] !== b;
60
const c_5 = $[5] !== c;
61
let x$0;
67
-
62
if (c_4 || c_5) {
63
x$0 = undefined;
70
-
64
bb3: switch (b) {
65
case 0: {
66
const c_7 = $[7] !== b;
67
let x$1;
75
-
68
if (c_7) {
69
x$1 = [];
70
x$1.push(b);
@@ -81,15 +73,12 @@ function foo(a, b, c) {
73
} else {
74
x$1 = $[8];
75
}
84
-
76
x$0 = x$1;
77
break bb3;
78
}
88
-
79
default: {
80
const c_9 = $[9] !== c;
81
let x$2;
92
-
82
if (c_9) {
83
x$2 = [];
84
x$2.push(c);
@@ -98,22 +87,18 @@ function foo(a, b, c) {
87
} else {
88
x$2 = $[10];
89
}
101
-
90
x$0 = x$2;
91
}
92
}
105
-
93
$[4] = b;
94
$[5] = c;
95
$[6] = x$0;
96
} else {
97
x$0 = $[6];
98
}
112
-
99
const c_11 = $[11] !== y;
100
const c_12 = $[12] !== x$0;
101
let t13;
116
-
102
if (c_11 || c_12) {
103
t13 = (
104
<div>
@@ -127,7 +112,6 @@ function foo(a, b, c) {
112
} else {
113
t13 = $[13];
114
}
130
-
115
return t13;
116
}
117
compiler/forget/src/__tests__/fixtures/hir/reassignment.expect.md
-5
@@ -30,14 +30,12 @@ function Component(props) {
30
x.push(props.p0);
31
y = x;
32
let x$0;
33
-
33
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
34
x$0 = [];
35
$[3] = x$0;
36
} else {
37
x$0 = $[3];
38
}
40
-
39
const _ = <Component x={x$0}></Component>;
40
41
y.push(props.p1);
@@ -47,11 +45,9 @@ function Component(props) {
45
} else {
46
y = $[2];
47
}
50
-
48
const c_4 = $[4] !== x$0;
49
const c_5 = $[5] !== y;
50
let t6;
54
-
51
if (c_4 || c_5) {
52
t6 = <Component x={x$0} y={y}></Component>;
53
$[4] = x$0;
@@ -60,7 +56,6 @@ function Component(props) {
56
} else {
57
t6 = $[6];
58
}
63
-
59
return t6;
60
}
61
compiler/forget/src/__tests__/fixtures/hir/reverse-postorder.expect.md
-6
@@ -49,7 +49,6 @@ function Component(props) {
49
let x$0;
50
if (c_0 || c_1 || c_2 || c_3 || c_4 || c_5 || c_6 || c_7) {
51
x$0 = undefined;
52
-
52
bb1: if (props.cond) {
53
switch (props.test) {
54
case 0: {
@@ -57,16 +56,13 @@ function Component(props) {
56
x$0 = x$1;
57
break bb1;
58
}
60
-
59
case 1: {
60
const x$2 = props.v1;
61
x$0 = x$2;
62
break bb1;
63
}
66
-
64
case 2: {
65
}
69
-
66
default: {
67
const x$3 = props.v2;
68
x$0 = x$3;
@@ -81,7 +77,6 @@ function Component(props) {
77
x$0 = x$5;
78
}
79
}
84
-
80
$[0] = props.cond;
81
$[1] = props.test;
82
$[2] = props.v0;
@@ -94,7 +89,6 @@ function Component(props) {
89
} else {
90
x$0 = $[8];
91
}
97
-
92
x$0;
93
}
94
compiler/forget/src/__tests__/fixtures/hir/simple-alias.expect.md
-6
@@ -20,11 +20,6 @@ function foo() {
20
21
```javascript
22
function mutate() {}
23
-
24
-```
25
-## Code
26
-
27
-```javascript
23
function foo() {
24
const $ = React.useMemoCache();
25
const a = {};
@@ -40,7 +35,6 @@ function foo() {
35
} else {
36
c$2 = $[0];
37
}
43
-
38
return c$2;
39
}
40
compiler/forget/src/__tests__/fixtures/hir/simple-function-1.expect.md
-2
@@ -21,12 +21,10 @@ function component() {
21
x = function (a) {
22
a.foo();
23
};
24
-
24
$[0] = x;
25
} else {
26
x = $[0];
27
}
29
-
28
return x;
29
}
30
compiler/forget/src/__tests__/fixtures/hir/simple-scope.expect.md
-1
@@ -23,7 +23,6 @@ function foo(a) {
23
} else {
24
x = $[1];
25
}
26
-
26
return x;
27
}
28
compiler/forget/src/__tests__/fixtures/hir/simple.expect.md
-5
@@ -19,7 +19,6 @@ function foo(x, y) {
19
if (x) {
20
const c_0 = $[0] !== y;
21
let t1;
22
-
22
if (c_0) {
23
t1 = foo(false, y);
24
$[0] = y;
@@ -27,19 +26,15 @@ function foo(x, y) {
26
} else {
27
t1 = $[1];
28
}
30
-
29
return t1;
30
}
33
-
31
let t2;
35
-
32
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
33
t2 = [y * 10];
34
$[2] = t2;
35
} else {
36
t2 = $[2];
37
}
42
-
38
return t2;
39
}
40
compiler/forget/src/__tests__/fixtures/hir/ssa-arrayexpression.expect.md
-1
@@ -25,7 +25,6 @@ function Component(props) {
25
} else {
26
x = $[0];
27
}
28
-
28
return x;
29
}
30
compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx-2.expect.md
+1
-9
@@ -21,12 +21,9 @@ function Component(props) {
21
## Code
22
23
```javascript
24
+// @Pass runMutableRangeAnalysis
25
function foo() {}
26
26
-```
27
-## Code
28
-
29
-```javascript
27
function Component(props) {
28
const $ = React.useMemoCache();
29
let a;
@@ -36,14 +33,12 @@ function Component(props) {
33
b = {};
34
foo(a, b);
35
let t2;
39
-
36
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
37
t2 = foo();
38
$[2] = t2;
39
} else {
40
t2 = $[2];
41
}
46
-
42
if (t2) {
43
const _ = <div a={a}></div>;
44
}
@@ -55,11 +50,9 @@ function Component(props) {
50
a = $[0];
51
b = $[1];
52
}
58
-
53
const c_3 = $[3] !== a;
54
const c_4 = $[4] !== b;
55
let t5;
62
-
56
if (c_3 || c_4) {
57
t5 = <div a={a} b={b}></div>;
58
$[3] = a;
@@ -68,7 +61,6 @@ function Component(props) {
61
} else {
62
t5 = $[5];
63
}
71
-
64
return t5;
65
}
66
compiler/forget/src/__tests__/fixtures/hir/ssa-call-jsx.expect.md
-9
@@ -20,10 +20,6 @@ function Component(props) {
20
```javascript
21
function foo() {}
22
23
-```
24
-## Code
25
-
26
-```javascript
23
function Component(props) {
24
const $ = React.useMemoCache();
25
let a;
@@ -32,9 +28,7 @@ function Component(props) {
28
a = [];
29
b = {};
30
foo(a, b);
35
-
31
const _ = <div a={a}></div>;
37
-
32
foo(a, b);
33
$[0] = a;
34
$[1] = b;
@@ -42,11 +36,9 @@ function Component(props) {
36
a = $[0];
37
b = $[1];
38
}
45
-
39
const c_2 = $[2] !== a;
40
const c_3 = $[3] !== b;
41
let t4;
49
-
42
if (c_2 || c_3) {
43
t4 = <div a={a} b={b}></div>;
44
$[2] = a;
@@ -55,7 +47,6 @@ function Component(props) {
47
} else {
48
t4 = $[4];
49
}
58
-
50
return t4;
51
}
52
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-multiple-if.expect.md
+2
@@ -25,9 +25,11 @@ function foo() {
25
const y = 2;
26
2;
27
true;
28
+
29
const x$0 = 3;
30
3;
31
false;
32
+
33
const y$1 = x$0;
34
}
35
compiler/forget/src/__tests__/fixtures/hir/ssa-complex-single-if.expect.md
+2
@@ -22,7 +22,9 @@ function foo() {
22
const y = 2;
23
2;
24
true;
25
+
26
const x$0 = 3;
27
+
28
const y$1 = x$0;
29
}
30
compiler/forget/src/__tests__/fixtures/hir/ssa-for-trivial-update.expect.md
-3
@@ -20,16 +20,13 @@ function foo() {
20
let x;
21
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
22
x = 1;
23
-
23
for (const i = 0; 10, true; 0) {
24
x = x + 1;
25
}
27
-
26
$[0] = x;
27
} else {
28
x = $[0];
29
}
32
-
30
return x;
31
}
32
compiler/forget/src/__tests__/fixtures/hir/ssa-for.expect.md
-3
@@ -20,16 +20,13 @@ function foo() {
20
let x;
21
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
22
x = 1;
23
-
23
for (let i = 0; i < 10; i = i + 1, i) {
24
x = x + 1;
25
}
27
-
26
$[0] = x;
27
} else {
28
x = $[0];
29
}
32
-
30
return x;
31
}
32
compiler/forget/src/__tests__/fixtures/hir/ssa-if-else.expect.md
+1
@@ -21,6 +21,7 @@ function foo() {
21
function foo() {
22
const x = 1;
23
const y = 2;
24
+
25
const z = 3;
26
}
27
compiler/forget/src/__tests__/fixtures/hir/ssa-multiple-phis.expect.md
+1
@@ -31,6 +31,7 @@ function foo(a, b, c, d) {
31
const x = 0;
32
true;
33
true;
34
+
35
const x$0 = a;
36
x$0;
37
return x$0;
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-loops-no-reassign.expect.md
+1
-1
@@ -20,6 +20,7 @@ function foo(a, b, c) {
20
## Code
21
22
```javascript
23
+// @xonly
24
function foo(a, b, c) {
25
const x = 0;
26
while (a) {
@@ -30,7 +31,6 @@ function foo(a, b, c) {
31
}
32
}
33
}
33
-
34
return x;
35
}
36
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-phi.expect.md
-4
@@ -23,21 +23,17 @@ function foo(a, b, c) {
23
if (b) {
24
const c_0 = $[0] !== c;
25
let x$0;
26
-
26
if (c_0) {
27
x$0 = x;
29
-
28
if (c) {
29
const x$1 = c;
30
x$0 = x$1;
31
}
34
-
32
$[0] = c;
33
$[1] = x$0;
34
} else {
35
x$0 = $[1];
36
}
40
-
37
x$0;
38
}
39
}
compiler/forget/src/__tests__/fixtures/hir/ssa-nested-partial-reassignment.expect.md
-3
@@ -29,7 +29,6 @@ function foo(a, b, c, d, e) {
29
let x$0;
30
if (c_0 || c_1 || c_2 || c_3) {
31
x$0 = x;
32
-
32
if (a) {
33
const x$1 = b;
34
x$0 = x$1;
@@ -39,7 +38,6 @@ function foo(a, b, c, d, e) {
38
x$0 = x$2;
39
}
40
}
42
-
41
$[0] = a;
42
$[1] = b;
43
$[2] = c;
@@ -48,7 +46,6 @@ function foo(a, b, c, d, e) {
46
} else {
47
x$0 = $[4];
48
}
51
-
49
return x$0;
50
}
51
compiler/forget/src/__tests__/fixtures/hir/ssa-newexpression.expect.md
-5
@@ -18,10 +18,6 @@ function Component(props) {
18
```javascript
19
function Foo() {}
20
21
-```
22
-## Code
23
-
24
-```javascript
21
function Component(props) {
22
const $ = React.useMemoCache();
23
let c;
@@ -33,7 +29,6 @@ function Component(props) {
29
} else {
30
c = $[0];
31
}
36
-
32
return c;
33
}
34
compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression-phi.expect.md
+2
-5
@@ -27,18 +27,15 @@ function foo() {
27
const y = 2;
28
1;
29
false;
30
+
31
const y$0 = 3;
32
let t;
33
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
33
- t = {
34
- x: x,
35
- y: y$0,
36
- };
34
+ t = { x: x, y: y$0 };
35
$[0] = t;
36
} else {
37
t = $[0];
38
}
41
-
39
return t;
40
}
41
compiler/forget/src/__tests__/fixtures/hir/ssa-objectexpression.expect.md
+1
-5
@@ -20,15 +20,11 @@ function Component(props) {
20
const b = 2;
21
let x;
22
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
23
- x = {
24
- a: a,
25
- b: b,
26
- };
23
+ x = { a: a, b: b };
24
$[0] = x;
25
} else {
26
x = $[0];
27
}
31
-
28
return x;
29
}
30
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-alias-mutate-if.expect.md
-2
@@ -28,7 +28,6 @@ function foo(a) {
28
if (c_0) {
29
const b = {};
30
x = b;
31
-
31
if (a) {
32
const y = {};
33
x.y = y;
@@ -43,7 +42,6 @@ function foo(a) {
42
} else {
43
x = $[1];
44
}
46
-
45
return x;
46
}
47
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-if.expect.md
-7
@@ -25,37 +25,30 @@ function foo(a) {
25
let x;
26
if (c_0) {
27
x = {};
28
-
28
if (a) {
29
let y;
31
-
30
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
31
y = {};
32
$[2] = y;
33
} else {
34
y = $[2];
35
}
38
-
36
x.y = y;
37
} else {
38
let z;
42
-
39
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
40
z = {};
41
$[3] = z;
42
} else {
43
z = $[3];
44
}
49
-
45
x.z = z;
46
}
52
-
47
$[0] = a;
48
$[1] = x;
49
} else {
50
x = $[1];
51
}
58
-
52
return x;
53
}
54
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-if.expect.md
-2
@@ -26,7 +26,6 @@ function foo(a) {
26
let x;
27
if (c_0) {
28
x = {};
29
-
29
if (a) {
30
const y = {};
31
x.y = y;
@@ -41,7 +40,6 @@ function foo(a) {
40
} else {
41
x = $[1];
42
}
44
-
43
return x;
44
}
45
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate-inside-if.expect.md
+1
-5
@@ -26,30 +26,26 @@ function foo(a) {
26
let x;
27
if (c_0) {
28
x = {};
29
-
29
if (a) {
30
const y = {};
31
x.y = y;
32
+
33
mutate(y);
34
} else {
35
let z;
36
-
36
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
37
z = {};
38
$[2] = z;
39
} else {
40
z = $[2];
41
}
43
-
42
x.z = z;
43
}
46
-
44
$[0] = a;
45
$[1] = x;
46
} else {
47
x = $[1];
48
}
52
-
49
return x;
50
}
51
compiler/forget/src/__tests__/fixtures/hir/ssa-property-alias-mutate.expect.md
+2
-1
@@ -24,14 +24,15 @@ function foo() {
24
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
25
const a = {};
26
const x = a;
27
+
28
y = {};
29
y.x = x;
30
+
31
mutate(a);
32
$[0] = y;
33
} else {
34
y = $[0];
35
}
34
-
36
return y;
37
}
38
compiler/forget/src/__tests__/fixtures/hir/ssa-property-call.expect.md
+1
-4
@@ -19,15 +19,12 @@ function foo() {
19
let y;
20
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
21
const x = [];
22
- y = {
23
- x: x,
24
- };
22
+ y = { x: x };
23
y.x.push([]);
24
$[0] = y;
25
} else {
26
y = $[0];
27
}
30
-
28
return y;
29
}
30
compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-2.expect.md
+1
-1
@@ -22,12 +22,12 @@ function foo() {
22
const x = [];
23
y = {};
24
y.x = x;
25
+
26
mutate(x);
27
$[0] = y;
28
} else {
29
y = $[0];
30
}
30
-
31
return y;
32
}
33
compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate-alias.expect.md
+1
-1
@@ -26,12 +26,12 @@ function foo() {
26
y = a;
27
const x = [];
28
y.x = x;
29
+
30
mutate(a);
31
$[0] = y;
32
} else {
33
y = $[0];
34
}
34
-
35
return y;
36
}
37
compiler/forget/src/__tests__/fixtures/hir/ssa-property-mutate.expect.md
+1
-1
@@ -22,12 +22,12 @@ function foo() {
22
const x = [];
23
y = {};
24
y.x = x;
25
+
26
mutate(y);
27
$[0] = y;
28
} else {
29
y = $[0];
30
}
30
-
31
return y;
32
}
33
compiler/forget/src/__tests__/fixtures/hir/ssa-property.expect.md
-3
@@ -23,10 +23,8 @@ function foo() {
23
} else {
24
x = $[0];
25
}
26
-
26
const c_1 = $[1] !== x;
27
let y;
29
-
28
if (c_1) {
29
y = {};
30
y.x = x;
@@ -35,7 +33,6 @@ function foo() {
33
} else {
34
y = $[2];
35
}
38
-
36
return y;
37
}
38
compiler/forget/src/__tests__/fixtures/hir/ssa-return.expect.md
+1
@@ -20,6 +20,7 @@ function foo() {
20
const x = 1;
21
1;
22
true;
23
+
24
const x$0 = 2;
25
return x$0;
26
}
compiler/forget/src/__tests__/fixtures/hir/ssa-shadowing.expect.md
-6
@@ -22,10 +22,6 @@ function Foo(cond) {
22
```javascript
23
function log() {}
24
25
-```
26
-## Code
27
-
28
-```javascript
25
function Foo(cond) {
26
const $ = React.useMemoCache();
27
const str = "";
@@ -33,7 +29,6 @@ function Foo(cond) {
29
let str$0;
30
if (c_0) {
31
str$0 = str;
36
-
32
if (cond) {
33
const str_0 = "other test";
34
log(str_0);
@@ -41,7 +36,6 @@ function Foo(cond) {
36
const str$1 = "fallthrough test";
37
str$0 = str$1;
38
}
44
-
39
$[0] = cond;
40
$[1] = str$0;
41
} else {
compiler/forget/src/__tests__/fixtures/hir/ssa-sibling-phis.expect.md
+1
@@ -31,6 +31,7 @@ function foo(a, b, c, d) {
31
const x = 0;
32
true;
33
true;
34
+
35
const x$0 = a;
36
x$0;
37
}
compiler/forget/src/__tests__/fixtures/hir/ssa-simple-phi.expect.md
+2
@@ -23,7 +23,9 @@ function foo() {
23
const y = 2;
24
1;
25
true;
26
+
27
const y$0 = 1;
28
+
29
const x = y$0;
30
}
31
compiler/forget/src/__tests__/fixtures/hir/ssa-single-if.expect.md
+1
@@ -19,6 +19,7 @@ function foo() {
19
function foo() {
20
const x = 1;
21
const y = 2;
22
+
23
const z = 3;
24
}
25
compiler/forget/src/__tests__/fixtures/hir/ssa-switch.expect.md
+3
-4
@@ -35,29 +35,28 @@ function foo() {
35
let x$0;
36
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
37
x$0 = undefined;
38
-
38
bb1: switch (x) {
39
case true: {
40
1;
41
+
42
const x$1 = 2;
43
x$0 = x$1;
44
break bb1;
45
}
46
-
46
case false: {
47
2;
48
+
49
const x$2 = 3;
50
x$0 = x$2;
51
break bb1;
52
}
53
-
53
default: {
54
3;
55
+
56
const x$3 = 4;
57
x$0 = x$3;
58
}
59
}
60
-
60
$[0] = x$0;
61
} else {
62
x$0 = $[0];
compiler/forget/src/__tests__/fixtures/hir/ssa-throw.expect.md
+1
@@ -19,6 +19,7 @@ function foo() {
19
const x = 1;
20
1;
21
true;
22
+
23
const x$0 = 2;
24
throw x$0;
25
}
compiler/forget/src/__tests__/fixtures/hir/ssa-while-no-reassign.expect.md
-1
@@ -22,7 +22,6 @@ function foo() {
22
1;
23
2;
24
}
25
-
25
return x;
26
}
27
compiler/forget/src/__tests__/fixtures/hir/ssa-while.expect.md
-3
@@ -21,16 +21,13 @@ function foo() {
21
let x;
22
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
23
x = 1;
24
-
24
while (x < 10) {
25
x = x + 1;
26
}
28
-
27
$[0] = x;
28
} else {
29
x = $[0];
30
}
33
-
31
return x;
32
}
33
compiler/forget/src/__tests__/fixtures/hir/store-via-call.expect.md
-1
@@ -25,7 +25,6 @@ function foo() {
25
} else {
26
x = $[0];
27
}
28
-
28
return x;
29
}
30
compiler/forget/src/__tests__/fixtures/hir/store-via-new.expect.md
-1
@@ -25,7 +25,6 @@ function Foo() {
25
} else {
26
x = $[0];
27
}
28
-
28
return x;
29
}
30
compiler/forget/src/__tests__/fixtures/hir/switch-non-final-default.expect.md
-12
@@ -40,47 +40,38 @@ function Component(props) {
40
x = [];
41
const y = undefined;
42
let y$0 = y;
43
-
43
bb1: switch (props.p0) {
44
case 1: {
45
break bb1;
46
}
48
-
47
case true: {
48
x.push(props.p2);
49
let y$1;
52
-
50
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
51
y$1 = [];
52
$[3] = y$1;
53
} else {
54
y$1 = $[3];
55
}
59
-
56
y$0 = y$1;
57
break bb1;
58
}
63
-
59
default: {
60
break bb1;
61
}
67
-
62
case false: {
63
const y$2 = x;
64
y$0 = y$2;
65
}
66
}
73
-
67
$[0] = props.p0;
68
$[1] = props.p2;
69
$[2] = x;
70
} else {
71
x = $[2];
72
}
80
-
73
const c_4 = $[4] !== x;
74
let child;
83
-
75
if (c_4) {
76
child = <Component data={x}></Component>;
77
$[4] = x;
@@ -88,12 +79,10 @@ function Component(props) {
79
} else {
80
child = $[5];
81
}
91
-
82
y$0.push(props.p4);
83
const c_6 = $[6] !== y$0;
84
const c_7 = $[7] !== child;
85
let t8;
96
-
86
if (c_6 || c_7) {
87
t8 = <Component data={y$0}>{child}</Component>;
88
$[6] = y$0;
@@ -102,7 +91,6 @@ function Component(props) {
91
} else {
92
t8 = $[8];
93
}
105
-
94
return t8;
95
}
96
compiler/forget/src/__tests__/fixtures/hir/switch-with-fallthrough.expect.md
-6
@@ -41,29 +41,23 @@ function foo(x) {
41
case 0: {
42
const y$0 = 0;
43
}
44
-
44
case 1: {
45
const y$1 = 1;
46
break bb1;
47
}
49
-
48
case 2: {
49
break bb1;
50
}
53
-
51
case 3: {
52
const y$2 = 3;
53
break bb1;
54
}
58
-
55
case 4: {
56
const y$3 = 4;
57
}
62
-
58
case 5: {
59
const y$4 = 5;
60
}
66
-
61
default: {
62
const y$5 = 0;
63
}
compiler/forget/src/__tests__/fixtures/hir/switch.expect.md
-8
@@ -36,20 +36,17 @@ function Component(props) {
36
x = [];
37
const y = undefined;
38
let y$0 = y;
39
-
39
switch (props.p0) {
40
case true: {
41
x.push(props.p2);
42
x.push(props.p3);
43
const y$1 = [];
44
}
46
-
45
case false: {
46
const y$2 = x;
47
y$0 = y$2;
48
}
49
}
52
-
50
$[0] = props.p0;
51
$[1] = props.p2;
52
$[2] = props.p3;
@@ -57,10 +54,8 @@ function Component(props) {
54
} else {
55
x = $[3];
56
}
60
-
57
const c_4 = $[4] !== x;
58
let child;
63
-
59
if (c_4) {
60
child = <Component data={x}></Component>;
61
$[4] = x;
@@ -68,12 +63,10 @@ function Component(props) {
63
} else {
64
child = $[5];
65
}
71
-
66
y$0.push(props.p4);
67
const c_6 = $[6] !== y$0;
68
const c_7 = $[7] !== child;
69
let t8;
76
-
70
if (c_6 || c_7) {
71
t8 = <Component data={y$0}>{child}</Component>;
72
$[6] = y$0;
@@ -82,7 +75,6 @@ function Component(props) {
75
} else {
76
t8 = $[8];
77
}
85
-
78
return t8;
79
}
80
compiler/forget/src/__tests__/fixtures/hir/transitive-alias-fields.expect.md
+1
@@ -28,6 +28,7 @@ function component() {
28
x.y = y;
29
p.y = x.y;
30
q.y = p.y;
31
+
32
mutate(q);
33
}
34
compiler/forget/src/__tests__/fixtures/hir/type-binary-operator.expect.md
-3
@@ -24,16 +24,13 @@ function component() {
24
} else {
25
a = $[0];
26
}
27
-
27
let b;
29
-
28
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
29
b = someOther();
30
$[1] = b;
31
} else {
32
b = $[1];
33
}
36
-
34
if (a > b) {
35
const m = {};
36
}
compiler/forget/src/__tests__/fixtures/hir/type-field-load.expect.md
+1
-4
@@ -16,14 +16,11 @@ function component() {
16
const $ = React.useMemoCache();
17
let x;
18
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
19
- x = {
20
- t: 1,
21
- };
19
+ x = { t: 1 };
20
$[0] = x;
21
} else {
22
x = $[0];
23
}
26
-
24
const p = x.t;
25
}
26
compiler/forget/src/__tests__/fixtures/hir/type-test-field-load-binary-op.expect.md
+1
-10
@@ -27,35 +27,26 @@ function component() {
27
} else {
28
t0 = $[0];
29
}
30
-
30
let t1;
32
-
31
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
32
t1 = makeSomePrimitive();
33
$[1] = t1;
34
} else {
35
t1 = $[1];
36
}
39
-
37
const c_2 = $[2] !== t0;
38
const c_3 = $[3] !== t1;
39
let x;
43
-
40
if (c_2 || c_3) {
45
- x = {
46
- u: t0,
47
- v: t1,
48
- };
41
+ x = { u: t0, v: t1 };
42
$[2] = t0;
43
$[3] = t1;
44
$[4] = x;
45
} else {
46
x = $[4];
47
}
55
-
48
const u = x.u;
49
const v = x.v;
58
-
50
if (u > v) {
51
}
52
compiler/forget/src/__tests__/fixtures/hir/type-test-field-store.expect.md
-2
@@ -20,14 +20,12 @@ function component() {
20
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
21
x = {};
22
let q;
23
-
23
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
24
q = {};
25
$[1] = q;
26
} else {
27
q = $[1];
28
}
30
-
29
x.t = q;
30
$[0] = x;
31
} else {
compiler/forget/src/__tests__/fixtures/hir/type-test-polymorphic.expect.md
+1
-4
@@ -30,23 +30,20 @@ function component() {
30
} else {
31
p = $[0];
32
}
33
-
33
p + p;
34
let o;
36
-
35
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
36
o = {};
37
$[1] = o;
38
} else {
39
o = $[1];
40
}
43
-
41
const c_2 = $[2] !== o;
42
let x;
46
-
43
if (c_2) {
44
x = {};
45
x.t = p;
46
+
47
const z = x.t;
48
x.t = o;
49
$[2] = o;
compiler/forget/src/__tests__/fixtures/hir/type-test-return-type-inference.expect.md
-3
@@ -26,16 +26,13 @@ function component() {
26
} else {
27
x = $[0];
28
}
29
-
29
let y;
31
-
30
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
31
y = foo();
32
$[1] = y;
33
} else {
34
y = $[1];
35
}
38
-
36
if (x > y) {
37
const z = {};
38
}
compiler/forget/src/__tests__/fixtures/hir/unconditional-break-label.expect.md
+1
@@ -18,6 +18,7 @@ function foo(a) {
18
```javascript
19
function foo(a) {
20
const x = 0;
21
+
22
const x$0 = 1;
23
return a + x$0;
24
}
compiler/forget/src/__tests__/fixtures/hir/while-conditional-continue.expect.md
+1
@@ -23,6 +23,7 @@ function foo(a, b, c, d) {
23
if (b) {
24
continue;
25
}
26
+
27
c();
28
}
29
compiler/forget/src/__tests__/fixtures/hir/while-property.expect.md
-3
@@ -22,18 +22,15 @@ function foo(a, b) {
22
let x;
23
if (c_0 || c_1) {
24
x = 0;
25
-
25
while (a.b.c) {
26
x = x + b;
27
}
29
-
28
$[0] = a.b.c;
29
$[1] = b;
30
$[2] = x;
31
} else {
32
x = $[2];
33
}
36
-
34
return x;
35
}
36
compiler/forget/src/__tests__/hir-test.ts
+11
-37
@@ -7,16 +7,16 @@
7
8
"use strict";
9
10
-import generate from "@babel/generator";
11
-import * as parser from "@babel/parser";
12
-import traverse from "@babel/traverse";
10
import { wasmFolder } from "@hpcc-js/wasm";
11
import path from "path";
15
-import prettier from "prettier";
16
-import { compile } from "../CompilerPipeline";
12
+import runReactForgetBabelPlugin from "../Babel/RunReactForgetBabelPlugin";
13
import { toggleLogging } from "../Utils/logger";
14
import generateTestsFromFixtures from "./test-utils/generateTestsFromFixtures";
15
16
+type TestOutput = {
17
+ js: string;
18
+};
19
+
20
function wrapWithTripleBackticks(s: string, ext?: string) {
21
return `\`\`\`${ext ?? ""}
22
${s}
@@ -46,13 +46,13 @@ describe("React Forget (HIR version)", () => {
46
}
47
}
48
49
- let items: Array<TestOutput> | null = null;
49
+ let items: Array<TestOutput> = [];
50
let error: Error | null = null;
51
if (options.debug) {
52
toggleLogging(options.debug);
53
}
54
try {
55
- items = transform(input, file);
55
+ items.push({ js: runReactForgetBabelPlugin(input, file).code });
56
} catch (e) {
57
error = e;
58
}
@@ -91,6 +91,10 @@ ${outputs.join("\n")}
91
});
92
93
function formatErrorOutput(error: Error): string {
94
+ // Babel outputs absolute paths of the filename in the error mesage, which means fixtures will
95
+ // contain paths that only pertain to your local machine. Strip it just here because that info
96
+ // is still useful in real world usage of the Babel plugin.
97
+ error.message = error.message.replace(/^\/.*?:\s/, "");
98
return `
99
## Error
100
@@ -107,33 +111,3 @@ ${wrapWithTripleBackticks(js, "javascript")}
111
`.trim();
112
});
113
}
110
-
111
-type TestOutput = {
112
- js: string;
113
-};
114
-
115
-function transform(text: string, file: string): Array<TestOutput> {
116
- const items: Array<TestOutput> = [];
117
- const ast = parser.parse(text, {
118
- sourceFilename: file,
119
- plugins: ["typescript", "jsx"],
120
- });
121
- traverse(ast, {
122
- FunctionDeclaration: {
123
- enter(nodePath) {
124
- if (nodePath.scope.getProgramParent() !== nodePath.scope.parent) {
125
- return;
126
- }
127
-
128
- const ast = compile(nodePath);
129
-
130
- const text = prettier.format(generate(ast).code.replace("\n\n", "\n"), {
131
- semi: true,
132
- parser: "babel-ts",
133
- });
134
- items.push({ js: text });
135
- },
136
- },
137
- });
138
- return items;
139
-}
compiler/forget/src/index.ts
+4
-7
@@ -5,14 +5,11 @@
5
* LICENSE file in the root directory of this source tree.
6
*/
7
8
-import BabelPlugin from "./Babel/BabelPlugin";
9
-
10
-declare global {
11
- var __DEV__: boolean | null | undefined;
12
-}
13
-
8
+export { default as BabelPlugin } from "./Babel/BabelPlugin";
9
export { compile, run } from "./CompilerPipeline";
10
export { printHIR } from "./HIR";
11
export { printReactiveFunction } from "./ReactiveScopes";
12
18
-export default BabelPlugin;
13
+declare global {
14
+ var __DEV__: boolean | null | undefined;
15
+}