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

[compiler][be] Patch test fixtures for evaluator (#31203)

Add more `FIXTURE_ENTRYPOINT`s ' --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31203). * #31202 * __->__ #31203 * #31201 * #31200 * #31521

mofeiZ committed Nov 15, 2024 at 13:06 UTC 0f3c62b4667f62bf36485079ab242dba8e54917c
7 files changed +200 -41
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md
+37 -9
@@ -2,39 +2,55 @@
2 ## Input
3
4 ```javascript
5 -function component(foo, bar) {
5 +import {mutate} from 'shared-runtime';
6 +
7 +function Component({foo, bar}) {
8 let x = {foo};
9 let y = {bar};
10 const f0 = function () {
9 - let a = {y};
11 + let a = [y];
12 let b = x;
11 - a.x = b;
13 + // this writes y.x = x
14 + a[0].x = b;
15 };
16 f0();
14 - mutate(y);
17 + mutate(y.x);
18 return y;
19 }
20
21 +export const FIXTURE_ENTRYPOINT = {
22 + fn: Component,
23 + params: [{foo: 3, bar: 4}],
24 + sequentialRenders: [
25 + {foo: 3, bar: 4},
26 + {foo: 3, bar: 5},
27 + ],
28 +};
29 +
30 ```
31
32 ## Code
33
34 ```javascript
35 import { c as _c } from "react/compiler-runtime";
24 -function component(foo, bar) {
36 +import { mutate } from "shared-runtime";
37 +
38 +function Component(t0) {
39 const $ = _c(3);
40 + const { foo, bar } = t0;
41 let y;
42 if ($[0] !== bar || $[1] !== foo) {
43 const x = { foo };
44 y = { bar };
45 const f0 = function () {
31 - const a = { y };
46 + const a = [y];
47 const b = x;
33 - a.x = b;
48 +
49 + a[0].x = b;
50 };
51
52 f0();
37 - mutate(y);
53 + mutate(y.x);
54 $[0] = bar;
55 $[1] = foo;
56 $[2] = y;
@@ -44,5 +60,17 @@ function component(foo, bar) {
60 return y;
61 }
62
63 +export const FIXTURE_ENTRYPOINT = {
64 + fn: Component,
65 + params: [{ foo: 3, bar: 4 }],
66 + sequentialRenders: [
67 + { foo: 3, bar: 4 },
68 + { foo: 3, bar: 5 },
69 + ],
70 +};
71 +
72 ```
48 -
\ No newline at end of file
73 +
74 +### Eval output
75 +(kind: ok) {"bar":4,"x":{"foo":3,"wat0":"joe"}}
76 +{"bar":5,"x":{"foo":3,"wat0":"joe"}}
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.js
+16 -4
@@ -1,12 +1,24 @@
1 -function component(foo, bar) {
1 +import {mutate} from 'shared-runtime';
2 +
3 +function Component({foo, bar}) {
4 let x = {foo};
5 let y = {bar};
6 const f0 = function () {
5 - let a = {y};
7 + let a = [y];
8 let b = x;
7 - a.x = b;
9 + // this writes y.x = x
10 + a[0].x = b;
11 };
12 f0();
10 - mutate(y);
13 + mutate(y.x);
14 return y;
15 }
16 +
17 +export const FIXTURE_ENTRYPOINT = {
18 + fn: Component,
19 + params: [{foo: 3, bar: 4}],
20 + sequentialRenders: [
21 + {foo: 3, bar: 4},
22 + {foo: 3, bar: 5},
23 + ],
24 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md
+40 -19
@@ -2,21 +2,28 @@
2 ## Input
3
4 ```javascript
5 -function component(a, b) {
5 +import {mutate} from 'shared-runtime';
6 +
7 +function Component({a, b}) {
8 let z = {a};
7 - let y = {b};
9 + let y = {b: {b}};
10 let x = function () {
11 z.a = 2;
10 - console.log(y.b);
12 + mutate(y.b);
13 };
14 x();
13 - return z;
15 + return [y, z];
16 }
17
18 export const FIXTURE_ENTRYPOINT = {
17 - fn: component,
18 - params: ['TodoAdd'],
19 - isComponent: 'TodoAdd',
19 + fn: Component,
20 + params: [{a: 2, b: 3}],
21 + sequentialRenders: [
22 + {a: 2, b: 3},
23 + {a: 2, b: 3},
24 + {a: 4, b: 3},
25 + {a: 4, b: 5},
26 + ],
27 };
28
29 ```
@@ -25,32 +32,46 @@ export const FIXTURE_ENTRYPOINT = {
32
33 ```javascript
34 import { c as _c } from "react/compiler-runtime";
28 -function component(a, b) {
35 +import { mutate } from "shared-runtime";
36 +
37 +function Component(t0) {
38 const $ = _c(3);
30 - let z;
39 + const { a, b } = t0;
40 + let t1;
41 if ($[0] !== a || $[1] !== b) {
32 - z = { a };
33 - const y = { b };
42 + const z = { a };
43 + const y = { b: { b } };
44 const x = function () {
45 z.a = 2;
36 - console.log(y.b);
46 + mutate(y.b);
47 };
48
49 x();
50 + t1 = [y, z];
51 $[0] = a;
52 $[1] = b;
42 - $[2] = z;
53 + $[2] = t1;
54 } else {
44 - z = $[2];
55 + t1 = $[2];
56 }
46 - return z;
57 + return t1;
58 }
59
60 export const FIXTURE_ENTRYPOINT = {
50 - fn: component,
51 - params: ["TodoAdd"],
52 - isComponent: "TodoAdd",
61 + fn: Component,
62 + params: [{ a: 2, b: 3 }],
63 + sequentialRenders: [
64 + { a: 2, b: 3 },
65 + { a: 2, b: 3 },
66 + { a: 4, b: 3 },
67 + { a: 4, b: 5 },
68 + ],
69 };
70
71 ```
56 -
\ No newline at end of file
72 +
73 +### Eval output
74 +(kind: ok) [{"b":{"b":3,"wat0":"joe"}},{"a":2}]
75 +[{"b":{"b":3,"wat0":"joe"}},{"a":2}]
76 +[{"b":{"b":3,"wat0":"joe"}},{"a":2}]
77 +[{"b":{"b":5,"wat0":"joe"}},{"a":2}]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate.js
+14 -7
@@ -1,16 +1,23 @@
1 -function component(a, b) {
1 +import {mutate} from 'shared-runtime';
2 +
3 +function Component({a, b}) {
4 let z = {a};
3 - let y = {b};
5 + let y = {b: {b}};
6 let x = function () {
7 z.a = 2;
6 - console.log(y.b);
8 + mutate(y.b);
9 };
10 x();
9 - return z;
11 + return [y, z];
12 }
13
14 export const FIXTURE_ENTRYPOINT = {
13 - fn: component,
14 - params: ['TodoAdd'],
15 - isComponent: 'TodoAdd',
15 + fn: Component,
16 + params: [{a: 2, b: 3}],
17 + sequentialRenders: [
18 + {a: 2, b: 3},
19 + {a: 2, b: 3},
20 + {a: 4, b: 3},
21 + {a: 4, b: 5},
22 + ],
23 };
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-no-mutate.expect.md new
+72
@@ -0,0 +1,72 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Component({a, b}) {
6 + let z = {a};
7 + let y = {b};
8 + let x = function () {
9 + z.a = 2;
10 + return Math.max(y.b, 0);
11 + };
12 + x();
13 + return z;
14 +}
15 +
16 +export const FIXTURE_ENTRYPOINT = {
17 + fn: Component,
18 + params: [{a: 2, b: 3}],
19 + sequentialRenders: [
20 + {a: 2, b: 3},
21 + {a: 2, b: 3},
22 + {a: 4, b: 3},
23 + {a: 4, b: 5},
24 + ],
25 +};
26 +
27 +```
28 +
29 +## Code
30 +
31 +```javascript
32 +import { c as _c } from "react/compiler-runtime";
33 +function Component(t0) {
34 + const $ = _c(3);
35 + const { a, b } = t0;
36 + let z;
37 + if ($[0] !== a || $[1] !== b) {
38 + z = { a };
39 + const y = { b };
40 + const x = function () {
41 + z.a = 2;
42 + return Math.max(y.b, 0);
43 + };
44 +
45 + x();
46 + $[0] = a;
47 + $[1] = b;
48 + $[2] = z;
49 + } else {
50 + z = $[2];
51 + }
52 + return z;
53 +}
54 +
55 +export const FIXTURE_ENTRYPOINT = {
56 + fn: Component,
57 + params: [{ a: 2, b: 3 }],
58 + sequentialRenders: [
59 + { a: 2, b: 3 },
60 + { a: 2, b: 3 },
61 + { a: 4, b: 3 },
62 + { a: 4, b: 5 },
63 + ],
64 +};
65 +
66 +```
67 +
68 +### Eval output
69 +(kind: ok) {"a":2}
70 +{"a":2}
71 +{"a":2}
72 +{"a":2}
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-no-mutate.js new
+21
@@ -0,0 +1,21 @@
1 +function Component({a, b}) {
2 + let z = {a};
3 + let y = {b};
4 + let x = function () {
5 + z.a = 2;
6 + return Math.max(y.b, 0);
7 + };
8 + x();
9 + return z;
10 +}
11 +
12 +export const FIXTURE_ENTRYPOINT = {
13 + fn: Component,
14 + params: [{a: 2, b: 3}],
15 + sequentialRenders: [
16 + {a: 2, b: 3},
17 + {a: 2, b: 3},
18 + {a: 4, b: 3},
19 + {a: 4, b: 5},
20 + ],
21 +};
compiler/packages/snap/src/SproutTodoFilter.ts
-2
@@ -34,7 +34,6 @@ const skipFilter = new Set([
34 'capturing-arrow-function-1',
35 'capturing-func-mutate-3',
36 'capturing-func-mutate-nested',
37 - 'capturing-func-mutate',
37 'capturing-function-1',
38 'capturing-function-alias-computed-load',
39 'capturing-function-decl',
@@ -236,7 +235,6 @@ const skipFilter = new Set([
235 'capturing-fun-alias-captured-mutate-2',
236 'capturing-fun-alias-captured-mutate-arr-2',
237 'capturing-func-alias-captured-mutate-arr',
239 - 'capturing-func-alias-captured-mutate',
238 'capturing-func-alias-computed-mutate',
239 'capturing-func-alias-mutate',
240 'capturing-func-alias-receiver-computed-mutate',