@samitouri / QOS-React / commits / f6dcce5199

[compiler][ez] Add entrypoints to ssa fixtures

Adds evaluator support for a few compiler test fixtures ghstack-source-id: 202654992a9876cea59885b54a338c908e369ddb Pull Request resolved: https://github.com/facebook/react/pull/30948

Mofei Zhang committed Sep 12, 2024 at 16:59 UTC f6dcce5199a3b9480a47d9feda8e00d8d9a0905d
27 files changed +413 -109
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/alias-capture-in-method-receiver-and-mutate.expect.md
+1 -1
@@ -57,4 +57,4 @@ export const FIXTURE_ENTRYPOINT = {
57 ```
58
59 ### Eval output
60 -(kind: ok) [[{"a":0,"b":"value1","c":true}],"[[ cyclic ref *2 ]]"]
\ No newline at end of file
60 +(kind: ok) [[{"a":0,"b":"value1","c":true},"joe"],"[[ cyclic ref *2 ]]"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/align-scopes-reactive-scope-overlaps-try.expect.md
+3 -3
@@ -60,6 +60,6 @@ export const FIXTURE_ENTRYPOINT = {
60 ```
61
62 ### Eval output
63 -(kind: ok) [2]
64 -[2]
65 -[3]
\ No newline at end of file
63 +(kind: ok) [2,"joe"]
64 +[2,"joe"]
65 +[3,"joe"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.expect.md
+20 -5
@@ -20,8 +20,13 @@ function Component(props) {
20
21 export const FIXTURE_ENTRYPOINT = {
22 fn: Component,
23 - params: ['TodoAdd'],
24 - isComponent: 'TodoAdd',
23 + params: [{a: 0, b: 1, c: true, d: true}],
24 + sequentialRenders: [
25 + {a: 0, b: 1, c: true, d: true},
26 + {a: 4, b: 1, c: true, d: true},
27 + {a: 4, b: 1, c: false, d: true},
28 + {a: 4, b: 1, c: false, d: false},
29 + ],
30 };
31
32 ```
@@ -61,9 +66,19 @@ function Component(props) {
66
67 export const FIXTURE_ENTRYPOINT = {
68 fn: Component,
64 - params: ["TodoAdd"],
65 - isComponent: "TodoAdd",
69 + params: [{ a: 0, b: 1, c: true, d: true }],
70 + sequentialRenders: [
71 + { a: 0, b: 1, c: true, d: true },
72 + { a: 4, b: 1, c: true, d: true },
73 + { a: 4, b: 1, c: false, d: true },
74 + { a: 4, b: 1, c: false, d: false },
75 + ],
76 };
77
78 ```
69 -
\ No newline at end of file
79 +
80 +### Eval output
81 +(kind: ok) [1,1,2]
82 +[4,1,2]
83 +[4,0,2]
84 +[4,0,0]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-cascading-eliminated-phis.js
+7 -2
@@ -16,6 +16,11 @@ function Component(props) {
16
17 export const FIXTURE_ENTRYPOINT = {
18 fn: Component,
19 - params: ['TodoAdd'],
20 - isComponent: 'TodoAdd',
19 + params: [{a: 0, b: 1, c: true, d: true}],
20 + sequentialRenders: [
21 + {a: 0, b: 1, c: true, d: true},
22 + {a: 4, b: 1, c: true, d: true},
23 + {a: 4, b: 1, c: false, d: true},
24 + {a: 4, b: 1, c: false, d: false},
25 + ],
26 };
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-leave-case.expect.md
+36 -5
@@ -2,6 +2,8 @@
2 ## Input
3
4 ```javascript
5 +import {Stringify} from 'shared-runtime';
6 +
7 function Component(props) {
8 let x = [];
9 let y;
@@ -10,19 +12,32 @@ function Component(props) {
12 y = x;
13 }
14 return (
13 - <Component>
15 + <Stringify>
16 {x}
17 {y}
16 - </Component>
18 + </Stringify>
19 );
20 }
21
22 +export const FIXTURE_ENTRYPOINT = {
23 + fn: Component,
24 + params: [{p0: false, p1: 2}],
25 + sequentialRenders: [
26 + {p0: false, p1: 2},
27 + {p0: false, p1: 2},
28 + {p0: true, p1: 2},
29 + {p0: true, p1: 3},
30 + ],
31 +};
32 +
33 ```
34
35 ## Code
36
37 ```javascript
38 import { c as _c } from "react/compiler-runtime";
39 +import { Stringify } from "shared-runtime";
40 +
41 function Component(props) {
42 const $ = _c(2);
43 let t0;
@@ -35,10 +50,10 @@ function Component(props) {
50 }
51
52 t0 = (
38 - <Component>
53 + <Stringify>
54 {x}
55 {y}
41 - </Component>
56 + </Stringify>
57 );
58 $[0] = props;
59 $[1] = t0;
@@ -48,5 +63,21 @@ function Component(props) {
63 return t0;
64 }
65
66 +export const FIXTURE_ENTRYPOINT = {
67 + fn: Component,
68 + params: [{ p0: false, p1: 2 }],
69 + sequentialRenders: [
70 + { p0: false, p1: 2 },
71 + { p0: false, p1: 2 },
72 + { p0: true, p1: 2 },
73 + { p0: true, p1: 3 },
74 + ],
75 +};
76 +
77 ```
52 -
\ No newline at end of file
78 +
79 +### Eval output
80 +(kind: ok) <div>{"children":[[],null]}</div>
81 +<div>{"children":[[],null]}</div>
82 +<div>{"children":[[2],"[[ cyclic ref *2 ]]"]}</div>
83 +<div>{"children":[[3],"[[ cyclic ref *2 ]]"]}</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-leave-case.js
+15 -2
@@ -1,3 +1,5 @@
1 +import {Stringify} from 'shared-runtime';
2 +
3 function Component(props) {
4 let x = [];
5 let y;
@@ -6,9 +8,20 @@ function Component(props) {
8 y = x;
9 }
10 return (
9 - <Component>
11 + <Stringify>
12 {x}
13 {y}
12 - </Component>
14 + </Stringify>
15 );
16 }
17 +
18 +export const FIXTURE_ENTRYPOINT = {
19 + fn: Component,
20 + params: [{p0: false, p1: 2}],
21 + sequentialRenders: [
22 + {p0: false, p1: 2},
23 + {p0: false, p1: 2},
24 + {p0: true, p1: 2},
25 + {p0: true, p1: 3},
26 + ],
27 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md
+33 -5
@@ -2,28 +2,42 @@
2 ## Input
3
4 ```javascript
5 -function foo(props) {
5 +import {mutate} from 'shared-runtime';
6 +
7 +function useFoo(props) {
8 let x = [];
9 x.push(props.bar);
10 props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
9 - mut(x);
11 + mutate(x);
12 return x;
13 }
14
15 +export const FIXTURE_ENTRYPOINT = {
16 + fn: useFoo,
17 + params: [{cond: false, foo: 2, bar: 55}],
18 + sequentialRenders: [
19 + {cond: false, foo: 2, bar: 55},
20 + {cond: false, foo: 3, bar: 55},
21 + {cond: true, foo: 3, bar: 55},
22 + ],
23 +};
24 +
25 ```
26
27 ## Code
28
29 ```javascript
30 import { c as _c } from "react/compiler-runtime";
19 -function foo(props) {
31 +import { mutate } from "shared-runtime";
32 +
33 +function useFoo(props) {
34 const $ = _c(2);
35 let x;
36 if ($[0] !== props) {
37 x = [];
38 x.push(props.bar);
39 props.cond ? (([x] = [[]]), x.push(props.foo)) : null;
26 - mut(x);
40 + mutate(x);
41 $[0] = props;
42 $[1] = x;
43 } else {
@@ -32,5 +46,19 @@ function foo(props) {
46 return x;
47 }
48
49 +export const FIXTURE_ENTRYPOINT = {
50 + fn: useFoo,
51 + params: [{ cond: false, foo: 2, bar: 55 }],
52 + sequentialRenders: [
53 + { cond: false, foo: 2, bar: 55 },
54 + { cond: false, foo: 3, bar: 55 },
55 + { cond: true, foo: 3, bar: 55 },
56 + ],
57 +};
58 +
59 ```
36 -
\ No newline at end of file
60 +
61 +### Eval output
62 +(kind: ok) [55,"joe"]
63 +[55,"joe"]
64 +[3,"joe"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.js
+14 -2
@@ -1,7 +1,19 @@
1 -function foo(props) {
1 +import {mutate} from 'shared-runtime';
2 +
3 +function useFoo(props) {
4 let x = [];
5 x.push(props.bar);
6 props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
5 - mut(x);
7 + mutate(x);
8 return x;
9 }
10 +
11 +export const FIXTURE_ENTRYPOINT = {
12 + fn: useFoo,
13 + params: [{cond: false, foo: 2, bar: 55}],
14 + sequentialRenders: [
15 + {cond: false, foo: 2, bar: 55},
16 + {cond: false, foo: 3, bar: 55},
17 + {cond: true, foo: 3, bar: 55},
18 + ],
19 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.expect.md
+21 -9
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -function foo(props) {
5 +function useFoo(props) {
6 let x = [];
7 x.push(props.bar);
8 props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
@@ -10,9 +10,13 @@ function foo(props) {
10 }
11
12 export const FIXTURE_ENTRYPOINT = {
13 - fn: foo,
14 - params: ['TodoAdd'],
15 - isComponent: 'TodoAdd',
13 + fn: useFoo,
14 + params: [{cond: false, foo: 2, bar: 55}],
15 + sequentialRenders: [
16 + {cond: false, foo: 2, bar: 55},
17 + {cond: false, foo: 3, bar: 55},
18 + {cond: true, foo: 3, bar: 55},
19 + ],
20 };
21
22 ```
@@ -21,7 +25,7 @@ export const FIXTURE_ENTRYPOINT = {
25
26 ```javascript
27 import { c as _c } from "react/compiler-runtime";
24 -function foo(props) {
28 +function useFoo(props) {
29 const $ = _c(4);
30 let x;
31 if ($[0] !== props.bar) {
@@ -43,10 +47,18 @@ function foo(props) {
47 }
48
49 export const FIXTURE_ENTRYPOINT = {
46 - fn: foo,
47 - params: ["TodoAdd"],
48 - isComponent: "TodoAdd",
50 + fn: useFoo,
51 + params: [{ cond: false, foo: 2, bar: 55 }],
52 + sequentialRenders: [
53 + { cond: false, foo: 2, bar: 55 },
54 + { cond: false, foo: 3, bar: 55 },
55 + { cond: true, foo: 3, bar: 55 },
56 + ],
57 };
58
59 ```
52 -
\ No newline at end of file
60 +
61 +### Eval output
62 +(kind: ok) [55]
63 +[55]
64 +[3]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.js
+8 -4
@@ -1,4 +1,4 @@
1 -function foo(props) {
1 +function useFoo(props) {
2 let x = [];
3 x.push(props.bar);
4 props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
@@ -6,7 +6,11 @@ function foo(props) {
6 }
7
8 export const FIXTURE_ENTRYPOINT = {
9 - fn: foo,
10 - params: ['TodoAdd'],
11 - isComponent: 'TodoAdd',
9 + fn: useFoo,
10 + params: [{cond: false, foo: 2, bar: 55}],
11 + sequentialRenders: [
12 + {cond: false, foo: 2, bar: 55},
13 + {cond: false, foo: 3, bar: 55},
14 + {cond: true, foo: 3, bar: 55},
15 + ],
16 };
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md
+33 -5
@@ -2,28 +2,42 @@
2 ## Input
3
4 ```javascript
5 -function foo(props) {
5 +import {mutate} from 'shared-runtime';
6 +
7 +function useFoo(props) {
8 let x = [];
9 x.push(props.bar);
10 props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
9 - mut(x);
11 + mutate(x);
12 return x;
13 }
14
15 +export const FIXTURE_ENTRYPOINT = {
16 + fn: useFoo,
17 + params: [{cond: false, foo: 2, bar: 55}],
18 + sequentialRenders: [
19 + {cond: false, foo: 2, bar: 55},
20 + {cond: false, foo: 3, bar: 55},
21 + {cond: true, foo: 3, bar: 55},
22 + ],
23 +};
24 +
25 ```
26
27 ## Code
28
29 ```javascript
30 import { c as _c } from "react/compiler-runtime";
19 -function foo(props) {
31 +import { mutate } from "shared-runtime";
32 +
33 +function useFoo(props) {
34 const $ = _c(2);
35 let x;
36 if ($[0] !== props) {
37 x = [];
38 x.push(props.bar);
39 props.cond ? ((x = []), x.push(props.foo)) : null;
26 - mut(x);
40 + mutate(x);
41 $[0] = props;
42 $[1] = x;
43 } else {
@@ -32,5 +46,19 @@ function foo(props) {
46 return x;
47 }
48
49 +export const FIXTURE_ENTRYPOINT = {
50 + fn: useFoo,
51 + params: [{ cond: false, foo: 2, bar: 55 }],
52 + sequentialRenders: [
53 + { cond: false, foo: 2, bar: 55 },
54 + { cond: false, foo: 3, bar: 55 },
55 + { cond: true, foo: 3, bar: 55 },
56 + ],
57 +};
58 +
59 ```
36 -
\ No newline at end of file
60 +
61 +### Eval output
62 +(kind: ok) [55,"joe"]
63 +[55,"joe"]
64 +[3,"joe"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.js
+14 -2
@@ -1,7 +1,19 @@
1 -function foo(props) {
1 +import {mutate} from 'shared-runtime';
2 +
3 +function useFoo(props) {
4 let x = [];
5 x.push(props.bar);
6 props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
5 - mut(x);
7 + mutate(x);
8 return x;
9 }
10 +
11 +export const FIXTURE_ENTRYPOINT = {
12 + fn: useFoo,
13 + params: [{cond: false, foo: 2, bar: 55}],
14 + sequentialRenders: [
15 + {cond: false, foo: 2, bar: 55},
16 + {cond: false, foo: 3, bar: 55},
17 + {cond: true, foo: 3, bar: 55},
18 + ],
19 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary.expect.md
+21 -9
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -function foo(props) {
5 +function useFoo(props) {
6 let x = [];
7 x.push(props.bar);
8 props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
@@ -10,9 +10,13 @@ function foo(props) {
10 }
11
12 export const FIXTURE_ENTRYPOINT = {
13 - fn: foo,
14 - params: ['TodoAdd'],
15 - isComponent: 'TodoAdd',
13 + fn: useFoo,
14 + params: [{cond: false, foo: 2, bar: 55}],
15 + sequentialRenders: [
16 + {cond: false, foo: 2, bar: 55},
17 + {cond: false, foo: 3, bar: 55},
18 + {cond: true, foo: 3, bar: 55},
19 + ],
20 };
21
22 ```
@@ -21,7 +25,7 @@ export const FIXTURE_ENTRYPOINT = {
25
26 ```javascript
27 import { c as _c } from "react/compiler-runtime";
24 -function foo(props) {
28 +function useFoo(props) {
29 const $ = _c(4);
30 let x;
31 if ($[0] !== props.bar) {
@@ -43,10 +47,18 @@ function foo(props) {
47 }
48
49 export const FIXTURE_ENTRYPOINT = {
46 - fn: foo,
47 - params: ["TodoAdd"],
48 - isComponent: "TodoAdd",
50 + fn: useFoo,
51 + params: [{ cond: false, foo: 2, bar: 55 }],
52 + sequentialRenders: [
53 + { cond: false, foo: 2, bar: 55 },
54 + { cond: false, foo: 3, bar: 55 },
55 + { cond: true, foo: 3, bar: 55 },
56 + ],
57 };
58
59 ```
52 -
\ No newline at end of file
60 +
61 +### Eval output
62 +(kind: ok) [55]
63 +[55]
64 +[3]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-ternary.js
+8 -4
@@ -1,4 +1,4 @@
1 -function foo(props) {
1 +function useFoo(props) {
2 let x = [];
3 x.push(props.bar);
4 props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
@@ -6,7 +6,11 @@ function foo(props) {
6 }
7
8 export const FIXTURE_ENTRYPOINT = {
9 - fn: foo,
10 - params: ['TodoAdd'],
11 - isComponent: 'TodoAdd',
9 + fn: useFoo,
10 + params: [{cond: false, foo: 2, bar: 55}],
11 + sequentialRenders: [
12 + {cond: false, foo: 2, bar: 55},
13 + {cond: false, foo: 3, bar: 55},
14 + {cond: true, foo: 3, bar: 55},
15 + ],
16 };
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md
+4 -4
@@ -3,7 +3,7 @@
3
4 ```javascript
5 import {arrayPush} from 'shared-runtime';
6 -function foo(props) {
6 +function useFoo(props) {
7 let x = [];
8 x.push(props.bar);
9 props.cond
@@ -14,7 +14,7 @@ function foo(props) {
14 }
15
16 export const FIXTURE_ENTRYPOINT = {
17 - fn: foo,
17 + fn: useFoo,
18 params: [{cond: false, foo: 2, bar: 55}],
19 sequentialRenders: [
20 {cond: false, foo: 2, bar: 55},
@@ -30,7 +30,7 @@ export const FIXTURE_ENTRYPOINT = {
30 ```javascript
31 import { c as _c } from "react/compiler-runtime";
32 import { arrayPush } from "shared-runtime";
33 -function foo(props) {
33 +function useFoo(props) {
34 const $ = _c(2);
35 let x;
36 if ($[0] !== props) {
@@ -47,7 +47,7 @@ function foo(props) {
47 }
48
49 export const FIXTURE_ENTRYPOINT = {
50 - fn: foo,
50 + fn: useFoo,
51 params: [{ cond: false, foo: 2, bar: 55 }],
52 sequentialRenders: [
53 { cond: false, foo: 2, bar: 55 },
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.js
+2 -2
@@ -1,5 +1,5 @@
1 import {arrayPush} from 'shared-runtime';
2 -function foo(props) {
2 +function useFoo(props) {
3 let x = [];
4 x.push(props.bar);
5 props.cond
@@ -10,7 +10,7 @@ function foo(props) {
10 }
11
12 export const FIXTURE_ENTRYPOINT = {
13 - fn: foo,
13 + fn: useFoo,
14 params: [{cond: false, foo: 2, bar: 55}],
15 sequentialRenders: [
16 {cond: false, foo: 2, bar: 55},
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.expect.md
+21 -9
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -function foo(props) {
5 +function useFoo(props) {
6 let x = [];
7 x.push(props.bar);
8 props.cond
@@ -12,9 +12,13 @@ function foo(props) {
12 }
13
14 export const FIXTURE_ENTRYPOINT = {
15 - fn: foo,
16 - params: ['TodoAdd'],
17 - isComponent: 'TodoAdd',
15 + fn: useFoo,
16 + params: [{cond: false, foo: 2, bar: 55}],
17 + sequentialRenders: [
18 + {cond: false, foo: 2, bar: 55},
19 + {cond: false, foo: 3, bar: 55},
20 + {cond: true, foo: 3, bar: 55},
21 + ],
22 };
23
24 ```
@@ -23,7 +27,7 @@ export const FIXTURE_ENTRYPOINT = {
27
28 ```javascript
29 import { c as _c } from "react/compiler-runtime";
26 -function foo(props) {
30 +function useFoo(props) {
31 const $ = _c(4);
32 let x;
33 if ($[0] !== props.bar) {
@@ -45,10 +49,18 @@ function foo(props) {
49 }
50
51 export const FIXTURE_ENTRYPOINT = {
48 - fn: foo,
49 - params: ["TodoAdd"],
50 - isComponent: "TodoAdd",
52 + fn: useFoo,
53 + params: [{ cond: false, foo: 2, bar: 55 }],
54 + sequentialRenders: [
55 + { cond: false, foo: 2, bar: 55 },
56 + { cond: false, foo: 3, bar: 55 },
57 + { cond: true, foo: 3, bar: 55 },
58 + ],
59 };
60
61 ```
54 -
\ No newline at end of file
62 +
63 +### Eval output
64 +(kind: ok) [55]
65 +[55]
66 +[3]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.js
+8 -4
@@ -1,4 +1,4 @@
1 -function foo(props) {
1 +function useFoo(props) {
2 let x = [];
3 x.push(props.bar);
4 props.cond
@@ -8,7 +8,11 @@ function foo(props) {
8 }
9
10 export const FIXTURE_ENTRYPOINT = {
11 - fn: foo,
12 - params: ['TodoAdd'],
13 - isComponent: 'TodoAdd',
11 + fn: useFoo,
12 + params: [{cond: false, foo: 2, bar: 55}],
13 + sequentialRenders: [
14 + {cond: false, foo: 2, bar: 55},
15 + {cond: false, foo: 3, bar: 55},
16 + {cond: true, foo: 3, bar: 55},
17 + ],
18 };
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.expect.md
+33 -5
@@ -2,7 +2,9 @@
2 ## Input
3
4 ```javascript
5 -function foo(props) {
5 +import {mutate} from 'shared-runtime';
6 +
7 +function useFoo(props) {
8 let x = [];
9 x.push(props.bar);
10 if (props.cond) {
@@ -14,17 +16,29 @@ function foo(props) {
16 x = [];
17 x.push(props.bar);
18 }
17 - mut(x);
19 + mutate(x);
20 return x;
21 }
22
23 +export const FIXTURE_ENTRYPOINT = {
24 + fn: useFoo,
25 + params: [{bar: 'bar', foo: 'foo', cond: true}],
26 + sequentialRenders: [
27 + {bar: 'bar', foo: 'foo', cond: true},
28 + {bar: 'bar', foo: 'foo', cond: true},
29 + {bar: 'bar', foo: 'foo', cond: false},
30 + ],
31 +};
32 +
33 ```
34
35 ## Code
36
37 ```javascript
38 import { c as _c } from "react/compiler-runtime";
27 -function foo(props) {
39 +import { mutate } from "shared-runtime";
40 +
41 +function useFoo(props) {
42 const $ = _c(2);
43 let x;
44 if ($[0] !== props) {
@@ -38,7 +52,7 @@ function foo(props) {
52 x.push(props.bar);
53 }
54
41 - mut(x);
55 + mutate(x);
56 $[0] = props;
57 $[1] = x;
58 } else {
@@ -47,5 +61,19 @@ function foo(props) {
61 return x;
62 }
63
64 +export const FIXTURE_ENTRYPOINT = {
65 + fn: useFoo,
66 + params: [{ bar: "bar", foo: "foo", cond: true }],
67 + sequentialRenders: [
68 + { bar: "bar", foo: "foo", cond: true },
69 + { bar: "bar", foo: "foo", cond: true },
70 + { bar: "bar", foo: "foo", cond: false },
71 + ],
72 +};
73 +
74 ```
51 -
\ No newline at end of file
75 +
76 +### Eval output
77 +(kind: ok) ["foo","joe"]
78 +["foo","joe"]
79 +["bar","joe"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-with-mutation.js
+14 -2
@@ -1,4 +1,6 @@
1 -function foo(props) {
1 +import {mutate} from 'shared-runtime';
2 +
3 +function useFoo(props) {
4 let x = [];
5 x.push(props.bar);
6 if (props.cond) {
@@ -10,6 +12,16 @@ function foo(props) {
12 x = [];
13 x.push(props.bar);
14 }
13 - mut(x);
15 + mutate(x);
16 return x;
17 }
18 +
19 +export const FIXTURE_ENTRYPOINT = {
20 + fn: useFoo,
21 + params: [{bar: 'bar', foo: 'foo', cond: true}],
22 + sequentialRenders: [
23 + {bar: 'bar', foo: 'foo', cond: true},
24 + {bar: 'bar', foo: 'foo', cond: true},
25 + {bar: 'bar', foo: 'foo', cond: false},
26 + ],
27 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.expect.md
+33 -5
@@ -2,7 +2,9 @@
2 ## Input
3
4 ```javascript
5 -function foo(props) {
5 +import {mutate} from 'shared-runtime';
6 +
7 +function useFoo(props) {
8 let {x} = {x: []};
9 x.push(props.bar);
10 if (props.cond) {
@@ -10,17 +12,29 @@ function foo(props) {
12 ({x} = {x: []});
13 x.push(props.foo);
14 }
13 - mut(x);
15 + mutate(x);
16 return x;
17 }
18
19 +export const FIXTURE_ENTRYPOINT = {
20 + fn: useFoo,
21 + params: [{bar: 'bar', foo: 'foo', cond: true}],
22 + sequentialRenders: [
23 + {bar: 'bar', foo: 'foo', cond: true},
24 + {bar: 'bar', foo: 'foo', cond: true},
25 + {bar: 'bar', foo: 'foo', cond: false},
26 + ],
27 +};
28 +
29 ```
30
31 ## Code
32
33 ```javascript
34 import { c as _c } from "react/compiler-runtime";
23 -function foo(props) {
35 +import { mutate } from "shared-runtime";
36 +
37 +function useFoo(props) {
38 const $ = _c(2);
39 let x;
40 if ($[0] !== props) {
@@ -31,7 +45,7 @@ function foo(props) {
45 x.push(props.foo);
46 }
47
34 - mut(x);
48 + mutate(x);
49 $[0] = props;
50 $[1] = x;
51 } else {
@@ -40,5 +54,19 @@ function foo(props) {
54 return x;
55 }
56
57 +export const FIXTURE_ENTRYPOINT = {
58 + fn: useFoo,
59 + params: [{ bar: "bar", foo: "foo", cond: true }],
60 + sequentialRenders: [
61 + { bar: "bar", foo: "foo", cond: true },
62 + { bar: "bar", foo: "foo", cond: true },
63 + { bar: "bar", foo: "foo", cond: false },
64 + ],
65 +};
66 +
67 ```
44 -
\ No newline at end of file
68 +
69 +### Eval output
70 +(kind: ok) ["foo","joe"]
71 +["foo","joe"]
72 +["bar","joe"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-via-destructuring-with-mutation.js
+14 -2
@@ -1,4 +1,6 @@
1 -function foo(props) {
1 +import {mutate} from 'shared-runtime';
2 +
3 +function useFoo(props) {
4 let {x} = {x: []};
5 x.push(props.bar);
6 if (props.cond) {
@@ -6,6 +8,16 @@ function foo(props) {
8 ({x} = {x: []});
9 x.push(props.foo);
10 }
9 - mut(x);
11 + mutate(x);
12 return x;
13 }
14 +
15 +export const FIXTURE_ENTRYPOINT = {
16 + fn: useFoo,
17 + params: [{bar: 'bar', foo: 'foo', cond: true}],
18 + sequentialRenders: [
19 + {bar: 'bar', foo: 'foo', cond: true},
20 + {bar: 'bar', foo: 'foo', cond: true},
21 + {bar: 'bar', foo: 'foo', cond: false},
22 + ],
23 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.expect.md
+33 -5
@@ -2,7 +2,9 @@
2 ## Input
3
4 ```javascript
5 -function foo(props) {
5 +import {mutate} from 'shared-runtime';
6 +
7 +function useFoo(props) {
8 let x = [];
9 x.push(props.bar);
10 if (props.cond) {
@@ -10,17 +12,29 @@ function foo(props) {
12 x = [];
13 x.push(props.foo);
14 }
13 - mut(x);
15 + mutate(x);
16 return x;
17 }
18
19 +export const FIXTURE_ENTRYPOINT = {
20 + fn: useFoo,
21 + params: [{bar: 'bar', foo: 'foo', cond: true}],
22 + sequentialRenders: [
23 + {bar: 'bar', foo: 'foo', cond: true},
24 + {bar: 'bar', foo: 'foo', cond: true},
25 + {bar: 'bar', foo: 'foo', cond: false},
26 + ],
27 +};
28 +
29 ```
30
31 ## Code
32
33 ```javascript
34 import { c as _c } from "react/compiler-runtime";
23 -function foo(props) {
35 +import { mutate } from "shared-runtime";
36 +
37 +function useFoo(props) {
38 const $ = _c(2);
39 let x;
40 if ($[0] !== props) {
@@ -31,7 +45,7 @@ function foo(props) {
45 x.push(props.foo);
46 }
47
34 - mut(x);
48 + mutate(x);
49 $[0] = props;
50 $[1] = x;
51 } else {
@@ -40,5 +54,19 @@ function foo(props) {
54 return x;
55 }
56
57 +export const FIXTURE_ENTRYPOINT = {
58 + fn: useFoo,
59 + params: [{ bar: "bar", foo: "foo", cond: true }],
60 + sequentialRenders: [
61 + { bar: "bar", foo: "foo", cond: true },
62 + { bar: "bar", foo: "foo", cond: true },
63 + { bar: "bar", foo: "foo", cond: false },
64 + ],
65 +};
66 +
67 ```
44 -
\ No newline at end of file
68 +
69 +### Eval output
70 +(kind: ok) ["foo","joe"]
71 +["foo","joe"]
72 +["bar","joe"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ssa-renaming-with-mutation.js
+14 -2
@@ -1,4 +1,6 @@
1 -function foo(props) {
1 +import {mutate} from 'shared-runtime';
2 +
3 +function useFoo(props) {
4 let x = [];
5 x.push(props.bar);
6 if (props.cond) {
@@ -6,6 +8,16 @@ function foo(props) {
8 x = [];
9 x.push(props.foo);
10 }
9 - mut(x);
11 + mutate(x);
12 return x;
13 }
14 +
15 +export const FIXTURE_ENTRYPOINT = {
16 + fn: useFoo,
17 + params: [{bar: 'bar', foo: 'foo', cond: true}],
18 + sequentialRenders: [
19 + {bar: 'bar', foo: 'foo', cond: true},
20 + {bar: 'bar', foo: 'foo', cond: true},
21 + {bar: 'bar', foo: 'foo', cond: false},
22 + ],
23 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/unmemoized-nonreactive-dependency-is-pruned-as-dependency.expect.md
+1 -1
@@ -42,4 +42,4 @@ export const FIXTURE_ENTRYPOINT = {
42 ```
43
44 ### Eval output
45 -(kind: ok) <div></div>
\ No newline at end of file
45 +(kind: ok) <div>joe</div>
\ No newline at end of file
compiler/packages/snap/src/SproutTodoFilter.ts
-10
@@ -134,7 +134,6 @@ const skipFilter = new Set([
134 'same-variable-as-dep-and-redeclare',
135 'simple-scope',
136 'ssa-arrayexpression',
137 - 'ssa-cascading-eliminated-phis',
137 'ssa-for-of',
138 'ssa-multiple-phis',
139 'ssa-nested-loops-no-reassign',
@@ -144,9 +143,6 @@ const skipFilter = new Set([
143 'ssa-objectexpression',
144 'ssa-property-alias-if',
145 'ssa-reassign',
147 - 'ssa-renaming-ternary-destruction',
148 - 'ssa-renaming-ternary',
149 - 'ssa-renaming-unconditional-ternary',
146 'ssa-renaming-via-destructuring',
147 'ssa-renaming',
148 'ssa-sibling-phis',
@@ -325,15 +321,9 @@ const skipFilter = new Set([
321 'repro-scope-missing-mutable-range',
322 'repro',
323 'simple',
328 - 'ssa-leave-case',
324 'ssa-property-alias-alias-mutate-if',
325 'ssa-property-alias-mutate-if',
326 'ssa-property-alias-mutate-inside-if',
332 - 'ssa-renaming-ternary-destruction-with-mutation',
333 - 'ssa-renaming-ternary-with-mutation',
334 - 'ssa-renaming-unconditional-with-mutation',
335 - 'ssa-renaming-via-destructuring-with-mutation',
336 - 'ssa-renaming-with-mutation',
327 'switch-global-propertyload-case-test',
328 'switch-non-final-default',
329 'switch',
compiler/packages/snap/src/sprout/shared-runtime.ts
+2
@@ -54,6 +54,8 @@ export function mutate(arg: any): void {
54 // don't mutate primitive
55 if (arg == null || typeof arg !== 'object') {
56 return;
57 + } else if (Array.isArray(arg)) {
58 + arg.push('joe');
59 }
60
61 let count: number = 0;