Skip to content

Commit 0cf6d0c

Browse files
authored
[compiler] Update fixtures for new inference (#33496)
--- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33496). * #33571 * #33558 * #33547 * #33543 * #33533 * #33532 * #33530 * #33526 * #33522 * #33518 * #33514 * #33513 * #33512 * #33504 * #33500 * #33497 * __->__ #33496
1 parent df080d2 commit 0cf6d0c

File tree

48 files changed

+389
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+389
-280
lines changed

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/aliased-nested-scope-truncated-dep.expect.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## Input
33

44
```javascript
5+
// @enableNewMutationAliasingModel
56
import {
67
Stringify,
78
mutate,
@@ -101,7 +102,7 @@ export const FIXTURE_ENTRYPOINT = {
101102
## Code
102103

103104
```javascript
104-
import { c as _c } from "react/compiler-runtime";
105+
import { c as _c } from "react/compiler-runtime"; // @enableNewMutationAliasingModel
105106
import {
106107
Stringify,
107108
mutate,
@@ -175,21 +176,14 @@ import {
175176
* and mutability.
176177
*/
177178
function Component(t0) {
178-
const $ = _c(4);
179+
const $ = _c(2);
179180
const { prop } = t0;
180181
let t1;
181182
if ($[0] !== prop) {
182183
const obj = shallowCopy(prop);
183184
const aliasedObj = identity(obj);
184-
let t2;
185-
if ($[2] !== obj) {
186-
t2 = [obj.id];
187-
$[2] = obj;
188-
$[3] = t2;
189-
} else {
190-
t2 = $[3];
191-
}
192-
const id = t2;
185+
186+
const id = [obj.id];
193187

194188
mutate(aliasedObj);
195189
setPropertyByKey(aliasedObj, "id", prop.id + 1);

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/aliased-nested-scope-truncated-dep.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @enableNewMutationAliasingModel
12
import {
23
Stringify,
34
mutate,

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/array-map-named-callback-cross-context.expect.md

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## Input
33

44
```javascript
5+
// @enableNewMutationAliasingModel
56
import {Stringify} from 'shared-runtime';
67

78
/**
@@ -43,7 +44,7 @@ export const FIXTURE_ENTRYPOINT = {
4344
## Code
4445

4546
```javascript
46-
import { c as _c } from "react/compiler-runtime";
47+
import { c as _c } from "react/compiler-runtime"; // @enableNewMutationAliasingModel
4748
import { Stringify } from "shared-runtime";
4849

4950
/**
@@ -57,62 +58,67 @@ import { Stringify } from "shared-runtime";
5758
* - cb1 is not assumed to be called since it's only used as a call operand
5859
*/
5960
function useFoo(t0) {
60-
const $ = _c(13);
61-
const { arr1, arr2 } = t0;
61+
const $ = _c(14);
62+
let arr1;
63+
let arr2;
6264
let t1;
63-
if ($[0] !== arr1[0]) {
64-
t1 = (e) => arr1[0].value + e.value;
65-
$[0] = arr1[0];
66-
$[1] = t1;
65+
if ($[0] !== t0) {
66+
({ arr1, arr2 } = t0);
67+
let t2;
68+
if ($[4] !== arr1[0]) {
69+
t2 = (e) => arr1[0].value + e.value;
70+
$[4] = arr1[0];
71+
$[5] = t2;
72+
} else {
73+
t2 = $[5];
74+
}
75+
const cb1 = t2;
76+
t1 = () => arr1.map(cb1);
77+
$[0] = t0;
78+
$[1] = arr1;
79+
$[2] = arr2;
80+
$[3] = t1;
6781
} else {
68-
t1 = $[1];
82+
arr1 = $[1];
83+
arr2 = $[2];
84+
t1 = $[3];
6985
}
70-
const cb1 = t1;
86+
const getArrMap1 = t1;
7187
let t2;
72-
if ($[2] !== arr1 || $[3] !== cb1) {
73-
t2 = () => arr1.map(cb1);
74-
$[2] = arr1;
75-
$[3] = cb1;
76-
$[4] = t2;
88+
if ($[6] !== arr2) {
89+
t2 = (e_0) => arr2[0].value + e_0.value;
90+
$[6] = arr2;
91+
$[7] = t2;
7792
} else {
78-
t2 = $[4];
93+
t2 = $[7];
7994
}
80-
const getArrMap1 = t2;
95+
const cb2 = t2;
8196
let t3;
82-
if ($[5] !== arr2) {
83-
t3 = (e_0) => arr2[0].value + e_0.value;
84-
$[5] = arr2;
85-
$[6] = t3;
97+
if ($[8] !== arr1 || $[9] !== cb2) {
98+
t3 = () => arr1.map(cb2);
99+
$[8] = arr1;
100+
$[9] = cb2;
101+
$[10] = t3;
86102
} else {
87-
t3 = $[6];
103+
t3 = $[10];
88104
}
89-
const cb2 = t3;
105+
const getArrMap2 = t3;
90106
let t4;
91-
if ($[7] !== arr1 || $[8] !== cb2) {
92-
t4 = () => arr1.map(cb2);
93-
$[7] = arr1;
94-
$[8] = cb2;
95-
$[9] = t4;
96-
} else {
97-
t4 = $[9];
98-
}
99-
const getArrMap2 = t4;
100-
let t5;
101-
if ($[10] !== getArrMap1 || $[11] !== getArrMap2) {
102-
t5 = (
107+
if ($[11] !== getArrMap1 || $[12] !== getArrMap2) {
108+
t4 = (
103109
<Stringify
104110
getArrMap1={getArrMap1}
105111
getArrMap2={getArrMap2}
106112
shouldInvokeFns={true}
107113
/>
108114
);
109-
$[10] = getArrMap1;
110-
$[11] = getArrMap2;
111-
$[12] = t5;
115+
$[11] = getArrMap1;
116+
$[12] = getArrMap2;
117+
$[13] = t4;
112118
} else {
113-
t5 = $[12];
119+
t4 = $[13];
114120
}
115-
return t5;
121+
return t4;
116122
}
117123

118124
export const FIXTURE_ENTRYPOINT = {

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/array-map-named-callback-cross-context.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @enableNewMutationAliasingModel
12
import {Stringify} from 'shared-runtime';
23

34
/**

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/capturing-function-alias-computed-load-2-iife.expect.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## Input
33

44
```javascript
5+
// @enableNewMutationAliasingModel
56
function bar(a) {
67
let x = [a];
78
let y = {};
@@ -23,19 +24,27 @@ export const FIXTURE_ENTRYPOINT = {
2324
## Code
2425

2526
```javascript
26-
import { c as _c } from "react/compiler-runtime";
27+
import { c as _c } from "react/compiler-runtime"; // @enableNewMutationAliasingModel
2728
function bar(a) {
28-
const $ = _c(2);
29-
let y;
29+
const $ = _c(4);
30+
let t0;
3031
if ($[0] !== a) {
31-
const x = [a];
32+
t0 = [a];
33+
$[0] = a;
34+
$[1] = t0;
35+
} else {
36+
t0 = $[1];
37+
}
38+
const x = t0;
39+
let y;
40+
if ($[2] !== x[0][1]) {
3241
y = {};
3342

3443
y = x[0][1];
35-
$[0] = a;
36-
$[1] = y;
44+
$[2] = x[0][1];
45+
$[3] = y;
3746
} else {
38-
y = $[1];
47+
y = $[3];
3948
}
4049
return y;
4150
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/capturing-function-alias-computed-load-2-iife.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @enableNewMutationAliasingModel
12
function bar(a) {
23
let x = [a];
34
let y = {};

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/capturing-function-alias-computed-load-3-iife.expect.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## Input
33

44
```javascript
5+
// @enableNewMutationAliasingModel
56
function bar(a, b) {
67
let x = [a, b];
78
let y = {};
@@ -27,22 +28,31 @@ export const FIXTURE_ENTRYPOINT = {
2728
## Code
2829

2930
```javascript
30-
import { c as _c } from "react/compiler-runtime";
31+
import { c as _c } from "react/compiler-runtime"; // @enableNewMutationAliasingModel
3132
function bar(a, b) {
32-
const $ = _c(3);
33-
let y;
33+
const $ = _c(6);
34+
let t0;
3435
if ($[0] !== a || $[1] !== b) {
35-
const x = [a, b];
36+
t0 = [a, b];
37+
$[0] = a;
38+
$[1] = b;
39+
$[2] = t0;
40+
} else {
41+
t0 = $[2];
42+
}
43+
const x = t0;
44+
let y;
45+
if ($[3] !== x[0][1] || $[4] !== x[1][0]) {
3646
y = {};
3747
let t = {};
3848

3949
y = x[0][1];
4050
t = x[1][0];
41-
$[0] = a;
42-
$[1] = b;
43-
$[2] = y;
51+
$[3] = x[0][1];
52+
$[4] = x[1][0];
53+
$[5] = y;
4454
} else {
45-
y = $[2];
55+
y = $[5];
4656
}
4757
return y;
4858
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/capturing-function-alias-computed-load-3-iife.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @enableNewMutationAliasingModel
12
function bar(a, b) {
23
let x = [a, b];
34
let y = {};

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/capturing-function-alias-computed-load-4-iife.expect.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## Input
33

44
```javascript
5+
// @enableNewMutationAliasingModel
56
function bar(a) {
67
let x = [a];
78
let y = {};
@@ -23,19 +24,27 @@ export const FIXTURE_ENTRYPOINT = {
2324
## Code
2425

2526
```javascript
26-
import { c as _c } from "react/compiler-runtime";
27+
import { c as _c } from "react/compiler-runtime"; // @enableNewMutationAliasingModel
2728
function bar(a) {
28-
const $ = _c(2);
29-
let y;
29+
const $ = _c(4);
30+
let t0;
3031
if ($[0] !== a) {
31-
const x = [a];
32+
t0 = [a];
33+
$[0] = a;
34+
$[1] = t0;
35+
} else {
36+
t0 = $[1];
37+
}
38+
const x = t0;
39+
let y;
40+
if ($[2] !== x[0].a[1]) {
3241
y = {};
3342

3443
y = x[0].a[1];
35-
$[0] = a;
36-
$[1] = y;
44+
$[2] = x[0].a[1];
45+
$[3] = y;
3746
} else {
38-
y = $[1];
47+
y = $[3];
3948
}
4049
return y;
4150
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/new-mutability/capturing-function-alias-computed-load-4-iife.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @enableNewMutationAliasingModel
12
function bar(a) {
23
let x = [a];
34
let y = {};

0 commit comments

Comments
 (0)