@samitouri / QOS-React-1 / commits / 4779fa0f81

Wrap MergeConsecutiveScopes in a feature flag

I should have done this originally, but figured if there were issues on the sync we could just do it then. Here we are!

Joe Savona committed Oct 2, 2023 at 15:46 UTC 4779fa0f8101233a90e1959d80b000d54fa25436
42 files changed +589 -266
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Pipeline.ts
+8 -6
@@ -270,12 +270,14 @@ export function* run(
270 value: reactiveFunction,
271 });
272
273 - mergeConsecutiveScopes(reactiveFunction);
274 - yield log({
275 - kind: "reactive",
276 - name: "MergeConsecutiveScopes",
277 - value: reactiveFunction,
278 - });
273 + if (env.enableMergeConsecutiveScopes) {
274 + mergeConsecutiveScopes(reactiveFunction);
275 + yield log({
276 + kind: "reactive",
277 + name: "MergeConsecutiveScopes",
278 + value: reactiveFunction,
279 + });
280 + }
281
282 if (config?.enableForest) {
283 yield* lowerToForest(reactiveFunction);
compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts
+10
@@ -208,6 +208,13 @@ export type EnvironmentConfig = Partial<{
208 */
209 enableEmitFreeze: ExternalFunction | null;
210
211 + /**
212 + * Enable merging consecutive scopes that invalidate together.
213 + *
214 + * Defaults to false.
215 + */
216 + enableMergeConsecutiveScopes: boolean;
217 +
218 /**
219 * Enable validation of mutable ranges
220 *
@@ -253,6 +260,7 @@ export class Environment {
260 enableNoAliasOptimizations: boolean;
261 disableAllMemoization: boolean;
262 enableEmitFreeze: ExternalFunction | null;
263 + enableMergeConsecutiveScopes: boolean;
264 assertValidMutableRanges: boolean;
265 bailoutOnHoleyArrays: boolean;
266 enableForest: boolean;
@@ -307,6 +315,8 @@ export class Environment {
315 config?.enableTreatHooksAsFunctions ?? true;
316 this.disableAllMemoization = config?.disableAllMemoization ?? false;
317 this.enableEmitFreeze = config?.enableEmitFreeze ?? null;
318 + this.enableMergeConsecutiveScopes =
319 + config?.enableMergeConsecutiveScopes ?? false;
320 this.assertValidMutableRanges = config?.assertValidMutableRanges ?? false;
321 this.validateNoSetStateInRender =
322 config?.validateNoSetStateInRender ?? false;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/alias-capture-in-method-receiver-and-mutate.expect.md
+15 -6
@@ -31,19 +31,28 @@ import { unstable_useMemoCache as useMemoCache } from "react";
31 import { makeObject_Primitives, mutate } from "shared-runtime";
32
33 function Component() {
34 - const $ = useMemoCache(1);
35 - let t0;
34 + const $ = useMemoCache(3);
35 + let x;
36 + let a;
37 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
37 - const a = makeObject_Primitives();
38 + a = makeObject_Primitives();
39
39 - const x = [];
40 + x = [];
41 x.push(a);
42
43 mutate(x);
44 + $[0] = x;
45 + $[1] = a;
46 + } else {
47 + x = $[0];
48 + a = $[1];
49 + }
50 + let t0;
51 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
52 t0 = [x, a];
44 - $[0] = t0;
53 + $[2] = t0;
54 } else {
46 - t0 = $[0];
55 + t0 = $[2];
56 }
57 return t0;
58 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/alias-capture-in-method-receiver.expect.md
+11 -6
@@ -20,7 +20,7 @@ function Component() {
20 ```javascript
21 import { unstable_useMemoCache as useMemoCache } from "react";
22 function Component() {
23 - const $ = useMemoCache(2);
23 + const $ = useMemoCache(3);
24 let t0;
25 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
26 t0 = someObj();
@@ -29,15 +29,20 @@ function Component() {
29 t0 = $[0];
30 }
31 const a = t0;
32 - let t1;
32 + let x;
33 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
34 - const x = [];
34 + x = [];
35 x.push(a);
36 -
36 + $[1] = x;
37 + } else {
38 + x = $[1];
39 + }
40 + let t1;
41 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
42 t1 = [x, a];
38 - $[1] = t1;
43 + $[2] = t1;
44 } else {
40 - t1 = $[1];
45 + t1 = $[2];
46 }
47 return t1;
48 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/alias-nested-member-path.expect.md
+11 -5
@@ -24,7 +24,7 @@ export const FIXTURE_ENTRYPOINT = {
24 ```javascript
25 import { unstable_useMemoCache as useMemoCache } from "react";
26 function component() {
27 - const $ = useMemoCache(2);
27 + const $ = useMemoCache(3);
28 let t0;
29 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
30 t0 = [];
@@ -33,15 +33,21 @@ function component() {
33 t0 = $[0];
34 }
35 const z = t0;
36 - let x;
36 + let y;
37 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
38 - const y = {};
38 + y = {};
39 y.z = z;
40 + $[1] = y;
41 + } else {
42 + y = $[1];
43 + }
44 + let x;
45 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
46 x = {};
47 x.y = y;
42 - $[1] = x;
48 + $[2] = x;
49 } else {
44 - x = $[1];
50 + x = $[2];
51 }
52 return x;
53 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-at-mutate-after-capture.expect.md
+10 -3
@@ -21,15 +21,22 @@ 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(1);
24 + const $ = useMemoCache(2);
25 let t0;
26 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
27 - t0 = [42, {}];
27 + t0 = {};
28 $[0] = t0;
29 } else {
30 t0 = $[0];
31 }
32 - const x = t0;
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;
40 const idx = foo(props.b);
41 const y = x.at(idx);
42 mutate(y);
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/array-join.expect.md
+6 -3
@@ -18,14 +18,17 @@ import { unstable_useMemoCache as useMemoCache } from "react";
18 function Component(props) {
19 const $ = useMemoCache(8);
20 let t0;
21 - let t1;
21 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
22 t0 = {};
24 - t1 = [];
23 $[0] = t0;
26 - $[1] = t1;
24 } else {
25 t0 = $[0];
26 + }
27 + let t1;
28 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
29 + t1 = [];
30 + $[1] = t1;
31 + } else {
32 t1 = $[1];
33 }
34 const c_2 = $[2] !== props.value;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/assignment-variations-complex-lvalue-array.expect.md
+10 -3
@@ -22,15 +22,22 @@ export const FIXTURE_ENTRYPOINT = {
22 ```javascript
23 import { unstable_useMemoCache as useMemoCache } from "react";
24 function foo() {
25 - const $ = useMemoCache(1);
25 + const $ = useMemoCache(2);
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 - const a = t0;
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;
41 const first = a.at(0);
42 first.set(0, 2);
43 return a;
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/builtin-jsx-tag-lowered-between-mutations.expect.md
+10 -3
@@ -14,16 +14,23 @@ function Component(props) {
14 ```javascript
15 import { unstable_useMemoCache as useMemoCache } from "react";
16 function Component(props) {
17 - const $ = useMemoCache(1);
17 + const $ = useMemoCache(2);
18 let t0;
19 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
20 const maybeMutable = new MaybeMutable();
21 - t0 = <div>{maybeMutate(maybeMutable)}</div>;
21 + t0 = maybeMutate(maybeMutable);
22 $[0] = t0;
23 } else {
24 t0 = $[0];
25 }
26 - return t0;
26 + let t1;
27 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
28 + t1 = <div>{t0}</div>;
29 + $[1] = t1;
30 + } else {
31 + t1 = $[1];
32 + }
33 + return t1;
34 }
35
36 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/call-with-independently-memoizable-arg.expect.md
+16 -11
@@ -19,31 +19,36 @@ function Component(props) {
19 ```javascript
20 import { unstable_useMemoCache as useMemoCache } from "react";
21 function Component(props) {
22 - const $ = useMemoCache(4);
22 + const $ = useMemoCache(6);
23 const c_0 = $[0] !== props;
24 - let t1;
24 + let t2;
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 = (
31 - <div>
32 - <span>{props.text}</span>
33 - </div>
34 - );
30 + t0 = <span>{props.text}</span>;
31 $[2] = props.text;
32 $[3] = t0;
33 } else {
34 t0 = $[3];
35 }
40 - t1 = x(t0);
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);
46 $[0] = props;
42 - $[1] = t1;
47 + $[1] = t2;
48 } else {
44 - t1 = $[1];
49 + t2 = $[1];
50 }
46 - const y = t1;
51 + const y = t2;
52 return y;
53 }
54
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/call.expect.md
+15 -6
@@ -22,18 +22,27 @@ import { unstable_useMemoCache as useMemoCache } from "react";
22 function foo() {}
23
24 function Component(props) {
25 - const $ = useMemoCache(1);
26 - let t0;
25 + const $ = useMemoCache(3);
26 + let a;
27 + let b;
28 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
28 - const a = [];
29 - const b = {};
29 + a = [];
30 + b = {};
31 foo(a, b);
32
33 foo(b);
34 + $[0] = a;
35 + $[1] = b;
36 + } else {
37 + a = $[0];
38 + b = $[1];
39 + }
40 + let t0;
41 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
42 t0 = <div a={a} b={b} />;
34 - $[0] = t0;
43 + $[2] = t0;
44 } else {
36 - t0 = $[0];
45 + t0 = $[2];
46 }
47 return t0;
48 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-call.expect.md
+12 -3
@@ -23,17 +23,26 @@ export const FIXTURE_ENTRYPOINT = {
23 ```javascript
24 import { unstable_useMemoCache as useMemoCache } from "react";
25 function component(a) {
26 - const $ = useMemoCache(2);
26 + const $ = useMemoCache(4);
27 const c_0 = $[0] !== a;
28 let t0;
29 if (c_0) {
30 - t0 = { a: { a } };
30 + t0 = { a };
31 $[0] = a;
32 $[1] = t0;
33 } else {
34 t0 = $[1];
35 }
36 - const z = t0;
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;
46 return z;
47 }
48
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.expect.md
+18 -9
@@ -25,31 +25,40 @@ export const FIXTURE_ENTRYPOINT = {
25 ```javascript
26 import { unstable_useMemoCache as useMemoCache } from "react";
27 function component(a) {
28 - const $ = useMemoCache(4);
28 + const $ = useMemoCache(6);
29 const c_0 = $[0] !== a;
30 let t0;
31 if (c_0) {
32 - t0 = { a: { a } };
32 + t0 = { a };
33 $[0] = a;
34 $[1] = t0;
35 } else {
36 t0 = $[1];
37 }
38 - const z = t0;
39 - const c_2 = $[2] !== z.a.a;
38 + const c_2 = $[2] !== t0;
39 let t1;
40 if (c_2) {
42 - t1 = function () {
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 () {
52 (function () {
53 console.log(z.a.a);
54 })();
55 };
47 - $[2] = z.a.a;
48 - $[3] = t1;
56 + $[4] = z.a.a;
57 + $[5] = t2;
58 } else {
50 - t1 = $[3];
59 + t2 = $[5];
60 }
52 - const x = t1;
61 + const x = t2;
62 return x;
63 }
64
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.expect.md
+18 -9
@@ -23,29 +23,38 @@ 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(6);
27 const c_0 = $[0] !== a;
28 let t0;
29 if (c_0) {
30 - t0 = { a: { a } };
30 + t0 = { a };
31 $[0] = a;
32 $[1] = t0;
33 } else {
34 t0 = $[1];
35 }
36 - const z = t0;
37 - const c_2 = $[2] !== z.a.a;
36 + const c_2 = $[2] !== t0;
37 let t1;
38 if (c_2) {
40 - t1 = function () {
41 - console.log(z.a.a);
42 - };
43 - $[2] = z.a.a;
39 + t1 = { a: t0 };
40 + $[2] = t0;
41 $[3] = t1;
42 } else {
43 t1 = $[3];
44 }
48 - const x = t1;
45 + const z = t1;
46 + const c_4 = $[4] !== z.a.a;
47 + let t2;
48 + if (c_4) {
49 + t2 = function () {
50 + console.log(z.a.a);
51 + };
52 + $[4] = z.a.a;
53 + $[5] = t2;
54 + } else {
55 + t2 = $[5];
56 + }
57 + const x = t2;
58 return x;
59 }
60
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/computed-call-evaluation-order.expect.md
+12 -5
@@ -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(2);
33 + const $ = useMemoCache(3);
34 let t0;
35 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36 t0 = (o) => {
@@ -41,16 +41,23 @@ function Component() {
41 t0 = $[0];
42 }
43 const changeF = t0;
44 - let x;
44 + let t1;
45 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
46 - x = { f: () => console.log("original") };
46 + t1 = () => console.log("original");
47 + $[1] = t1;
48 + } else {
49 + t1 = $[1];
50 + }
51 + let x;
52 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
53 + x = { f: t1 };
54
55 (console.log("A"), x)[(console.log("B"), "f")](
56 (changeF(x), console.log("arg"), 1)
57 );
51 - $[1] = x;
58 + $[2] = x;
59 } else {
53 - x = $[1];
60 + x = $[2];
61 }
62 return x;
63 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constructor.expect.md
+15 -6
@@ -22,17 +22,26 @@ import { unstable_useMemoCache as useMemoCache } from "react";
22 function Foo() {}
23
24 function Component(props) {
25 - const $ = useMemoCache(1);
26 - let t0;
25 + const $ = useMemoCache(3);
26 + let a;
27 + let b;
28 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
28 - const a = [];
29 - const b = {};
29 + a = [];
30 + b = {};
31 new Foo(a, b);
32 new Foo(b);
33 + $[0] = a;
34 + $[1] = b;
35 + } else {
36 + a = $[0];
37 + b = $[1];
38 + }
39 + let t0;
40 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
41 t0 = <div a={a} b={b} />;
33 - $[0] = t0;
42 + $[2] = t0;
43 } else {
35 - t0 = $[0];
44 + t0 = $[2];
45 }
46 return t0;
47 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbtparam-text-must-use-expression-container.expect.md
+10 -7
@@ -25,19 +25,22 @@ import { unstable_useMemoCache as useMemoCache } from "react";
25 import fbt from "fbt";
26
27 function Component(props) {
28 - const $ = useMemoCache(1);
28 + const $ = useMemoCache(2);
29 let t0;
30 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
31 - t0 = (
32 - <Foo
33 - value={fbt._("{value}%", [fbt._param("value", "0")], { hk: "10F5Cc" })}
34 - />
35 - );
31 + t0 = fbt._("{value}%", [fbt._param("value", "0")], { hk: "10F5Cc" });
32 $[0] = t0;
33 } else {
34 t0 = $[0];
35 }
40 - return t0;
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;
44 }
45
46 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbtparam-with-jsx-element-content.expect.md
+32 -27
@@ -29,40 +29,36 @@ import { unstable_useMemoCache as useMemoCache } from "react";
29 import fbt from "fbt";
30
31 function Component(t39) {
32 - const $ = useMemoCache(4);
32 + const $ = useMemoCache(6);
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 = (
40 - <Text type="body4">
41 - {fbt._(
42 - "{item author}{icon}{=m2}",
43 - [
44 - fbt._param(
45 - "item author",
39 + t0 = fbt._(
40 + "{item author}{icon}{=m2}",
41 + [
42 + fbt._param(
43 + "item author",
44
47 - <Text type="h4">{name}</Text>
48 - ),
49 - fbt._param(
50 - "icon",
45 + <Text type="h4">{name}</Text>
46 + ),
47 + fbt._param(
48 + "icon",
49
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>
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" }
62 );
63 $[0] = name;
64 $[1] = icon;
@@ -71,7 +67,16 @@ function Component(t39) {
67 } else {
68 t0 = $[3];
69 }
74 - return t0;
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;
80 }
81
82 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/fbtparam-with-jsx-fragment-value.expect.md
+14 -11
@@ -27,25 +27,28 @@ import fbt from "fbt";
27 import { identity } from "shared-runtime";
28
29 function Component(props) {
30 - const $ = useMemoCache(2);
30 + const $ = useMemoCache(4);
31 const c_0 = $[0] !== props.text;
32 let t0;
33 if (c_0) {
34 - t0 = (
35 - <Foo
36 - value={fbt._(
37 - "{value}%",
38 - [fbt._param("value", <>{identity(props.text)}</>)],
39 - { hk: "10F5Cc" }
40 - )}
41 - />
42 - );
34 + t0 = fbt._("{value}%", [fbt._param("value", <>{identity(props.text)}</>)], {
35 + hk: "10F5Cc",
36 + });
37 $[0] = props.text;
38 $[1] = t0;
39 } else {
40 t0 = $[1];
41 }
48 - return t0;
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;
52 }
53
54 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/for-of-mutate.expect.md
+11 -6
@@ -28,19 +28,24 @@ import { unstable_useMemoCache as useMemoCache } from "react";
28 import { makeObject_Primitives, mutate, Stringify } from "shared-runtime";
29
30 function Component(_props) {
31 - const $ = useMemoCache(1);
32 - let t0;
31 + const $ = useMemoCache(2);
32 + let results;
33 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
34 const collection = [makeObject_Primitives()];
35 - const results = [];
35 + results = [];
36 for (const item of collection) {
37 results.push(<div key={Stringify(item)}>{Stringify(mutate(item))}</div>);
38 }
39 -
39 + $[0] = results;
40 + } else {
41 + results = $[0];
42 + }
43 + let t0;
44 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
45 t0 = <div>{results}</div>;
41 - $[0] = t0;
46 + $[1] = t0;
47 } else {
43 - t0 = $[0];
48 + t0 = $[1];
49 }
50 return t0;
51 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-reassign.expect.md
+12 -5
@@ -23,17 +23,24 @@ export const FIXTURE_ENTRYPOINT = {
23 ```javascript
24 import { unstable_useMemoCache as useMemoCache } from "react";
25 function component() {
26 - const $ = useMemoCache(1);
27 - let x;
26 + const $ = useMemoCache(2);
27 + let t0;
28 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
29 - x = function x(a) {
29 + t0 = 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;
39
40 x = {};
34 - $[0] = x;
41 + $[1] = x;
42 } else {
36 - x = $[0];
43 + x = $[1];
44 }
45 return x;
46 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/global-jsx-tag-lowered-between-mutations.expect.md
+17 -6
@@ -25,17 +25,28 @@ function Component(props) {
25 ```javascript
26 import { unstable_useMemoCache as useMemoCache } from "react";
27 function Component(props) {
28 - const $ = useMemoCache(1);
29 - let t0;
28 + const $ = useMemoCache(3);
29 + let T0;
30 + let t1;
31 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
32 const maybeMutable = new MaybeMutable();
33
33 - t0 = <View>{maybeMutate(maybeMutable)}</View>;
34 - $[0] = t0;
34 + T0 = View;
35 + t1 = maybeMutate(maybeMutable);
36 + $[0] = T0;
37 + $[1] = t1;
38 } else {
36 - t0 = $[0];
39 + T0 = $[0];
40 + t1 = $[1];
41 }
38 - return t0;
42 + let t2;
43 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
44 + t2 = <T0>{t1}</T0>;
45 + $[2] = t2;
46 + } else {
47 + t2 = $[2];
48 + }
49 + return t2;
50 }
51
52 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/hoisting-simple-const-declaration.expect.md
+11 -5
@@ -24,17 +24,23 @@ export const FIXTURE_ENTRYPOINT = {
24 ```javascript
25 import { unstable_useMemoCache as useMemoCache } from "react";
26 function hoisting() {
27 - const $ = useMemoCache(1);
28 - let t0;
27 + const $ = useMemoCache(2);
28 + let foo;
29 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
30 - const foo = () => bar + baz;
30 + foo = () => bar + baz;
31
32 const bar = 3;
33 const baz = 2;
34 + $[0] = foo;
35 + } else {
36 + foo = $[0];
37 + }
38 + let t0;
39 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
40 t0 = foo();
35 - $[0] = t0;
41 + $[1] = t0;
42 } else {
37 - t0 = $[0];
43 + t0 = $[1];
44 }
45 return t0;
46 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/inner-memo-value-not-promoted-to-outer-scope-static.expect.md
+63 -14
@@ -21,30 +21,79 @@ function Component(props) {
21 ```javascript
22 import { unstable_useMemoCache as useMemoCache } from "react";
23 function Component(props) {
24 - const $ = useMemoCache(2);
24 + const $ = useMemoCache(11);
25 let t1;
26 + let T2;
27 + let t3;
28 + let t0;
29 + let t4;
30 + let T5;
31 + let t6;
32 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
33 const count = new MaybeMutable();
28 - let t0;
29 - if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
34 +
35 + T5 = View;
36 + t6 = "\n ";
37 + T2 = View;
38 + t3 = "\n ";
39 + if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
40 t0 = <span>Text</span>;
31 - $[1] = t0;
41 + $[7] = t0;
42 } else {
33 - t0 = $[1];
43 + t0 = $[7];
44 }
35 - t1 = (
36 - <View>
37 - <View>
38 - {t0}
39 - <span>{maybeMutate(count)}</span>
40 - </View>
41 - </View>
42 - );
45 + t4 = "\n ";
46 + t1 = maybeMutate(count);
47 $[0] = t1;
48 + $[1] = T2;
49 + $[2] = t3;
50 + $[3] = t0;
51 + $[4] = t4;
52 + $[5] = T5;
53 + $[6] = t6;
54 } else {
55 t1 = $[0];
56 + T2 = $[1];
57 + t3 = $[2];
58 + t0 = $[3];
59 + t4 = $[4];
60 + T5 = $[5];
61 + t6 = $[6];
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 = (
87 + <T5>
88 + {t6}
89 + {t8}
90 + </T5>
91 + );
92 + $[10] = t9;
93 + } else {
94 + t9 = $[10];
95 }
47 - return t1;
96 + return t9;
97 }
98
99 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-fragment.expect.md
+17 -15
@@ -26,34 +26,36 @@ export const FIXTURE_ENTRYPOINT = {
26 ```javascript
27 import { unstable_useMemoCache as useMemoCache } from "react";
28 function Foo(props) {
29 - const $ = useMemoCache(3);
29 + const $ = useMemoCache(4);
30 let t0;
31 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
32 - t0 = (
33 - <div>
34 - <>Text</>
35 - </div>
36 - );
32 + t0 = <>Text</>;
33 $[0] = t0;
34 } else {
35 t0 = $[0];
36 }
41 - const c_1 = $[1] !== props.greeting;
37 let t1;
43 - if (c_1) {
44 - 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 = (
48 <>
46 - Hello {props.greeting} {t0}
49 + Hello {props.greeting} {t1}
50 </>
51 );
49 - $[1] = props.greeting;
50 - $[2] = t1;
52 + $[2] = props.greeting;
53 + $[3] = t2;
54 } else {
52 - t1 = $[2];
55 + t2 = $[3];
56 }
54 - return t1;
57 + return t2;
58 }
56 -
59 export const FIXTURE_ENTRYPOINT = {
60 fn: Foo,
61 params: ["TodoAdd"],
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-member-expression-tag-grouping.expect.md
+17 -6
@@ -14,16 +14,27 @@ function Component(props) {
14 ```javascript
15 import { unstable_useMemoCache as useMemoCache } from "react";
16 function Component(props) {
17 - const $ = useMemoCache(1);
18 - let t0;
17 + const $ = useMemoCache(3);
18 + let T0;
19 + let t1;
20 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
21 const maybeMutable = new MaybeMutable();
21 - t0 = <Foo.Bar>{maybeMutate(maybeMutable)}</Foo.Bar>;
22 - $[0] = t0;
22 + T0 = Foo.Bar;
23 + t1 = maybeMutate(maybeMutable);
24 + $[0] = T0;
25 + $[1] = t1;
26 } else {
24 - t0 = $[0];
27 + T0 = $[0];
28 + t1 = $[1];
29 }
26 - return t0;
30 + let t2;
31 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
32 + t2 = <T0>{t1}</T0>;
33 + $[2] = t2;
34 + } else {
35 + t2 = $[2];
36 + }
37 + return t2;
38 }
39
40 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/jsx-member-expression.expect.md
+10 -7
@@ -17,19 +17,22 @@ function Component(props) {
17 ```javascript
18 import { unstable_useMemoCache as useMemoCache } from "react";
19 function Component(props) {
20 - const $ = useMemoCache(1);
20 + const $ = useMemoCache(2);
21 let t0;
22 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
23 - t0 = (
24 - <Sathya.Codes.Forget>
25 - <Foo.Bar.Baz />
26 - </Sathya.Codes.Forget>
27 - );
23 + t0 = <Foo.Bar.Baz />;
24 $[0] = t0;
25 } else {
26 t0 = $[0];
27 }
32 - return t0;
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;
36 }
37
38 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-with-fbt.expect.md
+17 -7
@@ -42,7 +42,7 @@ import { unstable_useMemoCache as useMemoCache } from "react";
42 import { fbt } from "fbt";
43
44 function Component() {
45 - const $ = useMemoCache(2);
45 + const $ = useMemoCache(4);
46 let t0;
47 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
48 t0 = () => {
@@ -73,16 +73,26 @@ function Component() {
73 const buttonLabel = t0;
74 let t1;
75 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
76 - t1 = (
77 - <View>
78 - <Button text={buttonLabel()} />
79 - </View>
80 - );
76 + t1 = buttonLabel();
77 $[1] = t1;
78 } else {
79 t1 = $[1];
80 }
85 - return t1;
81 + let t2;
82 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
83 + t2 = <Button text={t1} />;
84 + $[2] = t2;
85 + } else {
86 + t2 = $[2];
87 + }
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;
96 }
97
98 ```
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/merge-consecutive-scopes.expect.md
+2 -1
@@ -2,6 +2,7 @@
2 ## Input
3
4 ```javascript
5 +// @enableMergeConsecutiveScopes
6 function Component() {
7 let [state, setState] = useState(0);
8 return (
@@ -25,7 +26,7 @@ export const FIXTURE_ENTRYPOINT = {
26 ## Code
27
28 ```javascript
28 -import { unstable_useMemoCache as useMemoCache } from "react";
29 +import { unstable_useMemoCache as useMemoCache } from "react"; // @enableMergeConsecutiveScopes
30 function Component() {
31 const $ = useMemoCache(8);
32 const [state, setState] = useState(0);
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/merge-consecutive-scopes.js
+1
@@ -1,3 +1,4 @@
1 +// @enableMergeConsecutiveScopes
2 function Component() {
3 let [state, setState] = useState(0);
4 return (
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multi-arrow-expr-export-default-gating-test.expect.md
+13 -6
@@ -37,7 +37,7 @@ const ErrorView = isForgetEnabled_Fixtures()
37
38 export default Renderer = isForgetEnabled_Fixtures()
39 ? (props) => {
40 - const $ = useMemoCache(2);
40 + const $ = useMemoCache(3);
41 let t0;
42 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
43 t0 = <Bar />;
@@ -47,17 +47,24 @@ export default Renderer = isForgetEnabled_Fixtures()
47 }
48 let t1;
49 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
50 - t1 = (
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 = (
58 <Foo>
59 {t0}
53 - <ErrorView />
60 + {t1}
61 </Foo>
62 );
56 - $[1] = t1;
63 + $[2] = t2;
64 } else {
58 - t1 = $[1];
65 + t2 = $[2];
66 }
60 - return t1;
67 + return t2;
68 }
69 : (props) => (
70 <Foo>
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multi-arrow-expr-export-gating-test.expect.md
+13 -6
@@ -37,7 +37,7 @@ const ErrorView = isForgetEnabled_Fixtures()
37
38 export const Renderer = isForgetEnabled_Fixtures()
39 ? (props) => {
40 - const $ = useMemoCache(2);
40 + const $ = useMemoCache(3);
41 let t0;
42 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
43 t0 = <Bar />;
@@ -47,17 +47,24 @@ export const Renderer = isForgetEnabled_Fixtures()
47 }
48 let t1;
49 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
50 - t1 = (
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 = (
58 <Foo>
59 {t0}
53 - <ErrorView />
60 + {t1}
61 </Foo>
62 );
56 - $[1] = t1;
63 + $[2] = t2;
64 } else {
58 - t1 = $[1];
65 + t2 = $[2];
66 }
60 - return t1;
67 + return t2;
68 }
69 : (props) => (
70 <Foo>
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/multi-arrow-expr-gating-test.expect.md
+13 -6
@@ -39,7 +39,7 @@ const ErrorView = isForgetEnabled_Fixtures()
39
40 const Renderer = isForgetEnabled_Fixtures()
41 ? (props) => {
42 - const $ = useMemoCache(2);
42 + const $ = useMemoCache(3);
43 let t0;
44 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
45 t0 = <Bar />;
@@ -49,17 +49,24 @@ const Renderer = isForgetEnabled_Fixtures()
49 }
50 let t1;
51 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
52 - t1 = (
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 = (
60 <Foo>
61 {t0}
55 - <ErrorView />
62 + {t1}
63 </Foo>
64 );
58 - $[1] = t1;
65 + $[2] = t2;
66 } else {
60 - t1 = $[1];
67 + t2 = $[2];
68 }
62 - return t1;
69 + return t2;
70 }
71 : (props) => (
72 <Foo>
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/mutable-lifetime-loops.expect.md
+23 -8
@@ -76,13 +76,16 @@ function cond(x) {
76 }
77
78 function testFunction(props) {
79 - const $ = useMemoCache(1);
80 - let t0;
79 + const $ = useMemoCache(5);
80 + let a;
81 + let b;
82 + let c;
83 + let d;
84 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
82 - let a = {};
83 - let b = {};
84 - let c = {};
85 - let d = {};
85 + a = {};
86 + b = {};
87 + c = {};
88 + d = {};
89 while (true) {
90 const z = a;
91 a = b;
@@ -104,10 +107,22 @@ function testFunction(props) {
107 }
108
109 mutate(d, null);
110 + $[0] = a;
111 + $[1] = b;
112 + $[2] = c;
113 + $[3] = d;
114 + } else {
115 + a = $[0];
116 + b = $[1];
117 + c = $[2];
118 + d = $[3];
119 + }
120 + let t0;
121 + if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
122 t0 = { a, b, c, d };
108 - $[0] = t0;
123 + $[4] = t0;
124 } else {
110 - t0 = $[0];
125 + t0 = $[4];
126 }
127 return t0;
128 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/nested-function-with-param-as-captured-dep.expect.md
+11 -4
@@ -24,20 +24,27 @@ export const FIXTURE_ENTRYPOINT = {
24 ```javascript
25 import { unstable_useMemoCache as useMemoCache } from "react";
26 function Foo() {
27 - const $ = useMemoCache(1);
27 + const $ = useMemoCache(2);
28 let t0;
29 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
30 - t0 = (function t() {
30 + t0 = function t() {
31 return function a(t25) {
32 const x_0 = t25 === undefined ? () => {} : t25;
33 return x_0;
34 };
35 - })();
35 + };
36 $[0] = t0;
37 } else {
38 t0 = $[0];
39 }
40 - return t0;
40 + let t1;
41 + if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
42 + t1 = t0();
43 + $[1] = t1;
44 + } else {
45 + t1 = $[1];
46 + }
47 + return t1;
48 }
49
50 export const FIXTURE_ENTRYPOINT = {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/property-call-evaluation-order.expect.md
+12 -5
@@ -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(2);
33 + const $ = useMemoCache(3);
34 let t0;
35 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36 t0 = (o) => {
@@ -41,14 +41,21 @@ function Component() {
41 t0 = $[0];
42 }
43 const changeF = t0;
44 - let x;
44 + let t1;
45 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
46 - x = { f: () => console.log("original") };
46 + t1 = () => console.log("original");
47 + $[1] = t1;
48 + } else {
49 + t1 = $[1];
50 + }
51 + let x;
52 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
53 + x = { f: t1 };
54
55 (console.log("A"), x).f((changeF(x), console.log("arg"), 1));
49 - $[1] = x;
56 + $[2] = x;
57 } else {
51 - x = $[1];
58 + x = $[2];
59 }
60 return x;
61 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ssa-call-jsx-2.expect.md
+15 -6
@@ -25,20 +25,29 @@ import { unstable_useMemoCache as useMemoCache } from "react"; // @Pass runMutab
25 function foo() {}
26
27 function Component(props) {
28 - const $ = useMemoCache(1);
29 - let t0;
28 + const $ = useMemoCache(3);
29 + let a;
30 + let b;
31 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
31 - const a = [];
32 - const b = {};
32 + a = [];
33 + b = {};
34 foo(a, b);
35 if (foo()) {
36 }
37
38 foo(a, b);
39 + $[0] = a;
40 + $[1] = b;
41 + } else {
42 + a = $[0];
43 + b = $[1];
44 + }
45 + let t0;
46 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
47 t0 = <div a={a} b={b} />;
39 - $[0] = t0;
48 + $[2] = t0;
49 } else {
41 - t0 = $[0];
50 + t0 = $[2];
51 }
52 return t0;
53 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ssa-call-jsx.expect.md
+15 -6
@@ -22,18 +22,27 @@ import { unstable_useMemoCache as useMemoCache } from "react";
22 function foo() {}
23
24 function Component(props) {
25 - const $ = useMemoCache(1);
26 - let t0;
25 + const $ = useMemoCache(3);
26 + let a;
27 + let b;
28 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
28 - const a = [];
29 - const b = {};
29 + a = [];
30 + b = {};
31 foo(a, b);
32
33 foo(a, b);
34 + $[0] = a;
35 + $[1] = b;
36 + } else {
37 + a = $[0];
38 + b = $[1];
39 + }
40 + let t0;
41 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
42 t0 = <div a={a} b={b} />;
34 - $[0] = t0;
43 + $[2] = t0;
44 } else {
36 - t0 = $[0];
45 + t0 = $[2];
46 }
47 return t0;
48 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/type-test-field-load-binary-op.expect.md
+10 -3
@@ -21,7 +21,7 @@ function component() {
21 ```javascript
22 import { unstable_useMemoCache as useMemoCache } from "react";
23 function component() {
24 - const $ = useMemoCache(2);
24 + const $ = useMemoCache(3);
25 let t0;
26 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
27 t0 = makeSomePrimitive();
@@ -31,12 +31,19 @@ function component() {
31 }
32 let t1;
33 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
34 - t1 = { u: t0, v: makeSomePrimitive() };
34 + t1 = makeSomePrimitive();
35 $[1] = t1;
36 } else {
37 t1 = $[1];
38 }
39 - const x = t1;
39 + let t2;
40 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
41 + t2 = { u: t0, v: t1 };
42 + $[2] = t2;
43 + } else {
44 + t2 = $[2];
45 + }
46 + const x = t2;
47 const u = x.u;
48 const v = x.v;
49 if (u > v) {
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/uninitialized-declaration-in-reactive-scope.expect.md
+15 -6
@@ -16,16 +16,25 @@ function Component(props) {
16 ```javascript
17 import { unstable_useMemoCache as useMemoCache } from "react";
18 function Component(props) {
19 - const $ = useMemoCache(1);
20 - let t0;
19 + const $ = useMemoCache(3);
20 + let y;
21 + let x;
22 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
22 - const x = mutate();
23 - let y;
23 + x = mutate();
24 +
25 foo(x);
26 + $[0] = y;
27 + $[1] = x;
28 + } else {
29 + y = $[0];
30 + x = $[1];
31 + }
32 + let t0;
33 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
34 t0 = [y, x];
26 - $[0] = t0;
35 + $[2] = t0;
36 } else {
28 - t0 = $[0];
37 + t0 = $[2];
38 }
39 return t0;
40 }
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/useEffect-arg-memoized.expect.md
+13 -9
@@ -26,7 +26,7 @@ function Component(props) {
26 ```javascript
27 import { unstable_useMemoCache as useMemoCache } from "react";
28 function Component(props) {
29 - const $ = useMemoCache(6);
29 + const $ = useMemoCache(7);
30 const dispatch = useDispatch();
31 useFreeze(dispatch);
32 const c_0 = $[0] !== dispatch;
@@ -43,27 +43,31 @@ function Component(props) {
43 const onUpdate = t0;
44 const c_2 = $[2] !== onUpdate;
45 let t1;
46 - let t2;
46 if (c_2) {
47 t1 = () => {
48 onUpdate();
49 };
51 - t2 = [onUpdate];
50 $[2] = onUpdate;
51 $[3] = t1;
54 - $[4] = t2;
52 } else {
53 t1 = $[3];
57 - t2 = $[4];
54 }
59 - useEffect(t1, t2);
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];
63 + }
64 useEffect(t1, t2);
65 let t3;
62 - if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
66 + if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
67 t3 = <div />;
64 - $[5] = t3;
68 + $[6] = t3;
69 } else {
66 - t3 = $[5];
70 + t3 = $[6];
71 }
72 return t3;
73 }
compiler/packages/fixture-test-utils/src/compiler-utils.ts
+5
@@ -29,6 +29,7 @@ export function transformFixtureInput(
29 let compilationMode: CompilationMode = "all";
30 let enableForest = false;
31 let enableNoAliasOptimizations = false;
32 + let enableMergeConsecutiveScopes = false;
33 let bailoutOnHoleyArrays = false;
34
35 if (firstLine.indexOf("@compilationMode(annotation)") !== -1) {
@@ -93,6 +94,9 @@ export function transformFixtureInput(
94 bailoutOnHoleyArrays = true;
95 }
96
97 + if (firstLine.includes("@enableMergeConsecutiveScopes")) {
98 + enableMergeConsecutiveScopes = true;
99 + }
100
101 return pluginFn(
102 input,
@@ -141,6 +145,7 @@ export function transformFixtureInput(
145 validateFrozenLambdas: true,
146 validateNoSetStateInRender,
147 enableEmitFreeze,
148 + enableMergeConsecutiveScopes,
149 assertValidMutableRanges: true,
150 bailoutOnHoleyArrays,
151 enableForest,