Enable MergeConsecutiveScopes by default
## Test Plan (wip) Sync internally, manually verify code changes and test products.
Joe Savona committed
Oct 9, 2023 at 16:15 UTC
b61dba64ad6ded12e7ae1245861d2a08ec7ac5ff
23 files changed
+171
-320
compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts
+1
-1
@@ -217,6 +217,7 @@ export const DEFAULT_ENVIRONMENT_CONFIG: Readonly<EnvironmentConfig> = {
217
218
memoizeJsxElements: true,
219
validateHooksUsage: true,
220
+ enableMergeConsecutiveScopes: true,
221
222
assertValidMutableRanges: false,
223
bailoutOnHoleyArrays: false,
@@ -224,7 +225,6 @@ export const DEFAULT_ENVIRONMENT_CONFIG: Readonly<EnvironmentConfig> = {
225
enableAssumeHooksFollowRulesOfReact: false,
226
enableEmitFreeze: null,
227
enableForest: false,
227
- enableMergeConsecutiveScopes: false,
228
229
validateFrozenLambdas: false,
230
validateNoSetStateInRender: false,
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-at-mutate-after-capture.expect.md
+3
-10
@@ -21,22 +21,15 @@ function Component(props) {
21
import { unstable_useMemoCache as useMemoCache } from "react"; // x's mutable range should extend to `mutate(y)`
22
23
function Component(props) {
24
- const $ = useMemoCache(2);
24
+ const $ = useMemoCache(1);
25
let t0;
26
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
27
- t0 = {};
27
+ t0 = [42, {}];
28
$[0] = t0;
29
} else {
30
t0 = $[0];
31
}
32
- let t1;
33
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
34
- t1 = [42, t0];
35
- $[1] = t1;
36
- } else {
37
- t1 = $[1];
38
- }
39
- const x = t1;
32
+ const x = t0;
33
const idx = foo(props.b);
34
const y = x.at(idx);
35
mutate(y);
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-join.expect.md
+3
-6
@@ -18,17 +18,14 @@ import { unstable_useMemoCache as useMemoCache } from "react";
18
function Component(props) {
19
const $ = useMemoCache(8);
20
let t0;
21
+ let t1;
22
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
23
t0 = {};
23
- $[0] = t0;
24
- } else {
25
- t0 = $[0];
26
- }
27
- let t1;
28
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
24
t1 = [];
25
+ $[0] = t0;
26
$[1] = t1;
27
} else {
28
+ t0 = $[0];
29
t1 = $[1];
30
}
31
const c_2 = $[2] !== props.value;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/assignment-variations-complex-lvalue-array.expect.md
+3
-10
@@ -22,22 +22,15 @@ export const FIXTURE_ENTRYPOINT = {
22
```javascript
23
import { unstable_useMemoCache as useMemoCache } from "react";
24
function foo() {
25
- const $ = useMemoCache(2);
25
+ const $ = useMemoCache(1);
26
let t0;
27
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
28
- t0 = [1];
28
+ t0 = [[1]];
29
$[0] = t0;
30
} else {
31
t0 = $[0];
32
}
33
- let t1;
34
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
35
- t1 = [t0];
36
- $[1] = t1;
37
- } else {
38
- t1 = $[1];
39
- }
40
- const a = t1;
33
+ const a = t0;
34
const first = a.at(0);
35
first.set(0, 2);
36
return a;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/call-with-independently-memoizable-arg.expect.md
+11
-16
@@ -19,36 +19,31 @@ function Component(props) {
19
```javascript
20
import { unstable_useMemoCache as useMemoCache } from "react";
21
function Component(props) {
22
- const $ = useMemoCache(6);
22
+ const $ = useMemoCache(4);
23
const c_0 = $[0] !== props;
24
- let t2;
24
+ let t1;
25
if (c_0) {
26
const x = makeFunction(props);
27
const c_2 = $[2] !== props.text;
28
let t0;
29
if (c_2) {
30
- t0 = <span>{props.text}</span>;
30
+ t0 = (
31
+ <div>
32
+ <span>{props.text}</span>
33
+ </div>
34
+ );
35
$[2] = props.text;
36
$[3] = t0;
37
} else {
38
t0 = $[3];
39
}
36
- const c_4 = $[4] !== t0;
37
- let t1;
38
- if (c_4) {
39
- t1 = <div>{t0}</div>;
40
- $[4] = t0;
41
- $[5] = t1;
42
- } else {
43
- t1 = $[5];
44
- }
45
- t2 = x(t1);
40
+ t1 = x(t0);
41
$[0] = props;
47
- $[1] = t2;
42
+ $[1] = t1;
43
} else {
49
- t2 = $[1];
44
+ t1 = $[1];
45
}
51
- const y = t2;
46
+ const y = t1;
47
return y;
48
}
49
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-call.expect.md
+3
-12
@@ -23,26 +23,17 @@ export const FIXTURE_ENTRYPOINT = {
23
```javascript
24
import { unstable_useMemoCache as useMemoCache } from "react";
25
function component(a) {
26
- const $ = useMemoCache(4);
26
+ const $ = useMemoCache(2);
27
const c_0 = $[0] !== a;
28
let t0;
29
if (c_0) {
30
- t0 = { a };
30
+ t0 = { a: { a } };
31
$[0] = a;
32
$[1] = t0;
33
} else {
34
t0 = $[1];
35
}
36
- const c_2 = $[2] !== t0;
37
- let t1;
38
- if (c_2) {
39
- t1 = { a: t0 };
40
- $[2] = t0;
41
- $[3] = t1;
42
- } else {
43
- t1 = $[3];
44
- }
45
- const z = t1;
36
+ const z = t0;
37
return z;
38
}
39
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.expect.md
+9
-18
@@ -25,40 +25,31 @@ export const FIXTURE_ENTRYPOINT = {
25
```javascript
26
import { unstable_useMemoCache as useMemoCache } from "react";
27
function component(a) {
28
- const $ = useMemoCache(6);
28
+ const $ = useMemoCache(4);
29
const c_0 = $[0] !== a;
30
let t0;
31
if (c_0) {
32
- t0 = { a };
32
+ t0 = { a: { a } };
33
$[0] = a;
34
$[1] = t0;
35
} else {
36
t0 = $[1];
37
}
38
- const c_2 = $[2] !== t0;
38
+ const z = t0;
39
+ const c_2 = $[2] !== z.a.a;
40
let t1;
41
if (c_2) {
41
- t1 = { a: t0 };
42
- $[2] = t0;
43
- $[3] = t1;
44
- } else {
45
- t1 = $[3];
46
- }
47
- const z = t1;
48
- const c_4 = $[4] !== z.a.a;
49
- let t2;
50
- if (c_4) {
51
- t2 = function () {
42
+ t1 = function () {
43
(function () {
44
console.log(z.a.a);
45
})();
46
};
56
- $[4] = z.a.a;
57
- $[5] = t2;
47
+ $[2] = z.a.a;
48
+ $[3] = t1;
49
} else {
59
- t2 = $[5];
50
+ t1 = $[3];
51
}
61
- const x = t2;
52
+ const x = t1;
53
return x;
54
}
55
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.expect.md
+9
-18
@@ -23,38 +23,29 @@ export const FIXTURE_ENTRYPOINT = {
23
```javascript
24
import { unstable_useMemoCache as useMemoCache } from "react";
25
function component(a) {
26
- const $ = useMemoCache(6);
26
+ const $ = useMemoCache(4);
27
const c_0 = $[0] !== a;
28
let t0;
29
if (c_0) {
30
- t0 = { a };
30
+ t0 = { a: { a } };
31
$[0] = a;
32
$[1] = t0;
33
} else {
34
t0 = $[1];
35
}
36
- const c_2 = $[2] !== t0;
36
+ const z = t0;
37
+ const c_2 = $[2] !== z.a.a;
38
let t1;
39
if (c_2) {
39
- t1 = { a: t0 };
40
- $[2] = t0;
41
- $[3] = t1;
42
- } else {
43
- t1 = $[3];
44
- }
45
- const z = t1;
46
- const c_4 = $[4] !== z.a.a;
47
- let t2;
48
- if (c_4) {
49
- t2 = function () {
40
+ t1 = function () {
41
console.log(z.a.a);
42
};
52
- $[4] = z.a.a;
53
- $[5] = t2;
43
+ $[2] = z.a.a;
44
+ $[3] = t1;
45
} else {
55
- t2 = $[5];
46
+ t1 = $[3];
47
}
57
- const x = t2;
48
+ const x = t1;
49
return x;
50
}
51
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/computed-call-evaluation-order.expect.md
+5
-12
@@ -30,7 +30,7 @@ export const FIXTURE_ENTRYPOINT = {
30
```javascript
31
import { unstable_useMemoCache as useMemoCache } from "react"; // Should print A, B, arg, original
32
function Component() {
33
- const $ = useMemoCache(3);
33
+ const $ = useMemoCache(2);
34
let t0;
35
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36
t0 = (o) => {
@@ -41,23 +41,16 @@ function Component() {
41
t0 = $[0];
42
}
43
const changeF = t0;
44
- let t1;
45
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
46
- t1 = () => console.log("original");
47
- $[1] = t1;
48
- } else {
49
- t1 = $[1];
50
- }
44
let x;
52
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
53
- x = { f: t1 };
45
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
46
+ x = { f: () => console.log("original") };
47
48
(console.log("A"), x)[(console.log("B"), "f")](
49
(changeF(x), console.log("arg"), 1)
50
);
58
- $[2] = x;
51
+ $[1] = x;
52
} else {
60
- x = $[2];
53
+ x = $[1];
54
}
55
return x;
56
}
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbtparam-text-must-use-expression-container.expect.md
+7
-10
@@ -25,22 +25,19 @@ import { unstable_useMemoCache as useMemoCache } from "react";
25
import fbt from "fbt";
26
27
function Component(props) {
28
- const $ = useMemoCache(2);
28
+ const $ = useMemoCache(1);
29
let t0;
30
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
31
- t0 = fbt._("{value}%", [fbt._param("value", "0")], { hk: "10F5Cc" });
31
+ t0 = (
32
+ <Foo
33
+ value={fbt._("{value}%", [fbt._param("value", "0")], { hk: "10F5Cc" })}
34
+ />
35
+ );
36
$[0] = t0;
37
} else {
38
t0 = $[0];
39
}
36
- let t1;
37
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
38
- t1 = <Foo value={t0} />;
39
- $[1] = t1;
40
- } else {
41
- t1 = $[1];
42
- }
43
- return t1;
40
+ return t0;
41
}
42
43
```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbtparam-with-jsx-element-content.expect.md
+27
-32
@@ -29,36 +29,40 @@ import { unstable_useMemoCache as useMemoCache } from "react";
29
import fbt from "fbt";
30
31
function Component(t39) {
32
- const $ = useMemoCache(6);
32
+ const $ = useMemoCache(4);
33
const { name, data, icon } = t39;
34
const c_0 = $[0] !== name;
35
const c_1 = $[1] !== icon;
36
const c_2 = $[2] !== data;
37
let t0;
38
if (c_0 || c_1 || c_2) {
39
- t0 = fbt._(
40
- "{item author}{icon}{=m2}",
41
- [
42
- fbt._param(
43
- "item author",
39
+ t0 = (
40
+ <Text type="body4">
41
+ {fbt._(
42
+ "{item author}{icon}{=m2}",
43
+ [
44
+ fbt._param(
45
+ "item author",
46
45
- <Text type="h4">{name}</Text>
46
- ),
47
- fbt._param(
48
- "icon",
47
+ <Text type="h4">{name}</Text>
48
+ ),
49
+ fbt._param(
50
+ "icon",
51
50
- icon
51
- ),
52
- fbt._implicitParam(
53
- "=m2",
54
- <Text type="h4">
55
- {fbt._("{item details}", [fbt._param("item details", data)], {
56
- hk: "4jLfVq",
57
- })}
58
- </Text>
59
- ),
60
- ],
61
- { hk: "2HLm2j" }
52
+ icon
53
+ ),
54
+ fbt._implicitParam(
55
+ "=m2",
56
+ <Text type="h4">
57
+ {fbt._("{item details}", [fbt._param("item details", data)], {
58
+ hk: "4jLfVq",
59
+ })}
60
+ </Text>
61
+ ),
62
+ ],
63
+ { hk: "2HLm2j" }
64
+ )}
65
+ </Text>
66
);
67
$[0] = name;
68
$[1] = icon;
@@ -67,16 +71,7 @@ function Component(t39) {
71
} else {
72
t0 = $[3];
73
}
70
- const c_4 = $[4] !== t0;
71
- let t1;
72
- if (c_4) {
73
- t1 = <Text type="body4">{t0}</Text>;
74
- $[4] = t0;
75
- $[5] = t1;
76
- } else {
77
- t1 = $[5];
78
- }
79
- return t1;
74
+ return t0;
75
}
76
77
```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbtparam-with-jsx-fragment-value.expect.md
+11
-14
@@ -27,28 +27,25 @@ import fbt from "fbt";
27
import { identity } from "shared-runtime";
28
29
function Component(props) {
30
- const $ = useMemoCache(4);
30
+ const $ = useMemoCache(2);
31
const c_0 = $[0] !== props.text;
32
let t0;
33
if (c_0) {
34
- t0 = fbt._("{value}%", [fbt._param("value", <>{identity(props.text)}</>)], {
35
- hk: "10F5Cc",
36
- });
34
+ t0 = (
35
+ <Foo
36
+ value={fbt._(
37
+ "{value}%",
38
+ [fbt._param("value", <>{identity(props.text)}</>)],
39
+ { hk: "10F5Cc" }
40
+ )}
41
+ />
42
+ );
43
$[0] = props.text;
44
$[1] = t0;
45
} else {
46
t0 = $[1];
47
}
42
- const c_2 = $[2] !== t0;
43
- let t1;
44
- if (c_2) {
45
- t1 = <Foo value={t0} />;
46
- $[2] = t0;
47
- $[3] = t1;
48
- } else {
49
- t1 = $[3];
50
- }
51
- return t1;
48
+ return t0;
49
}
50
51
```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-reassign.expect.md
+5
-12
@@ -23,24 +23,17 @@ export const FIXTURE_ENTRYPOINT = {
23
```javascript
24
import { unstable_useMemoCache as useMemoCache } from "react";
25
function component() {
26
- const $ = useMemoCache(2);
27
- let t0;
26
+ const $ = useMemoCache(1);
27
+ let x;
28
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
29
- t0 = function x(a) {
29
+ x = function x(a) {
30
a.foo();
31
};
32
- $[0] = t0;
33
- } else {
34
- t0 = $[0];
35
- }
36
- let x;
37
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
38
- x = t0;
32
33
x = {};
41
- $[1] = x;
34
+ $[0] = x;
35
} else {
43
- x = $[1];
36
+ x = $[0];
37
}
38
return x;
39
}
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/inner-memo-value-not-promoted-to-outer-scope-static.expect.md
+11
-27
@@ -21,7 +21,7 @@ function Component(props) {
21
```javascript
22
import { unstable_useMemoCache as useMemoCache } from "react";
23
function Component(props) {
24
- const $ = useMemoCache(11);
24
+ const $ = useMemoCache(9);
25
let t1;
26
let T2;
27
let t3;
@@ -62,38 +62,22 @@ function Component(props) {
62
}
63
let t7;
64
if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
65
- t7 = <span>{t1}</span>;
66
- $[8] = t7;
67
- } else {
68
- t7 = $[8];
69
- }
70
- let t8;
71
- if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
72
- t8 = (
73
- <T2>
74
- {t3}
75
- {t0}
76
- {t4}
77
- {t7}
78
- </T2>
79
- );
80
- $[9] = t8;
81
- } else {
82
- t8 = $[9];
83
- }
84
- let t9;
85
- if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
86
- t9 = (
65
+ t7 = (
66
<T5>
67
{t6}
89
- {t8}
68
+ <T2>
69
+ {t3}
70
+ {t0}
71
+ {t4}
72
+ <span>{t1}</span>
73
+ </T2>
74
</T5>
75
);
92
- $[10] = t9;
76
+ $[8] = t7;
77
} else {
94
- t9 = $[10];
78
+ t7 = $[8];
79
}
96
- return t9;
80
+ return t7;
81
}
82
83
```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-fragment.expect.md
+15
-17
@@ -26,36 +26,34 @@ export const FIXTURE_ENTRYPOINT = {
26
```javascript
27
import { unstable_useMemoCache as useMemoCache } from "react";
28
function Foo(props) {
29
- const $ = useMemoCache(4);
29
+ const $ = useMemoCache(3);
30
let t0;
31
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
32
- t0 = <>Text</>;
32
+ t0 = (
33
+ <div>
34
+ <>Text</>
35
+ </div>
36
+ );
37
$[0] = t0;
38
} else {
39
t0 = $[0];
40
}
41
+ const c_1 = $[1] !== props.greeting;
42
let t1;
38
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
39
- t1 = <div>{t0}</div>;
40
- $[1] = t1;
41
- } else {
42
- t1 = $[1];
43
- }
44
- const c_2 = $[2] !== props.greeting;
45
- let t2;
46
- if (c_2) {
47
- t2 = (
43
+ if (c_1) {
44
+ t1 = (
45
<>
49
- Hello {props.greeting} {t1}
46
+ Hello {props.greeting} {t0}
47
</>
48
);
52
- $[2] = props.greeting;
53
- $[3] = t2;
49
+ $[1] = props.greeting;
50
+ $[2] = t1;
51
} else {
55
- t2 = $[3];
52
+ t1 = $[2];
53
}
57
- return t2;
54
+ return t1;
55
}
56
+
57
export const FIXTURE_ENTRYPOINT = {
58
fn: Foo,
59
params: ["TodoAdd"],
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-member-expression.expect.md
+7
-10
@@ -17,22 +17,19 @@ function Component(props) {
17
```javascript
18
import { unstable_useMemoCache as useMemoCache } from "react";
19
function Component(props) {
20
- const $ = useMemoCache(2);
20
+ const $ = useMemoCache(1);
21
let t0;
22
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
23
- t0 = <Foo.Bar.Baz />;
23
+ t0 = (
24
+ <Sathya.Codes.Forget>
25
+ <Foo.Bar.Baz />
26
+ </Sathya.Codes.Forget>
27
+ );
28
$[0] = t0;
29
} else {
30
t0 = $[0];
31
}
28
- let t1;
29
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
30
- t1 = <Sathya.Codes.Forget>{t0}</Sathya.Codes.Forget>;
31
- $[1] = t1;
32
- } else {
33
- t1 = $[1];
34
- }
35
- return t1;
32
+ return t0;
33
}
34
35
```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-ternary-local-variable.expect.md
+3
-21
@@ -24,36 +24,18 @@ import { unstable_useMemoCache as useMemoCache } from "react";
24
import { RenderPropAsChild, StaticText1, StaticText2 } from "shared-runtime";
25
26
function Component(props) {
27
- const $ = useMemoCache(6);
27
+ const $ = useMemoCache(2);
28
const Foo = props.showText1 ? StaticText1 : StaticText2;
29
const c_0 = $[0] !== Foo;
30
let t0;
31
if (c_0) {
32
- t0 = () => <Foo key="0" />;
32
+ t0 = <RenderPropAsChild items={[() => <Foo key="0" />]} />;
33
$[0] = Foo;
34
$[1] = t0;
35
} else {
36
t0 = $[1];
37
}
38
- const c_2 = $[2] !== t0;
39
- let t1;
40
- if (c_2) {
41
- t1 = [t0];
42
- $[2] = t0;
43
- $[3] = t1;
44
- } else {
45
- t1 = $[3];
46
- }
47
- const c_4 = $[4] !== t1;
48
- let t2;
49
- if (c_4) {
50
- t2 = <RenderPropAsChild items={t1} />;
51
- $[4] = t1;
52
- $[5] = t2;
53
- } else {
54
- t2 = $[5];
55
- }
56
- return t2;
38
+ return t0;
39
}
40
41
export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-with-fbt.expect.md
+7
-10
@@ -42,7 +42,7 @@ import { unstable_useMemoCache as useMemoCache } from "react";
42
import { fbt } from "fbt";
43
44
function Component() {
45
- const $ = useMemoCache(4);
45
+ const $ = useMemoCache(3);
46
let t0;
47
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
48
t0 = () => {
@@ -80,19 +80,16 @@ function Component() {
80
}
81
let t2;
82
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
83
- t2 = <Button text={t1} />;
83
+ t2 = (
84
+ <View>
85
+ <Button text={t1} />
86
+ </View>
87
+ );
88
$[2] = t2;
89
} else {
90
t2 = $[2];
91
}
88
- let t3;
89
- if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
90
- t3 = <View>{t2}</View>;
91
- $[3] = t3;
92
- } else {
93
- t3 = $[3];
94
- }
95
- return t3;
92
+ return t2;
93
}
94
95
```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multi-arrow-expr-export-default-gating-test.expect.md
+6
-13
@@ -37,7 +37,7 @@ const ErrorView = isForgetEnabled_Fixtures()
37
38
export default Renderer = isForgetEnabled_Fixtures()
39
? (props) => {
40
- const $ = useMemoCache(3);
40
+ const $ = useMemoCache(2);
41
let t0;
42
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
43
t0 = <Bar />;
@@ -47,24 +47,17 @@ export default Renderer = isForgetEnabled_Fixtures()
47
}
48
let t1;
49
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
50
- t1 = <ErrorView />;
51
- $[1] = t1;
52
- } else {
53
- t1 = $[1];
54
- }
55
- let t2;
56
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
57
- t2 = (
50
+ t1 = (
51
<Foo>
52
{t0}
60
- {t1}
53
+ <ErrorView />
54
</Foo>
55
);
63
- $[2] = t2;
56
+ $[1] = t1;
57
} else {
65
- t2 = $[2];
58
+ t1 = $[1];
59
}
67
- return t2;
60
+ return t1;
61
}
62
: (props) => (
63
<Foo>
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.expect.md
+6
-13
@@ -37,7 +37,7 @@ const ErrorView = isForgetEnabled_Fixtures()
37
38
export const Renderer = isForgetEnabled_Fixtures()
39
? (props) => {
40
- const $ = useMemoCache(3);
40
+ const $ = useMemoCache(2);
41
let t0;
42
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
43
t0 = <Bar />;
@@ -47,24 +47,17 @@ export const Renderer = isForgetEnabled_Fixtures()
47
}
48
let t1;
49
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
50
- t1 = <ErrorView />;
51
- $[1] = t1;
52
- } else {
53
- t1 = $[1];
54
- }
55
- let t2;
56
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
57
- t2 = (
50
+ t1 = (
51
<Foo>
52
{t0}
60
- {t1}
53
+ <ErrorView />
54
</Foo>
55
);
63
- $[2] = t2;
56
+ $[1] = t1;
57
} else {
65
- t2 = $[2];
58
+ t1 = $[1];
59
}
67
- return t2;
60
+ return t1;
61
}
62
: (props) => (
63
<Foo>
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.expect.md
+6
-13
@@ -39,7 +39,7 @@ const ErrorView = isForgetEnabled_Fixtures()
39
40
const Renderer = isForgetEnabled_Fixtures()
41
? (props) => {
42
- const $ = useMemoCache(3);
42
+ const $ = useMemoCache(2);
43
let t0;
44
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
45
t0 = <Bar />;
@@ -49,24 +49,17 @@ const Renderer = isForgetEnabled_Fixtures()
49
}
50
let t1;
51
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
52
- t1 = <ErrorView />;
53
- $[1] = t1;
54
- } else {
55
- t1 = $[1];
56
- }
57
- let t2;
58
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
59
- t2 = (
52
+ t1 = (
53
<Foo>
54
{t0}
62
- {t1}
55
+ <ErrorView />
56
</Foo>
57
);
65
- $[2] = t2;
58
+ $[1] = t1;
59
} else {
67
- t2 = $[2];
60
+ t1 = $[1];
61
}
69
- return t2;
62
+ return t1;
63
}
64
: (props) => (
65
<Foo>
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/property-call-evaluation-order.expect.md
+5
-12
@@ -30,7 +30,7 @@ export const FIXTURE_ENTRYPOINT = {
30
import { unstable_useMemoCache as useMemoCache } from "react"; // Should print A, arg, original
31
32
function Component() {
33
- const $ = useMemoCache(3);
33
+ const $ = useMemoCache(2);
34
let t0;
35
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36
t0 = (o) => {
@@ -41,21 +41,14 @@ function Component() {
41
t0 = $[0];
42
}
43
const changeF = t0;
44
- let t1;
45
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
46
- t1 = () => console.log("original");
47
- $[1] = t1;
48
- } else {
49
- t1 = $[1];
50
- }
44
let x;
52
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
53
- x = { f: t1 };
45
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
46
+ x = { f: () => console.log("original") };
47
48
(console.log("A"), x).f((changeF(x), console.log("arg"), 1));
56
- $[2] = x;
49
+ $[1] = x;
50
} else {
58
- x = $[2];
51
+ x = $[1];
52
}
53
return x;
54
}
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useEffect-arg-memoized.expect.md
+8
-13
@@ -26,7 +26,7 @@ function Component(props) {
26
```javascript
27
import { unstable_useMemoCache as useMemoCache } from "react";
28
function Component(props) {
29
- const $ = useMemoCache(7);
29
+ const $ = useMemoCache(6);
30
const dispatch = useDispatch();
31
useFreeze(dispatch);
32
const c_0 = $[0] !== dispatch;
@@ -43,31 +43,26 @@ function Component(props) {
43
const onUpdate = t0;
44
const c_2 = $[2] !== onUpdate;
45
let t1;
46
+ let t2;
47
if (c_2) {
48
t1 = () => {
49
onUpdate();
50
};
51
+ t2 = [onUpdate];
52
$[2] = onUpdate;
53
$[3] = t1;
54
+ $[4] = t2;
55
} else {
56
t1 = $[3];
54
- }
55
- const c_4 = $[4] !== onUpdate;
56
- let t2;
57
- if (c_4) {
58
- t2 = [onUpdate];
59
- $[4] = onUpdate;
60
- $[5] = t2;
61
- } else {
62
- t2 = $[5];
57
+ t2 = $[4];
58
}
59
useEffect(t1, t2);
60
let t3;
66
- if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
61
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
62
t3 = <div />;
68
- $[6] = t3;
63
+ $[5] = t3;
64
} else {
70
- t3 = $[6];
65
+ t3 = $[5];
66
}
67
return t3;
68
}