Skip to content

Commit 2c749e9

Browse files
committed
[compiler][ez] Move compiler gating tests
Move all gating tests to `gating/`
1 parent f0635e7 commit 2c749e9

File tree

42 files changed

+399
-163
lines changed

Some content is hidden

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

42 files changed

+399
-163
lines changed

compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ const testComplexConfigDefaults: PartialEnvironmentConfig = {
663663
source: 'react-compiler-runtime',
664664
importSpecifierName: 'shouldInstrument',
665665
},
666-
globalGating: '__DEV__',
666+
globalGating: 'DEV',
667667
},
668668
enableEmitHookGuards: {
669669
source: 'react-compiler-runtime',

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.expect.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/arrow-function-expr-gating-test.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/gating-test-export-function-and-default.js

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
## Input
3+
4+
```javascript
5+
// @gating
6+
import {Stringify} from 'shared-runtime';
7+
const ErrorView = ({error, _retry}) => <Stringify error={error}></Stringify>;
8+
9+
export default ErrorView;
10+
11+
export const FIXTURE_ENTRYPOINT = {
12+
fn: eval('ErrorView'),
13+
params: [{}],
14+
};
15+
16+
```
17+
18+
## Code
19+
20+
```javascript
21+
import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag";
22+
import { c as _c } from "react/compiler-runtime"; // @gating
23+
import { Stringify } from "shared-runtime";
24+
const ErrorView = isForgetEnabled_Fixtures()
25+
? (t0) => {
26+
const $ = _c(2);
27+
const { error } = t0;
28+
let t1;
29+
if ($[0] !== error) {
30+
t1 = <Stringify error={error} />;
31+
$[0] = error;
32+
$[1] = t1;
33+
} else {
34+
t1 = $[1];
35+
}
36+
return t1;
37+
}
38+
: ({ error, _retry }) => <Stringify error={error}></Stringify>;
39+
40+
export default ErrorView;
41+
42+
export const FIXTURE_ENTRYPOINT = {
43+
fn: eval("ErrorView"),
44+
params: [{}],
45+
};
46+
47+
```
48+
49+
### Eval output
50+
(kind: ok) <div>{}</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @gating
2+
import {Stringify} from 'shared-runtime';
3+
const ErrorView = ({error, _retry}) => <Stringify error={error}></Stringify>;
4+
5+
export default ErrorView;
6+
7+
export const FIXTURE_ENTRYPOINT = {
8+
fn: eval('ErrorView'),
9+
params: [{}],
10+
};
Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,22 @@ function NoForget(props) {
1515

1616
function Foo(props) {
1717
'use forget';
18-
return <Foo>{props.bar}</Foo>;
18+
if (props.bar < 0) {
19+
return props.children;
20+
}
21+
return (
22+
<Foo bar={props.bar - 1}>
23+
<NoForget />
24+
</Foo>
25+
);
1926
}
2027

28+
global.DEV = true;
29+
export const FIXTURE_ENTRYPOINT = {
30+
fn: eval('Foo'),
31+
params: [{bar: 2}],
32+
};
33+
2134
```
2235

2336
## Code
@@ -29,7 +42,7 @@ import { c as _c } from "react/compiler-runtime"; // @enableEmitInstrumentForget
2942
const Bar = isForgetEnabled_Fixtures()
3043
? function Bar(props) {
3144
"use forget";
32-
if (__DEV__ && shouldInstrument)
45+
if (DEV && shouldInstrument)
3346
useRenderCounter("Bar", "/codegen-instrument-forget-gating-test.ts");
3447
const $ = _c(2);
3548
let t0;
@@ -53,23 +66,50 @@ function NoForget(props) {
5366
const Foo = isForgetEnabled_Fixtures()
5467
? function Foo(props) {
5568
"use forget";
56-
if (__DEV__ && shouldInstrument)
69+
if (DEV && shouldInstrument)
5770
useRenderCounter("Foo", "/codegen-instrument-forget-gating-test.ts");
58-
const $ = _c(2);
59-
let t0;
60-
if ($[0] !== props.bar) {
61-
t0 = <Foo>{props.bar}</Foo>;
62-
$[0] = props.bar;
71+
const $ = _c(3);
72+
if (props.bar < 0) {
73+
return props.children;
74+
}
75+
76+
const t0 = props.bar - 1;
77+
let t1;
78+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
79+
t1 = <NoForget />;
80+
$[0] = t1;
81+
} else {
82+
t1 = $[0];
83+
}
84+
let t2;
85+
if ($[1] !== t0) {
86+
t2 = <Foo bar={t0}>{t1}</Foo>;
6387
$[1] = t0;
88+
$[2] = t2;
6489
} else {
65-
t0 = $[1];
90+
t2 = $[2];
6691
}
67-
return t0;
92+
return t2;
6893
}
6994
: function Foo(props) {
7095
"use forget";
71-
return <Foo>{props.bar}</Foo>;
96+
if (props.bar < 0) {
97+
return props.children;
98+
}
99+
return (
100+
<Foo bar={props.bar - 1}>
101+
<NoForget />
102+
</Foo>
103+
);
72104
};
73105

106+
global.DEV = true;
107+
export const FIXTURE_ENTRYPOINT = {
108+
fn: eval("Foo"),
109+
params: [{ bar: 2 }],
110+
};
111+
74112
```
75-
113+
114+
### Eval output
115+
(kind: ok) <div></div>
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,18 @@ function NoForget(props) {
1111

1212
function Foo(props) {
1313
'use forget';
14-
return <Foo>{props.bar}</Foo>;
14+
if (props.bar < 0) {
15+
return props.children;
16+
}
17+
return (
18+
<Foo bar={props.bar - 1}>
19+
<NoForget />
20+
</Foo>
21+
);
1522
}
23+
24+
global.DEV = true;
25+
export const FIXTURE_ENTRYPOINT = {
26+
fn: eval('Foo'),
27+
params: [{bar: 2}],
28+
};

0 commit comments

Comments
 (0)