Skip to content

Commit 0f3c62b

Browse files
authored
[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
1 parent 858633f commit 0f3c62b

7 files changed

+200
-41
lines changed

Diff for: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md

+37-9
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,55 @@
22
## Input
33

44
```javascript
5-
function component(foo, bar) {
5+
import {mutate} from 'shared-runtime';
6+
7+
function Component({foo, bar}) {
68
let x = {foo};
79
let y = {bar};
810
const f0 = function () {
9-
let a = {y};
11+
let a = [y];
1012
let b = x;
11-
a.x = b;
13+
// this writes y.x = x
14+
a[0].x = b;
1215
};
1316
f0();
14-
mutate(y);
17+
mutate(y.x);
1518
return y;
1619
}
1720

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+
1830
```
1931

2032
## Code
2133

2234
```javascript
2335
import { c as _c } from "react/compiler-runtime";
24-
function component(foo, bar) {
36+
import { mutate } from "shared-runtime";
37+
38+
function Component(t0) {
2539
const $ = _c(3);
40+
const { foo, bar } = t0;
2641
let y;
2742
if ($[0] !== bar || $[1] !== foo) {
2843
const x = { foo };
2944
y = { bar };
3045
const f0 = function () {
31-
const a = { y };
46+
const a = [y];
3247
const b = x;
33-
a.x = b;
48+
49+
a[0].x = b;
3450
};
3551

3652
f0();
37-
mutate(y);
53+
mutate(y.x);
3854
$[0] = bar;
3955
$[1] = foo;
4056
$[2] = y;
@@ -44,5 +60,17 @@ function component(foo, bar) {
4460
return y;
4561
}
4662

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+
4772
```
48-
73+
74+
### Eval output
75+
(kind: ok) {"bar":4,"x":{"foo":3,"wat0":"joe"}}
76+
{"bar":5,"x":{"foo":3,"wat0":"joe"}}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
function component(foo, bar) {
1+
import {mutate} from 'shared-runtime';
2+
3+
function Component({foo, bar}) {
24
let x = {foo};
35
let y = {bar};
46
const f0 = function () {
5-
let a = {y};
7+
let a = [y];
68
let b = x;
7-
a.x = b;
9+
// this writes y.x = x
10+
a[0].x = b;
811
};
912
f0();
10-
mutate(y);
13+
mutate(y.x);
1114
return y;
1215
}
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+
};

Diff for: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md

+40-19
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,28 @@
22
## Input
33

44
```javascript
5-
function component(a, b) {
5+
import {mutate} from 'shared-runtime';
6+
7+
function Component({a, b}) {
68
let z = {a};
7-
let y = {b};
9+
let y = {b: {b}};
810
let x = function () {
911
z.a = 2;
10-
console.log(y.b);
12+
mutate(y.b);
1113
};
1214
x();
13-
return z;
15+
return [y, z];
1416
}
1517

1618
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+
],
2027
};
2128

2229
```
@@ -25,32 +32,46 @@ export const FIXTURE_ENTRYPOINT = {
2532

2633
```javascript
2734
import { c as _c } from "react/compiler-runtime";
28-
function component(a, b) {
35+
import { mutate } from "shared-runtime";
36+
37+
function Component(t0) {
2938
const $ = _c(3);
30-
let z;
39+
const { a, b } = t0;
40+
let t1;
3141
if ($[0] !== a || $[1] !== b) {
32-
z = { a };
33-
const y = { b };
42+
const z = { a };
43+
const y = { b: { b } };
3444
const x = function () {
3545
z.a = 2;
36-
console.log(y.b);
46+
mutate(y.b);
3747
};
3848

3949
x();
50+
t1 = [y, z];
4051
$[0] = a;
4152
$[1] = b;
42-
$[2] = z;
53+
$[2] = t1;
4354
} else {
44-
z = $[2];
55+
t1 = $[2];
4556
}
46-
return z;
57+
return t1;
4758
}
4859

4960
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+
],
5369
};
5470

5571
```
56-
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}]
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
function component(a, b) {
1+
import {mutate} from 'shared-runtime';
2+
3+
function Component({a, b}) {
24
let z = {a};
3-
let y = {b};
5+
let y = {b: {b}};
46
let x = function () {
57
z.a = 2;
6-
console.log(y.b);
8+
mutate(y.b);
79
};
810
x();
9-
return z;
11+
return [y, z];
1012
}
1113

1214
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+
],
1623
};
Original file line numberDiff line numberDiff line change
@@ -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}
Original file line numberDiff line numberDiff line change
@@ -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+
};

Diff for: compiler/packages/snap/src/SproutTodoFilter.ts

-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const skipFilter = new Set([
3434
'capturing-arrow-function-1',
3535
'capturing-func-mutate-3',
3636
'capturing-func-mutate-nested',
37-
'capturing-func-mutate',
3837
'capturing-function-1',
3938
'capturing-function-alias-computed-load',
4039
'capturing-function-decl',
@@ -236,7 +235,6 @@ const skipFilter = new Set([
236235
'capturing-fun-alias-captured-mutate-2',
237236
'capturing-fun-alias-captured-mutate-arr-2',
238237
'capturing-func-alias-captured-mutate-arr',
239-
'capturing-func-alias-captured-mutate',
240238
'capturing-func-alias-computed-mutate',
241239
'capturing-func-alias-mutate',
242240
'capturing-func-alias-receiver-computed-mutate',

0 commit comments

Comments
 (0)