Skip to content

Commit eab37c2

Browse files
committed
Update fixture snapshots after ObjectMethod removal (#36151)
Method shorthand now lowered to FunctionExpression in BuildHIR, so all object-method fixtures emit function() syntax instead of method() syntax. Also adds two new bug fixtures demonstrating consistent memoization for objects with mixed fn-expression / arrow / shorthand methods.
1 parent 38f5ad4 commit eab37c2

137 files changed

Lines changed: 639 additions & 243 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
## Input
3+
4+
```javascript
5+
function Component({a, b}) {
6+
return {
7+
test1: () => {
8+
console.log(a);
9+
},
10+
test2: function () {
11+
console.log(b);
12+
},
13+
};
14+
}
15+
16+
export const FIXTURE_ENTRYPOINT = {
17+
fn: Component,
18+
params: [{a: 1, b: 2}],
19+
};
20+
21+
```
22+
23+
## Code
24+
25+
```javascript
26+
import { c as _c } from "react/compiler-runtime";
27+
function Component(t0) {
28+
const $ = _c(7);
29+
const { a, b } = t0;
30+
let t1;
31+
if ($[0] !== a) {
32+
t1 = () => {
33+
console.log(a);
34+
};
35+
$[0] = a;
36+
$[1] = t1;
37+
} else {
38+
t1 = $[1];
39+
}
40+
let t2;
41+
if ($[2] !== b) {
42+
t2 = function () {
43+
console.log(b);
44+
};
45+
$[2] = b;
46+
$[3] = t2;
47+
} else {
48+
t2 = $[3];
49+
}
50+
let t3;
51+
if ($[4] !== t1 || $[5] !== t2) {
52+
t3 = { test1: t1, test2: t2 };
53+
$[4] = t1;
54+
$[5] = t2;
55+
$[6] = t3;
56+
} else {
57+
t3 = $[6];
58+
}
59+
return t3;
60+
}
61+
62+
export const FIXTURE_ENTRYPOINT = {
63+
fn: Component,
64+
params: [{ a: 1, b: 2 }],
65+
};
66+
67+
```
68+
69+
### Eval output
70+
(kind: ok) {"test1":"[[ function params=0 ]]","test2":"[[ function params=0 ]]"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function Component({a, b}) {
2+
return {
3+
test1: () => {
4+
console.log(a);
5+
},
6+
test2: function () {
7+
console.log(b);
8+
},
9+
};
10+
}
11+
12+
export const FIXTURE_ENTRYPOINT = {
13+
fn: Component,
14+
params: [{a: 1, b: 2}],
15+
};
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
## Input
3+
4+
```javascript
5+
function Component({a, b, c}) {
6+
return {
7+
test1() {
8+
console.log(a);
9+
},
10+
test2: () => {
11+
console.log(b);
12+
},
13+
test3: function () {
14+
console.log(c);
15+
},
16+
};
17+
}
18+
19+
export const FIXTURE_ENTRYPOINT = {
20+
fn: Component,
21+
params: [{a: 1, b: 2, c: 3}],
22+
};
23+
24+
```
25+
26+
## Code
27+
28+
```javascript
29+
import { c as _c } from "react/compiler-runtime";
30+
function Component(t0) {
31+
const $ = _c(10);
32+
const { a, b, c } = t0;
33+
let t1;
34+
if ($[0] !== a) {
35+
t1 = function () {
36+
console.log(a);
37+
};
38+
$[0] = a;
39+
$[1] = t1;
40+
} else {
41+
t1 = $[1];
42+
}
43+
let t2;
44+
if ($[2] !== b) {
45+
t2 = () => {
46+
console.log(b);
47+
};
48+
$[2] = b;
49+
$[3] = t2;
50+
} else {
51+
t2 = $[3];
52+
}
53+
let t3;
54+
if ($[4] !== c) {
55+
t3 = function () {
56+
console.log(c);
57+
};
58+
$[4] = c;
59+
$[5] = t3;
60+
} else {
61+
t3 = $[5];
62+
}
63+
let t4;
64+
if ($[6] !== t1 || $[7] !== t2 || $[8] !== t3) {
65+
t4 = { test1: t1, test2: t2, test3: t3 };
66+
$[6] = t1;
67+
$[7] = t2;
68+
$[8] = t3;
69+
$[9] = t4;
70+
} else {
71+
t4 = $[9];
72+
}
73+
return t4;
74+
}
75+
76+
export const FIXTURE_ENTRYPOINT = {
77+
fn: Component,
78+
params: [{ a: 1, b: 2, c: 3 }],
79+
};
80+
81+
```
82+
83+
### Eval output
84+
(kind: ok) {"test1":"[[ function params=0 ]]","test2":"[[ function params=0 ]]","test3":"[[ function params=0 ]]"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function Component({a, b, c}) {
2+
return {
3+
test1() {
4+
console.log(a);
5+
},
6+
test2: () => {
7+
console.log(b);
8+
},
9+
test3: function () {
10+
console.log(c);
11+
},
12+
};
13+
}
14+
15+
export const FIXTURE_ENTRYPOINT = {
16+
fn: Component,
17+
params: [{a: 1, b: 2, c: 3}],
18+
};

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/codegen-instrument-forget-test.expect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { c as _c } from "react/compiler-runtime"; // @enableEmitInstrumentForget
2929
function Bar(props) {
3030
"use forget";
3131
if (DEV && shouldInstrument)
32-
useRenderCounter("Bar", "/codegen-instrument-forget-test.ts");
32+
useRenderCounter("Bar", "C:\\codegen-instrument-forget-test.ts");
3333
const $ = _c(2);
3434
let t0;
3535
if ($[0] !== props.bar) {
@@ -49,7 +49,7 @@ function NoForget(props) {
4949
function Foo(props) {
5050
"use forget";
5151
if (DEV && shouldInstrument)
52-
useRenderCounter("Foo", "/codegen-instrument-forget-test.ts");
52+
useRenderCounter("Foo", "C:\\codegen-instrument-forget-test.ts");
5353
const $ = _c(2);
5454
let t0;
5555
if ($[0] !== props.bar) {

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/conflict-codegen-instrument-forget.expect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { identity } from "shared-runtime";
4242
function Bar(props) {
4343
"use forget";
4444
if (DEV && _shouldInstrument3)
45-
useRenderCounter("Bar", "/conflict-codegen-instrument-forget.ts");
45+
useRenderCounter("Bar", "C:\\conflict-codegen-instrument-forget.ts");
4646
const $ = _c(4);
4747
let t0;
4848
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
@@ -78,7 +78,7 @@ function Bar(props) {
7878
function Foo(props) {
7979
"use forget";
8080
if (DEV && _shouldInstrument3)
81-
useRenderCounter("Foo", "/conflict-codegen-instrument-forget.ts");
81+
useRenderCounter("Foo", "C:\\conflict-codegen-instrument-forget.ts");
8282
const $ = _c(2);
8383
let t0;
8484
if ($[0] !== props.bar) {

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-prop-across-objectmethod-def.expect.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ import { identity } from "shared-runtime";
3434
// inferred as a context variable.
3535

3636
function Component() {
37-
const obj = { method() {} };
37+
const obj = { method: _temp };
3838

3939
identity(obj);
4040

4141
return 4;
4242
}
43+
function _temp() {}
4344

4445
export const FIXTURE_ENTRYPOINT = {
4546
fn: Component,

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/constant-prop-to-object-method.expect.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,17 @@ function Foo() {
3131
const $ = _c(1);
3232
let t0;
3333
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
34-
const x = {
35-
foo() {
36-
return identity(1);
37-
},
38-
};
34+
const x = { foo: _temp };
3935
t0 = x.foo();
4036
$[0] = t0;
4137
} else {
4238
t0 = $[0];
4339
}
4440
return t0;
4541
}
42+
function _temp() {
43+
return identity(1);
44+
}
4645

4746
export const FIXTURE_ENTRYPOINT = {
4847
fn: Foo,

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/context-variable-reassigned-objectmethod.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function Component(t0) {
3737
if ($[0] !== cond) {
3838
x = 2;
3939
const obj = {
40-
method(cond_0) {
40+
method: function (cond_0) {
4141
if (cond_0) {
4242
x = 4;
4343
}

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/effect-derived-computations/derived-state-conditionally-in-effect.expect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export const FIXTURE_ENTRYPOINT = {
5656
## Logs
5757

5858
```
59-
{"kind":"CompileError","detail":{"options":{"description":"Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user\n\nThis setState call is setting a derived value that depends on the following reactive sources:\n\nProps: [value]\n\nData Flow Tree:\n└── value (Prop)\n\nSee: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state","category":"EffectDerivationsOfState","reason":"You might not need an effect. Derive values in render, not effects.","details":[{"kind":"error","loc":{"start":{"line":9,"column":6,"index":263},"end":{"line":9,"column":19,"index":276},"filename":"derived-state-conditionally-in-effect.ts","identifierName":"setLocalValue"},"message":"This should be computed during render, not in an effect"}]}},"fnLoc":null}
60-
{"kind":"CompileSuccess","fnLoc":{"start":{"line":4,"column":0,"index":126},"end":{"line":16,"column":1,"index":397},"filename":"derived-state-conditionally-in-effect.ts"},"fnName":"Component","memoSlots":6,"memoBlocks":2,"memoValues":3,"prunedMemoBlocks":0,"prunedMemoValues":0}
59+
{"kind":"CompileError","detail":{"options":{"description":"Using an effect triggers an additional render which can hurt performance and user experience, potentially briefly showing stale values to the user\n\nThis setState call is setting a derived value that depends on the following reactive sources:\n\nProps: [value]\n\nData Flow Tree:\n└── value (Prop)\n\nSee: https://react.dev/learn/you-might-not-need-an-effect#updating-state-based-on-props-or-state","category":"EffectDerivationsOfState","reason":"You might not need an effect. Derive values in render, not effects.","details":[{"kind":"error","loc":{"start":{"line":9,"column":6,"index":271},"end":{"line":9,"column":19,"index":284},"filename":"derived-state-conditionally-in-effect.ts","identifierName":"setLocalValue"},"message":"This should be computed during render, not in an effect"}]}},"fnLoc":null}
60+
{"kind":"CompileSuccess","fnLoc":{"start":{"line":4,"column":0,"index":129},"end":{"line":16,"column":1,"index":412},"filename":"derived-state-conditionally-in-effect.ts"},"fnName":"Component","memoSlots":6,"memoBlocks":2,"memoValues":3,"prunedMemoBlocks":0,"prunedMemoValues":0}
6161
```
6262
6363
### Eval output

0 commit comments

Comments
 (0)