Skip to content

Commit 28d6b84

Browse files
committed
[compiler] Fixture tests for PropertyStore effects
Adds fixture tests to demonstrate an issue in changing PropertyStore to always have a Store effect on its object operand, regardless of the operand type. The issue is that if we're doing a PropertyStore on a nested value, that has be considered a transitive mutation of the parent object: ``` const x = {y: {z: {}}}; x.y.z.key = 'value'; // this has to be a mutation of `x` ``` Fix in the next PR. ghstack-source-id: 4d3ea71 Pull Request resolved: facebook/react#33163
1 parent 15b3ab7 commit 28d6b84

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
## Input
3+
4+
```javascript
5+
function Component({a, b, c}) {
6+
// This is an object version of array-access-assignment.js
7+
// Meant to confirm that object expressions and PropertyStore/PropertyLoad with strings
8+
// works equivalently to array expressions and property accesses with numeric indices
9+
const x = {zero: a};
10+
const y = {zero: null, one: b};
11+
const z = {zero: {}, one: {}, two: {zero: c}};
12+
x.zero = y.one;
13+
z.zero.zero = x.zero;
14+
return {zero: x, one: z};
15+
}
16+
17+
export const FIXTURE_ENTRYPOINT = {
18+
fn: Component,
19+
params: [{a: 1, b: 20, c: 300}],
20+
sequentialRenders: [
21+
{a: 2, b: 20, c: 300},
22+
{a: 3, b: 20, c: 300},
23+
{a: 3, b: 21, c: 300},
24+
{a: 3, b: 22, c: 300},
25+
{a: 3, b: 22, c: 301},
26+
],
27+
};
28+
29+
```
30+
31+
## Code
32+
33+
```javascript
34+
import { c as _c } from "react/compiler-runtime";
35+
function Component(t0) {
36+
const $ = _c(10);
37+
const { a, b, c } = t0;
38+
let t1;
39+
if ($[0] !== a || $[1] !== b || $[2] !== c) {
40+
const x = { zero: a };
41+
let t2;
42+
if ($[4] !== b) {
43+
t2 = { zero: null, one: b };
44+
$[4] = b;
45+
$[5] = t2;
46+
} else {
47+
t2 = $[5];
48+
}
49+
const y = t2;
50+
let t3;
51+
let t4;
52+
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
53+
t3 = {};
54+
t4 = {};
55+
$[6] = t3;
56+
$[7] = t4;
57+
} else {
58+
t3 = $[6];
59+
t4 = $[7];
60+
}
61+
let t5;
62+
if ($[8] !== c) {
63+
t5 = { zero: c };
64+
$[8] = c;
65+
$[9] = t5;
66+
} else {
67+
t5 = $[9];
68+
}
69+
const z = { zero: t3, one: t4, two: t5 };
70+
x.zero = y.one;
71+
z.zero.zero = x.zero;
72+
t1 = { zero: x, one: z };
73+
$[0] = a;
74+
$[1] = b;
75+
$[2] = c;
76+
$[3] = t1;
77+
} else {
78+
t1 = $[3];
79+
}
80+
return t1;
81+
}
82+
83+
export const FIXTURE_ENTRYPOINT = {
84+
fn: Component,
85+
params: [{ a: 1, b: 20, c: 300 }],
86+
sequentialRenders: [
87+
{ a: 2, b: 20, c: 300 },
88+
{ a: 3, b: 20, c: 300 },
89+
{ a: 3, b: 21, c: 300 },
90+
{ a: 3, b: 22, c: 300 },
91+
{ a: 3, b: 22, c: 301 },
92+
],
93+
};
94+
95+
```
96+
97+
### Eval output
98+
(kind: ok) {"zero":{"zero":20},"one":{"zero":{"zero":20},"one":{},"two":{"zero":300}}}
99+
{"zero":{"zero":20},"one":{"zero":{"zero":20},"one":{},"two":{"zero":300}}}
100+
{"zero":{"zero":21},"one":{"zero":{"zero":21},"one":{},"two":{"zero":300}}}
101+
{"zero":{"zero":22},"one":{"zero":{"zero":22},"one":{},"two":{"zero":300}}}
102+
{"zero":{"zero":22},"one":{"zero":{"zero":22},"one":{},"two":{"zero":301}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function Component({a, b, c}) {
2+
// This is an object version of array-access-assignment.js
3+
// Meant to confirm that object expressions and PropertyStore/PropertyLoad with strings
4+
// works equivalently to array expressions and property accesses with numeric indices
5+
const x = {zero: a};
6+
const y = {zero: null, one: b};
7+
const z = {zero: {}, one: {}, two: {zero: c}};
8+
x.zero = y.one;
9+
z.zero.zero = x.zero;
10+
return {zero: x, one: z};
11+
}
12+
13+
export const FIXTURE_ENTRYPOINT = {
14+
fn: Component,
15+
params: [{a: 1, b: 20, c: 300}],
16+
sequentialRenders: [
17+
{a: 2, b: 20, c: 300},
18+
{a: 3, b: 20, c: 300},
19+
{a: 3, b: 21, c: 300},
20+
{a: 3, b: 22, c: 300},
21+
{a: 3, b: 22, c: 301},
22+
],
23+
};

0 commit comments

Comments
 (0)