@samitouri / QOS-React-2 / commits / 61d7e6ae3d

[js] optimize function expressions by default

This mode improves compilation and makes optimizations easier, let's make it the default. I previously confirmed that enabling this mode didn't affect output when synced internally, and I'll do that again before landing the PR.

Joe Savona committed Jul 11, 2023 at 13:06 UTC 61d7e6ae3d81dbaa0c86950b3befbb108f14d4d4
67 files changed +111 -106
compiler/forget/apps/playground/components/Editor/index.tsx
+3 -3
@@ -115,7 +115,7 @@ function parsePragma(pragma: string) {
115 let disableAllMemoization = false;
116 let validateRefAccessDuringRender = true;
117 let enableEmitFreeze = null;
118 - let enableOptimizeFunctionExpressions = false;
118 + let enableOptimizeFunctionExpressions = true;
119 let inlineUseMemo = true;
120 let validateHooksUsage = true;
121 let enableFunctionCallSignatureOptimizations = true;
@@ -137,8 +137,8 @@ function parsePragma(pragma: string) {
137 if (pragma.includes("@validateRefAccessDuringRender false")) {
138 validateRefAccessDuringRender = false;
139 }
140 - if (pragma.includes("@enableOptimizeFunctionExpressions")) {
141 - enableOptimizeFunctionExpressions = true;
140 + if (pragma.includes("@enableOptimizeFunctionExpressions false")) {
141 + enableOptimizeFunctionExpressions = false;
142 }
143 if (pragma.includes("@enableEmitFreeze")) {
144 enableEmitFreeze = {
compiler/forget/packages/babel-plugin-react-forget/src/HIR/Environment.ts
+1 -1
@@ -229,7 +229,7 @@ export class Environment {
229 this.disableAllMemoization = config?.disableAllMemoization ?? false;
230 this.enableEmitFreeze = config?.enableEmitFreeze ?? null;
231 this.enableOptimizeFunctionExpressions =
232 - config?.enableOptimizeFunctionExpressions ?? false;
232 + config?.enableOptimizeFunctionExpressions ?? true;
233 this.assertValidMutableRanges = config?.assertValidMutableRanges ?? false;
234
235 this.#contextIdentifiers = contextIdentifiers;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capture-indirect-mutate-alias.expect.md
+1 -1
@@ -27,7 +27,7 @@ function component(a) {
27 if (c_0) {
28 x = { a };
29 (function () {
30 - let q = x;
30 + const q = x;
31 (function () {
32 q.b = 1;
33 })();
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capture-param-mutate.expect.md
+4 -4
@@ -52,18 +52,17 @@ function getNativeLogFunction(level) {
52 let t0;
53 if (c_0) {
54 t0 = function () {
55 - let str;
55 + let str = undefined;
56 if (arguments.length === 1 && typeof arguments[0] === "string") {
57 str = arguments[0];
58 } else {
59 str = Array.prototype.map
60 .call(arguments, function (arg) {
61 - return inspect(arg, {
62 - depth: 10,
63 - });
61 + return inspect(arg, { depth: 10 });
62 })
63 .join(", ");
64 }
65 +
66 const firstArg = arguments[0];
67 let logLevel = level;
68 if (
@@ -84,6 +83,7 @@ function getNativeLogFunction(level) {
83 if (groupStack.length) {
84 str = groupFormat("", str);
85 }
86 +
87 global.nativeLoggingHook(str, logLevel);
88 };
89 $[0] = level;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-arrow-function-1.expect.md
+2 -2
@@ -5,7 +5,7 @@
5 function component(a) {
6 let z = { a };
7 let x = () => {
8 - z;
8 + console.log(z);
9 };
10 return x;
11 }
@@ -32,7 +32,7 @@ function component(a) {
32 let t1;
33 if (c_2) {
34 t1 = () => {
35 - z;
35 + console.log(z);
36 };
37 $[2] = z;
38 $[3] = t1;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-arrow-function-1.js
+1 -1
@@ -1,7 +1,7 @@
1 function component(a) {
2 let z = { a };
3 let x = () => {
4 - z;
4 + console.log(z);
5 };
6 return x;
7 }
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2.expect.md
+2 -2
@@ -29,8 +29,8 @@ function component(foo, bar) {
29 x = { foo };
30 const y = { bar };
31 (function () {
32 - let a = { y };
33 - let b = x;
32 + const a = { y };
33 + const b = x;
34 a.x = b;
35 })();
36 mutate(y);
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2.expect.md
+2 -2
@@ -29,8 +29,8 @@ function component(foo, bar) {
29 x = { foo };
30 const y = { bar };
31 (function () {
32 - let a = [y];
33 - let b = x;
32 + const a = [y];
33 + const b = x;
34 a.x = b;
35 })();
36 mutate(y);
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr.expect.md
+2 -2
@@ -29,8 +29,8 @@ function component(foo, bar) {
29 const x = { foo };
30 y = { bar };
31 (function () {
32 - let a = [y];
33 - let b = x;
32 + const a = [y];
33 + const b = x;
34 a.x = b;
35 })();
36 mutate(y);
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md
+2 -2
@@ -29,8 +29,8 @@ function component(foo, bar) {
29 const x = { foo };
30 y = { bar };
31 (function () {
32 - let a = { y };
33 - let b = x;
32 + const a = { y };
33 + const b = x;
34 a.x = b;
35 })();
36 mutate(y);
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate.expect.md
+1 -1
@@ -26,7 +26,7 @@ function component(a) {
26 const x = { a };
27 y = {};
28 (function () {
29 - y["x"] = x;
29 + y.x = x;
30 })();
31 mutate(y);
32 $[0] = a;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate.expect.md
+2 -2
@@ -27,8 +27,8 @@ function component(a) {
27 const x = { a };
28 y = {};
29 (function () {
30 - let a_0 = y;
31 - a_0["x"] = x;
30 + const a_0 = y;
31 + a_0.x = x;
32 })();
33 mutate(y);
34 $[0] = a;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate.expect.md
+1 -1
@@ -27,7 +27,7 @@ function component(a) {
27 const x = { a };
28 y = {};
29 (function () {
30 - let a_0 = y;
30 + const a_0 = y;
31 a_0.x = x;
32 })();
33 mutate(y);
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate-2.expect.md
+1 -1
@@ -38,8 +38,8 @@ function component(a, b) {
38 z = { a };
39 const x = function () {
40 z.a = 2;
41 - y.b;
41 };
42 +
43 x();
44 $[2] = a;
45 $[3] = y.b;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate-nested.expect.md
+1
@@ -26,6 +26,7 @@ function component(a) {
26 const x = function () {
27 y.b.a = 2;
28 };
29 +
30 x();
31 $[0] = a;
32 $[1] = y;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md
+3 -2
@@ -7,7 +7,7 @@ function component(a, b) {
7 let y = { b };
8 let x = function () {
9 z.a = 2;
10 - y.b;
10 + console.log(y.b);
11 };
12 x();
13 return z;
@@ -29,8 +29,9 @@ function component(a, b) {
29 const y = { b };
30 const x = function () {
31 z.a = 2;
32 - y.b;
32 + console.log(y.b);
33 };
34 +
35 x();
36 $[0] = a;
37 $[1] = b;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate.js
+1 -1
@@ -3,7 +3,7 @@ function component(a, b) {
3 let y = { b };
4 let x = function () {
5 z.a = 2;
6 - y.b;
6 + console.log(y.b);
7 };
8 x();
9 return z;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-1.expect.md
+2 -2
@@ -5,7 +5,7 @@
5 function component(a) {
6 let z = { a };
7 let x = function () {
8 - z;
8 + console.log(z);
9 };
10 return x;
11 }
@@ -32,7 +32,7 @@ function component(a) {
32 let t1;
33 if (c_2) {
34 t1 = function () {
35 - z;
35 + console.log(z);
36 };
37 $[2] = z;
38 $[3] = t1;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-1.js
+1 -1
@@ -1,7 +1,7 @@
1 function component(a) {
2 let z = { a };
3 let x = function () {
4 - z;
4 + console.log(z);
5 };
6 return x;
7 }
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-conditional-capture-mutate.expect.md
-3
@@ -42,9 +42,6 @@ function component(a, b) {
42 if (c_2 || c_3) {
43 t1 = function () {
44 if (y) {
45 - // we don't know for sure this mutates, so we should assume
46 - // that there is no mutation so long as `x` isn't called
47 - // during render
45 maybeMutate(z);
46 }
47 };
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-decl.expect.md
+1
@@ -26,6 +26,7 @@ function component(a) {
26 const x = function x() {
27 t.foo();
28 };
29 +
30 x(t);
31 $[0] = a;
32 $[1] = t;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-within-block.expect.md
+2 -2
@@ -7,7 +7,7 @@ function component(a) {
7 let x;
8 {
9 x = function () {
10 - z;
10 + console.log(z);
11 };
12 }
13 return x;
@@ -35,7 +35,7 @@ function component(a) {
35 let t1;
36 if (c_2) {
37 t1 = function () {
38 - z;
38 + console.log(z);
39 };
40 $[2] = z;
41 $[3] = t1;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-within-block.js
+1 -1
@@ -3,7 +3,7 @@ function component(a) {
3 let x;
4 {
5 x = function () {
6 - z;
6 + console.log(z);
7 };
8 }
9 return x;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-member-expr.expect.md
+2 -2
@@ -5,7 +5,7 @@
5 function component(a) {
6 let z = { a };
7 let x = function () {
8 - z.a;
8 + console.log(z.a);
9 };
10 return x;
11 }
@@ -32,7 +32,7 @@ function component(a) {
32 let t1;
33 if (c_2) {
34 t1 = function () {
35 - z.a;
35 + console.log(z.a);
36 };
37 $[2] = z.a;
38 $[3] = t1;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-member-expr.js
+1 -1
@@ -1,7 +1,7 @@
1 function component(a) {
2 let z = { a };
3 let x = function () {
4 - z.a;
4 + console.log(z.a);
5 };
6 return x;
7 }
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.expect.md
+2 -2
@@ -6,7 +6,7 @@ function component(a) {
6 let z = { a: { a } };
7 let x = function () {
8 (function () {
9 - z.a.a;
9 + console.log(z.a.a);
10 })();
11 };
12 return x;
@@ -44,7 +44,7 @@ function component(a) {
44 if (c_4) {
45 t2 = function () {
46 (function () {
47 - z.a.a;
47 + console.log(z.a.a);
48 })();
49 };
50 $[4] = z.a.a;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.js
+1 -1
@@ -2,7 +2,7 @@ function component(a) {
2 let z = { a: { a } };
3 let x = function () {
4 (function () {
5 - z.a.a;
5 + console.log(z.a.a);
6 })();
7 };
8 return x;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.expect.md
+2 -2
@@ -5,7 +5,7 @@
5 function component(a) {
6 let z = { a: { a } };
7 let x = function () {
8 - z.a.a;
8 + console.log(z.a.a);
9 };
10 return x;
11 }
@@ -41,7 +41,7 @@ function component(a) {
41 let t2;
42 if (c_4) {
43 t2 = function () {
44 - z.a.a;
44 + console.log(z.a.a);
45 };
46 $[4] = z.a.a;
47 $[5] = t2;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.js
+1 -1
@@ -1,7 +1,7 @@
1 function component(a) {
2 let z = { a: { a } };
3 let x = function () {
4 - z.a.a;
4 + console.log(z.a.a);
5 };
6 return x;
7 }
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-block.expect.md
+2 -4
@@ -6,7 +6,7 @@ function component(a) {
6 let z = { a };
7 let x = function () {
8 {
9 - z;
9 + console.log(z);
10 }
11 };
12 return x;
@@ -34,9 +34,7 @@ function component(a) {
34 let t1;
35 if (c_2) {
36 t1 = function () {
37 - {
38 - z;
39 - }
37 + console.log(z);
38 };
39 $[2] = z;
40 $[3] = t1;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-block.js
+1 -1
@@ -2,7 +2,7 @@ function component(a) {
2 let z = { a };
3 let x = function () {
4 {
5 - z;
5 + console.log(z);
6 }
7 };
8 return x;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-function.expect.md
+2 -2
@@ -6,7 +6,7 @@ function component(a) {
6 let z = { a };
7 let x = function () {
8 (function () {
9 - z;
9 + console.log(z);
10 })();
11 };
12 return x;
@@ -35,7 +35,7 @@ function component(a) {
35 if (c_2) {
36 t1 = function () {
37 (function () {
38 - z;
38 + console.log(z);
39 })();
40 };
41 $[2] = z;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-function.js
+1 -1
@@ -2,7 +2,7 @@ function component(a) {
2 let z = { a };
3 let x = function () {
4 (function () {
5 - z;
5 + console.log(z);
6 })();
7 };
8 return x;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/chained-assignment-context-variable.expect.md
+1
@@ -28,6 +28,7 @@ function Component() {
28 const foo = () => {
29 x = getObject();
30 };
31 +
32 foo();
33 $[0] = x;
34 $[1] = y;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-global.expect.md
+2 -5
@@ -5,7 +5,7 @@
5 function foo() {
6 const isX = GLOBAL_IS_X;
7 const getJSX = () => {
8 - <Child x={isX}></Child>;
8 + return <Child x={isX}></Child>;
9 };
10 const result = getJSX();
11 return result;
@@ -19,12 +19,9 @@ function foo() {
19 import { unstable_useMemoCache as useMemoCache } from "react";
20 function foo() {
21 const $ = useMemoCache(2);
22 - const isX = GLOBAL_IS_X;
22 let t0;
23 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
25 - t0 = () => {
26 - <Child x={isX}></Child>;
27 - };
24 + t0 = () => <Child x={GLOBAL_IS_X} />;
25 $[0] = t0;
26 } else {
27 t0 = $[0];
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-global.js
+1 -1
@@ -1,7 +1,7 @@
1 function foo() {
2 const isX = GLOBAL_IS_X;
3 const getJSX = () => {
4 - <Child x={isX}></Child>;
4 + return <Child x={isX}></Child>;
5 };
6 const result = getJSX();
7 return result;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-primitive.expect.md
+2 -2
@@ -17,10 +17,10 @@ function foo() {
17
18 ```javascript
19 function foo() {
20 - const x = 42;
20 const f = () => {
22 - console.log(x);
21 + console.log(42);
22 };
23 +
24 f();
25 return 42;
26 }
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableOptimizeFunctionExpressions
5 function Component(props) {
6 const x = 42;
7 const onEvent = () => {
@@ -16,7 +15,7 @@ function Component(props) {
15 ## Code
16
17 ```javascript
19 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableOptimizeFunctionExpressions
18 +import { unstable_useMemoCache as useMemoCache } from "react";
19 function Component(props) {
20 const $ = useMemoCache(2);
21 let t0;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.js
-1
@@ -1,4 +1,3 @@
1 -// @enableOptimizeFunctionExpressions
1 function Component(props) {
2 const x = 42;
3 const onEvent = () => {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/context-variable-reassigned-outside-of-lambda.expect.md
+1
@@ -27,6 +27,7 @@ function Component(props) {
27 onChange = (e) => {
28 console.log(x);
29 };
30 +
31 x = {};
32 $[0] = onChange;
33 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/declare-reassign-variable-in-closure.expect.md
+1
@@ -25,6 +25,7 @@ function Component(p) {
25 const foo = () => {
26 x = {};
27 };
28 +
29 foo();
30 $[0] = x;
31 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/declare-reassign-variable-in-function-declaration.expect.md
+1
@@ -26,6 +26,7 @@ function Component() {
26 const foo = function foo() {
27 x = 9;
28 };
29 +
30 t0 = bar(foo);
31 $[0] = t0;
32 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.expect.md
+2
@@ -67,6 +67,7 @@ function Component(props) {
67 if (!comments.length) {
68 return;
69 }
70 +
71 console.log(comments.length);
72 };
73 $[7] = comments.length;
@@ -75,6 +76,7 @@ function Component(props) {
76 t4 = $[8];
77 }
78 onClick = t4;
79 +
80 allUrls.push(...urls);
81 $[0] = post;
82 $[1] = media;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.expect.md
+4 -2
@@ -38,8 +38,8 @@ function Component(props) {
38 if (c_0) {
39 const allUrls = [];
40
41 - const { media: t84, comments, urls } = post;
42 - media = t84;
41 + const { media: t83, comments, urls } = post;
42 + media = t83;
43 const c_3 = $[3] !== comments.length;
44 let t0;
45 if (c_3) {
@@ -47,6 +47,7 @@ function Component(props) {
47 if (!comments.length) {
48 return;
49 }
50 +
51 console.log(comments.length);
52 };
53 $[3] = comments.length;
@@ -55,6 +56,7 @@ function Component(props) {
56 t0 = $[4];
57 }
58 onClick = t0;
59 +
60 allUrls.push(...urls);
61 $[0] = post;
62 $[1] = media;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-reassign.expect.md
+1
@@ -30,6 +30,7 @@ function component() {
30 let x;
31 if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
32 x = t0;
33 +
34 x = {};
35 $[1] = x;
36 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-simple.expect.md
+1
@@ -33,6 +33,7 @@ function component(a) {
33 t0 = $[2];
34 }
35 const x = t0;
36 +
37 x(t);
38 $[0] = a;
39 $[1] = t;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-capture-returned-alias.expect.md
+1
@@ -54,6 +54,7 @@ function CaptureNotMutate(props) {
54 const arr = { element };
55 return arr[idx];
56 };
57 +
58 aliasedElement = fn();
59 mutate(aliasedElement);
60 $[2] = props.el;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-mutate-shadowed-object.expect.md
+1
@@ -35,6 +35,7 @@ function Component() {
35 const fn = function () {
36 mutate(x_0);
37 };
38 +
39 fn();
40 return x;
41 }
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-reassign-primitive.expect.md
+1
@@ -36,6 +36,7 @@ function Component() {
36 const fn = function () {
37 x = x + 1;
38 };
39 +
40 fn();
41 $[0] = x;
42 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-reassign-shadowed-primitive.expect.md
+1
@@ -36,6 +36,7 @@ function Component() {
36 const fn = function () {
37 x_0 = 42;
38 };
39 +
40 fn();
41 return x;
42 }
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-with-fbt.expect.md
+16 -18
@@ -48,24 +48,22 @@ function Component() {
48 t0 = () => {
49 if (!someCondition) {
50 return fbt._("Purchase as a gift", null, { hk: "1gHj4g" });
51 - } else if (
52 - !iconOnly &&
53 - showPrice &&
54 - item?.current_gift_offer?.price?.formatted != null
55 - ) {
56 - return fbt._(
57 - "Gift | {price}",
58 - [
59 - fbt._param(
60 - "price",
61 -
62 - item?.current_gift_offer?.price?.formatted
63 - ),
64 - ],
65 - { hk: "3GTnGE" }
66 - );
67 - } else if (!iconOnly && !showPrice) {
68 - return fbt._("Gift", null, { hk: "3fqfrk" });
51 + } else {
52 + if (
53 + !iconOnly &&
54 + showPrice &&
55 + item?.current_gift_offer?.price?.formatted != null
56 + ) {
57 + return fbt._(
58 + "Gift | {price}",
59 + [fbt._param("price", item?.current_gift_offer?.price?.formatted)],
60 + { hk: "3GTnGE" }
61 + );
62 + } else {
63 + if (!iconOnly && !showPrice) {
64 + return fbt._("Gift", null, { hk: "3fqfrk" });
65 + }
66 + }
67 }
68 };
69 $[0] = t0;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/nested-function-shadowed-identifiers.expect.md
+1 -2
@@ -25,8 +25,7 @@ function Component(props) {
25 let t0;
26 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
27 t0 = (e) => {
28 - let x_0 = null; // intentionally shadow the original x
29 - setX((currentX) => currentX + x_0); // intentionally refer to shadowed x
28 + setX((currentX) => currentX + null);
29 };
30 $[0] = t0;
31 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/prop-capturing-function-1.expect.md
+2 -2
@@ -5,7 +5,7 @@
5 function component(a, b) {
6 let z = { a, b };
7 let x = function () {
8 - z;
8 + console.log(z);
9 };
10 return x;
11 }
@@ -34,7 +34,7 @@ function component(a, b) {
34 let t1;
35 if (c_3) {
36 t1 = function () {
37 - z;
37 + console.log(z);
38 };
39 $[3] = z;
40 $[4] = t1;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/prop-capturing-function-1.js
+1 -1
@@ -1,7 +1,7 @@
1 function component(a, b) {
2 let z = { a, b };
3 let x = function () {
4 - z;
4 + console.log(z);
5 };
6 return x;
7 }
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassign-object-in-context.expect.md
+1
@@ -25,6 +25,7 @@ function Component(props) {
25 const foo = () => {
26 x = {};
27 };
28 +
29 foo();
30 $[0] = x;
31 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassign-primitive-in-context.expect.md
+1
@@ -25,6 +25,7 @@ function Component(props) {
25 const foo = () => {
26 x = {};
27 };
28 +
29 foo();
30 $[0] = x;
31 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @enableOptimizeFunctionExpressions
5 function Component(props) {
6 return () => {
7 let str;
@@ -20,7 +19,7 @@ function Component(props) {
19 ## Code
20
21 ```javascript
23 -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableOptimizeFunctionExpressions
22 +import { unstable_useMemoCache as useMemoCache } from "react";
23 function Component(props) {
24 const $ = useMemoCache(2);
25 const c_0 = $[0] !== props.str;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.js
-1
@@ -1,4 +1,3 @@
1 -// @enableOptimizeFunctionExpressions
1 function Component(props) {
2 return () => {
3 let str;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-no-added-to-dep.expect.md
+2 -2
@@ -7,7 +7,7 @@ function VideoTab() {
7 const ref = useRef();
8 const t = ref.current;
9 let x = () => {
10 - t;
10 + console.log(t);
11 };
12
13 return <VideoList videos={x} />;
@@ -26,7 +26,7 @@ function VideoTab() {
26 let t0;
27 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
28 t0 = () => {
29 - t;
29 + console.log(t);
30 };
31 $[0] = t0;
32 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-no-added-to-dep.js
+1 -1
@@ -3,7 +3,7 @@ function VideoTab() {
3 const ref = useRef();
4 const t = ref.current;
5 let x = () => {
6 - t;
6 + console.log(t);
7 };
8
9 return <VideoList videos={x} />;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-not-added-to-dep.expect.md
+2 -2
@@ -6,7 +6,7 @@
6 function VideoTab() {
7 const ref = useRef();
8 let x = () => {
9 - ref.current.x;
9 + console.log(ref.current.x);
10 };
11
12 return <VideoList videos={x} />;
@@ -24,7 +24,7 @@ function VideoTab() {
24 let t0;
25 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
26 t0 = () => {
27 - ref.current.x;
27 + console.log(ref.current.x);
28 };
29 $[0] = t0;
30 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-not-added-to-dep.js
+1 -1
@@ -2,7 +2,7 @@
2 function VideoTab() {
3 const ref = useRef();
4 let x = () => {
5 - ref.current.x;
5 + console.log(ref.current.x);
6 };
7
8 return <VideoList videos={x} />;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep.expect.md
+2 -2
@@ -5,7 +5,7 @@
5 function VideoTab() {
6 const ref = useRef();
7 let x = () => {
8 - ref.current;
8 + console.log(ref.current);
9 };
10
11 return <VideoList videos={x} />;
@@ -23,7 +23,7 @@ function VideoTab() {
23 let t0;
24 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
25 t0 = () => {
26 - ref.current;
26 + console.log(ref.current);
27 };
28 $[0] = t0;
29 } else {
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep.js
+1 -1
@@ -1,7 +1,7 @@
1 function VideoTab() {
2 const ref = useRef();
3 let x = () => {
4 - ref.current;
4 + console.log(ref.current);
5 };
6
7 return <VideoList videos={x} />;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/remove-memoization-kitchen-sink.expect.md
+1
@@ -26,6 +26,7 @@ function Component(props) {
26 const onChange = (e) => {
27 setX(e.target.value);
28 };
29 +
30 const object = { x, onChange };
31
32 const { x: x_0, onChange: onChange_0 } = object;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-scope-missing-mutable-range.expect.md
+1 -1
@@ -26,7 +26,7 @@ function HomeDiscoStoreItemTileRating(props) {
26 count = 0;
27 const aggregates = item?.aggregates || [];
28 aggregates.forEach((aggregate) => {
29 - count += aggregate.count || 0;
29 + count = count + (aggregate.count || 0);
30 });
31 let t0;
32 if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
compiler/forget/packages/snap/src/compiler-worker.ts
+3 -3
@@ -98,7 +98,7 @@ export async function compile(
98 let disableAllMemoization = false;
99 let validateRefAccessDuringRender = true;
100 let enableEmitFreeze = null;
101 - let enableOptimizeFunctionExpressions = false;
101 + let enableOptimizeFunctionExpressions = true;
102 if (firstLine.indexOf("@forgetDirective") !== -1) {
103 enableOnlyOnUseForgetDirective = true;
104 }
@@ -132,8 +132,8 @@ export async function compile(
132 if (firstLine.includes("@validateRefAccessDuringRender false")) {
133 validateRefAccessDuringRender = false;
134 }
135 - if (firstLine.includes("@enableOptimizeFunctionExpressions")) {
136 - enableOptimizeFunctionExpressions = true;
135 + if (firstLine.includes("@enableOptimizeFunctionExpressions false")) {
136 + enableOptimizeFunctionExpressions = false;
137 }
138 if (firstLine.includes("@enableEmitFreeze")) {
139 enableEmitFreeze = {