diff --git a/compiler/forget/apps/playground/components/Editor/index.tsx b/compiler/forget/apps/playground/components/Editor/index.tsx
index 4aba76cdb4..13a7d024ed 100644
--- a/compiler/forget/apps/playground/components/Editor/index.tsx
+++ b/compiler/forget/apps/playground/components/Editor/index.tsx
@@ -115,7 +115,7 @@ function parsePragma(pragma: string) {
let disableAllMemoization = false;
let validateRefAccessDuringRender = true;
let enableEmitFreeze = null;
- let enableOptimizeFunctionExpressions = false;
+ let enableOptimizeFunctionExpressions = true;
let inlineUseMemo = true;
let validateHooksUsage = true;
let enableFunctionCallSignatureOptimizations = true;
@@ -137,8 +137,8 @@ function parsePragma(pragma: string) {
if (pragma.includes("@validateRefAccessDuringRender false")) {
validateRefAccessDuringRender = false;
}
- if (pragma.includes("@enableOptimizeFunctionExpressions")) {
- enableOptimizeFunctionExpressions = true;
+ if (pragma.includes("@enableOptimizeFunctionExpressions false")) {
+ enableOptimizeFunctionExpressions = false;
}
if (pragma.includes("@enableEmitFreeze")) {
enableEmitFreeze = {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/HIR/Environment.ts b/compiler/forget/packages/babel-plugin-react-forget/src/HIR/Environment.ts
index e77aedb2f6..16de839a47 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/HIR/Environment.ts
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/HIR/Environment.ts
@@ -229,7 +229,7 @@ export class Environment {
this.disableAllMemoization = config?.disableAllMemoization ?? false;
this.enableEmitFreeze = config?.enableEmitFreeze ?? null;
this.enableOptimizeFunctionExpressions =
- config?.enableOptimizeFunctionExpressions ?? false;
+ config?.enableOptimizeFunctionExpressions ?? true;
this.assertValidMutableRanges = config?.assertValidMutableRanges ?? false;
this.#contextIdentifiers = contextIdentifiers;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capture-indirect-mutate-alias.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capture-indirect-mutate-alias.expect.md
index e805e8ad75..f62e8dd8be 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capture-indirect-mutate-alias.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capture-indirect-mutate-alias.expect.md
@@ -27,7 +27,7 @@ function component(a) {
if (c_0) {
x = { a };
(function () {
- let q = x;
+ const q = x;
(function () {
q.b = 1;
})();
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capture-param-mutate.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capture-param-mutate.expect.md
index 87ca0c1427..328d6219e5 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capture-param-mutate.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capture-param-mutate.expect.md
@@ -52,18 +52,17 @@ function getNativeLogFunction(level) {
let t0;
if (c_0) {
t0 = function () {
- let str;
+ let str = undefined;
if (arguments.length === 1 && typeof arguments[0] === "string") {
str = arguments[0];
} else {
str = Array.prototype.map
.call(arguments, function (arg) {
- return inspect(arg, {
- depth: 10,
- });
+ return inspect(arg, { depth: 10 });
})
.join(", ");
}
+
const firstArg = arguments[0];
let logLevel = level;
if (
@@ -84,6 +83,7 @@ function getNativeLogFunction(level) {
if (groupStack.length) {
str = groupFormat("", str);
}
+
global.nativeLoggingHook(str, logLevel);
};
$[0] = level;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-arrow-function-1.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-arrow-function-1.expect.md
index 0957e0fd95..99f96de7f3 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-arrow-function-1.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-arrow-function-1.expect.md
@@ -5,7 +5,7 @@
function component(a) {
let z = { a };
let x = () => {
- z;
+ console.log(z);
};
return x;
}
@@ -32,7 +32,7 @@ function component(a) {
let t1;
if (c_2) {
t1 = () => {
- z;
+ console.log(z);
};
$[2] = z;
$[3] = t1;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-arrow-function-1.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-arrow-function-1.js
index c7efd24dfb..1974b68dd6 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-arrow-function-1.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-arrow-function-1.js
@@ -1,7 +1,7 @@
function component(a) {
let z = { a };
let x = () => {
- z;
+ console.log(z);
};
return x;
}
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2.expect.md
index abcfecddab..4a70bac937 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-2.expect.md
@@ -29,8 +29,8 @@ function component(foo, bar) {
x = { foo };
const y = { bar };
(function () {
- let a = { y };
- let b = x;
+ const a = { y };
+ const b = x;
a.x = b;
})();
mutate(y);
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2.expect.md
index d542efe021..d3bbb5e30d 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-fun-alias-captured-mutate-arr-2.expect.md
@@ -29,8 +29,8 @@ function component(foo, bar) {
x = { foo };
const y = { bar };
(function () {
- let a = [y];
- let b = x;
+ const a = [y];
+ const b = x;
a.x = b;
})();
mutate(y);
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr.expect.md
index 447636ce63..a31f7ac140 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate-arr.expect.md
@@ -29,8 +29,8 @@ function component(foo, bar) {
const x = { foo };
y = { bar };
(function () {
- let a = [y];
- let b = x;
+ const a = [y];
+ const b = x;
a.x = b;
})();
mutate(y);
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md
index 7ce869a709..18fcd07014 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-captured-mutate.expect.md
@@ -29,8 +29,8 @@ function component(foo, bar) {
const x = { foo };
y = { bar };
(function () {
- let a = { y };
- let b = x;
+ const a = { y };
+ const b = x;
a.x = b;
})();
mutate(y);
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate.expect.md
index 6f297a15b7..65781d661d 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-computed-mutate.expect.md
@@ -26,7 +26,7 @@ function component(a) {
const x = { a };
y = {};
(function () {
- y["x"] = x;
+ y.x = x;
})();
mutate(y);
$[0] = a;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate.expect.md
index 184374b802..5bad6e6aed 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-computed-mutate.expect.md
@@ -27,8 +27,8 @@ function component(a) {
const x = { a };
y = {};
(function () {
- let a_0 = y;
- a_0["x"] = x;
+ const a_0 = y;
+ a_0.x = x;
})();
mutate(y);
$[0] = a;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate.expect.md
index d63e7c46b7..d35e96aa60 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-alias-receiver-mutate.expect.md
@@ -27,7 +27,7 @@ function component(a) {
const x = { a };
y = {};
(function () {
- let a_0 = y;
+ const a_0 = y;
a_0.x = x;
})();
mutate(y);
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate-2.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate-2.expect.md
index dfe78b3b1c..be40b06f5c 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate-2.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate-2.expect.md
@@ -38,8 +38,8 @@ function component(a, b) {
z = { a };
const x = function () {
z.a = 2;
- y.b;
};
+
x();
$[2] = a;
$[3] = y.b;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate-nested.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate-nested.expect.md
index 70ff460545..f6ef330073 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate-nested.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate-nested.expect.md
@@ -26,6 +26,7 @@ function component(a) {
const x = function () {
y.b.a = 2;
};
+
x();
$[0] = a;
$[1] = y;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md
index 2953cebf44..b26f761e84 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate.expect.md
@@ -7,7 +7,7 @@ function component(a, b) {
let y = { b };
let x = function () {
z.a = 2;
- y.b;
+ console.log(y.b);
};
x();
return z;
@@ -29,8 +29,9 @@ function component(a, b) {
const y = { b };
const x = function () {
z.a = 2;
- y.b;
+ console.log(y.b);
};
+
x();
$[0] = a;
$[1] = b;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate.js
index 420879a6f1..84e88a0328 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-func-mutate.js
@@ -3,7 +3,7 @@ function component(a, b) {
let y = { b };
let x = function () {
z.a = 2;
- y.b;
+ console.log(y.b);
};
x();
return z;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-1.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-1.expect.md
index a4db60afd7..d3cfbd1989 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-1.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-1.expect.md
@@ -5,7 +5,7 @@
function component(a) {
let z = { a };
let x = function () {
- z;
+ console.log(z);
};
return x;
}
@@ -32,7 +32,7 @@ function component(a) {
let t1;
if (c_2) {
t1 = function () {
- z;
+ console.log(z);
};
$[2] = z;
$[3] = t1;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-1.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-1.js
index 9862aadec3..c885885069 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-1.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-1.js
@@ -1,7 +1,7 @@
function component(a) {
let z = { a };
let x = function () {
- z;
+ console.log(z);
};
return x;
}
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-conditional-capture-mutate.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-conditional-capture-mutate.expect.md
index 67842b14af..700a0094f1 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-conditional-capture-mutate.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-conditional-capture-mutate.expect.md
@@ -42,9 +42,6 @@ function component(a, b) {
if (c_2 || c_3) {
t1 = function () {
if (y) {
- // we don't know for sure this mutates, so we should assume
- // that there is no mutation so long as `x` isn't called
- // during render
maybeMutate(z);
}
};
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-decl.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-decl.expect.md
index e1fcc401ff..2c46e3ae19 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-decl.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-decl.expect.md
@@ -26,6 +26,7 @@ function component(a) {
const x = function x() {
t.foo();
};
+
x(t);
$[0] = a;
$[1] = t;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-within-block.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-within-block.expect.md
index 06b742a69a..835c8d6990 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-within-block.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-within-block.expect.md
@@ -7,7 +7,7 @@ function component(a) {
let x;
{
x = function () {
- z;
+ console.log(z);
};
}
return x;
@@ -35,7 +35,7 @@ function component(a) {
let t1;
if (c_2) {
t1 = function () {
- z;
+ console.log(z);
};
$[2] = z;
$[3] = t1;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-within-block.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-within-block.js
index 1baa1c67a2..4c0975595f 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-within-block.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-function-within-block.js
@@ -3,7 +3,7 @@ function component(a) {
let x;
{
x = function () {
- z;
+ console.log(z);
};
}
return x;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-member-expr.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-member-expr.expect.md
index b5169be829..62bce523c4 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-member-expr.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-member-expr.expect.md
@@ -5,7 +5,7 @@
function component(a) {
let z = { a };
let x = function () {
- z.a;
+ console.log(z.a);
};
return x;
}
@@ -32,7 +32,7 @@ function component(a) {
let t1;
if (c_2) {
t1 = function () {
- z.a;
+ console.log(z.a);
};
$[2] = z.a;
$[3] = t1;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-member-expr.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-member-expr.js
index e445e9adac..07f5a90ce5 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-member-expr.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-member-expr.js
@@ -1,7 +1,7 @@
function component(a) {
let z = { a };
let x = function () {
- z.a;
+ console.log(z.a);
};
return x;
}
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.expect.md
index bf8b701a45..ee9dba1b34 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.expect.md
@@ -6,7 +6,7 @@ function component(a) {
let z = { a: { a } };
let x = function () {
(function () {
- z.a.a;
+ console.log(z.a.a);
})();
};
return x;
@@ -44,7 +44,7 @@ function component(a) {
if (c_4) {
t2 = function () {
(function () {
- z.a.a;
+ console.log(z.a.a);
})();
};
$[4] = z.a.a;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.js
index 3d9ed70b84..aa03be2d34 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr-in-nested-func.js
@@ -2,7 +2,7 @@ function component(a) {
let z = { a: { a } };
let x = function () {
(function () {
- z.a.a;
+ console.log(z.a.a);
})();
};
return x;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.expect.md
index 2c6c59a82c..1359f46f4d 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.expect.md
@@ -5,7 +5,7 @@
function component(a) {
let z = { a: { a } };
let x = function () {
- z.a.a;
+ console.log(z.a.a);
};
return x;
}
@@ -41,7 +41,7 @@ function component(a) {
let t2;
if (c_4) {
t2 = function () {
- z.a.a;
+ console.log(z.a.a);
};
$[4] = z.a.a;
$[5] = t2;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.js
index c0ac21f1fe..f836620745 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-nested-member-expr.js
@@ -1,7 +1,7 @@
function component(a) {
let z = { a: { a } };
let x = function () {
- z.a.a;
+ console.log(z.a.a);
};
return x;
}
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-block.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-block.expect.md
index ccdc191b45..1859aa029d 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-block.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-block.expect.md
@@ -6,7 +6,7 @@ function component(a) {
let z = { a };
let x = function () {
{
- z;
+ console.log(z);
}
};
return x;
@@ -34,9 +34,7 @@ function component(a) {
let t1;
if (c_2) {
t1 = function () {
- {
- z;
- }
+ console.log(z);
};
$[2] = z;
$[3] = t1;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-block.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-block.js
index 9509220eef..0c95eaf093 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-block.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-block.js
@@ -2,7 +2,7 @@ function component(a) {
let z = { a };
let x = function () {
{
- z;
+ console.log(z);
}
};
return x;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-function.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-function.expect.md
index 5329379a59..ab586278d5 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-function.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-function.expect.md
@@ -6,7 +6,7 @@ function component(a) {
let z = { a };
let x = function () {
(function () {
- z;
+ console.log(z);
})();
};
return x;
@@ -35,7 +35,7 @@ function component(a) {
if (c_2) {
t1 = function () {
(function () {
- z;
+ console.log(z);
})();
};
$[2] = z;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-function.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-function.js
index a074edb95d..b4e3379f95 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-function.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/capturing-variable-in-nested-function.js
@@ -2,7 +2,7 @@ function component(a) {
let z = { a };
let x = function () {
(function () {
- z;
+ console.log(z);
})();
};
return x;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/chained-assignment-context-variable.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/chained-assignment-context-variable.expect.md
index b8630a1670..ce24959203 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/chained-assignment-context-variable.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/chained-assignment-context-variable.expect.md
@@ -28,6 +28,7 @@ function Component() {
const foo = () => {
x = getObject();
};
+
foo();
$[0] = x;
$[1] = y;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-global.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-global.expect.md
index 85cb91a01d..8d06d9a1ed 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-global.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-global.expect.md
@@ -5,7 +5,7 @@
function foo() {
const isX = GLOBAL_IS_X;
const getJSX = () => {
- ;
+ return ;
};
const result = getJSX();
return result;
@@ -19,12 +19,9 @@ function foo() {
import { unstable_useMemoCache as useMemoCache } from "react";
function foo() {
const $ = useMemoCache(2);
- const isX = GLOBAL_IS_X;
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
- t0 = () => {
- ;
- };
+ t0 = () => ;
$[0] = t0;
} else {
t0 = $[0];
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-global.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-global.js
index 3b6354d514..ca1f4023ac 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-global.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-global.js
@@ -1,7 +1,7 @@
function foo() {
const isX = GLOBAL_IS_X;
const getJSX = () => {
- ;
+ return ;
};
const result = getJSX();
return result;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-primitive.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-primitive.expect.md
index 22e8b5b543..3d9988a401 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-primitive.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/const-propagation-into-function-expression-primitive.expect.md
@@ -17,10 +17,10 @@ function foo() {
```javascript
function foo() {
- const x = 42;
const f = () => {
- console.log(x);
+ console.log(42);
};
+
f();
return 42;
}
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.expect.md
index edf5e08baa..3c36c69808 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.expect.md
@@ -2,7 +2,6 @@
## Input
```javascript
-// @enableOptimizeFunctionExpressions
function Component(props) {
const x = 42;
const onEvent = () => {
@@ -16,7 +15,7 @@ function Component(props) {
## Code
```javascript
-import { unstable_useMemoCache as useMemoCache } from "react"; // @enableOptimizeFunctionExpressions
+import { unstable_useMemoCache as useMemoCache } from "react";
function Component(props) {
const $ = useMemoCache(2);
let t0;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.js
index 69de68c13f..c98bd9b670 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.js
@@ -1,4 +1,3 @@
-// @enableOptimizeFunctionExpressions
function Component(props) {
const x = 42;
const onEvent = () => {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/context-variable-reassigned-outside-of-lambda.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/context-variable-reassigned-outside-of-lambda.expect.md
index a9dc711486..f429e29f1f 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/context-variable-reassigned-outside-of-lambda.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/context-variable-reassigned-outside-of-lambda.expect.md
@@ -27,6 +27,7 @@ function Component(props) {
onChange = (e) => {
console.log(x);
};
+
x = {};
$[0] = onChange;
} else {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/declare-reassign-variable-in-closure.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/declare-reassign-variable-in-closure.expect.md
index 6071d15098..68767a92f7 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/declare-reassign-variable-in-closure.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/declare-reassign-variable-in-closure.expect.md
@@ -25,6 +25,7 @@ function Component(p) {
const foo = () => {
x = {};
};
+
foo();
$[0] = x;
} else {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/declare-reassign-variable-in-function-declaration.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/declare-reassign-variable-in-function-declaration.expect.md
index a18fd717ab..ab85103f31 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/declare-reassign-variable-in-function-declaration.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/declare-reassign-variable-in-function-declaration.expect.md
@@ -26,6 +26,7 @@ function Component() {
const foo = function foo() {
x = 9;
};
+
t0 = bar(foo);
$[0] = t0;
} else {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.expect.md
index 05490643ad..78ab58e13f 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-and-local-variables-with-default.expect.md
@@ -67,6 +67,7 @@ function Component(props) {
if (!comments.length) {
return;
}
+
console.log(comments.length);
};
$[7] = comments.length;
@@ -75,6 +76,7 @@ function Component(props) {
t4 = $[8];
}
onClick = t4;
+
allUrls.push(...urls);
$[0] = post;
$[1] = media;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.expect.md
index 536652b111..9d606ddc5b 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/destructuring-mixed-scope-declarations-and-locals.expect.md
@@ -38,8 +38,8 @@ function Component(props) {
if (c_0) {
const allUrls = [];
- const { media: t84, comments, urls } = post;
- media = t84;
+ const { media: t83, comments, urls } = post;
+ media = t83;
const c_3 = $[3] !== comments.length;
let t0;
if (c_3) {
@@ -47,6 +47,7 @@ function Component(props) {
if (!comments.length) {
return;
}
+
console.log(comments.length);
};
$[3] = comments.length;
@@ -55,6 +56,7 @@ function Component(props) {
t0 = $[4];
}
onClick = t0;
+
allUrls.push(...urls);
$[0] = post;
$[1] = media;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-reassign.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-reassign.expect.md
index 93ff3e1290..d831c481d0 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-reassign.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-reassign.expect.md
@@ -30,6 +30,7 @@ function component() {
let x;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
x = t0;
+
x = {};
$[1] = x;
} else {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-simple.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-simple.expect.md
index 1cfe84085f..41c19d5c89 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-simple.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/function-declaration-simple.expect.md
@@ -33,6 +33,7 @@ function component(a) {
t0 = $[2];
}
const x = t0;
+
x(t);
$[0] = a;
$[1] = t;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-capture-returned-alias.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-capture-returned-alias.expect.md
index 8c0a5d7287..b811bbb873 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-capture-returned-alias.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-capture-returned-alias.expect.md
@@ -54,6 +54,7 @@ function CaptureNotMutate(props) {
const arr = { element };
return arr[idx];
};
+
aliasedElement = fn();
mutate(aliasedElement);
$[2] = props.el;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-mutate-shadowed-object.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-mutate-shadowed-object.expect.md
index f023e622bf..49b3cc952a 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-mutate-shadowed-object.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-mutate-shadowed-object.expect.md
@@ -35,6 +35,7 @@ function Component() {
const fn = function () {
mutate(x_0);
};
+
fn();
return x;
}
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-reassign-primitive.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-reassign-primitive.expect.md
index a80ed568af..74b42c7341 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-reassign-primitive.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-reassign-primitive.expect.md
@@ -36,6 +36,7 @@ function Component() {
const fn = function () {
x = x + 1;
};
+
fn();
$[0] = x;
} else {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-reassign-shadowed-primitive.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-reassign-shadowed-primitive.expect.md
index ef486d16de..a86984ebb3 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-reassign-shadowed-primitive.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-reassign-shadowed-primitive.expect.md
@@ -36,6 +36,7 @@ function Component() {
const fn = function () {
x_0 = 42;
};
+
fn();
return x;
}
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-with-fbt.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-with-fbt.expect.md
index 6214b8b8bf..8df18e36a1 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-with-fbt.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/lambda-with-fbt.expect.md
@@ -48,24 +48,22 @@ function Component() {
t0 = () => {
if (!someCondition) {
return fbt._("Purchase as a gift", null, { hk: "1gHj4g" });
- } else if (
- !iconOnly &&
- showPrice &&
- item?.current_gift_offer?.price?.formatted != null
- ) {
- return fbt._(
- "Gift | {price}",
- [
- fbt._param(
- "price",
-
- item?.current_gift_offer?.price?.formatted
- ),
- ],
- { hk: "3GTnGE" }
- );
- } else if (!iconOnly && !showPrice) {
- return fbt._("Gift", null, { hk: "3fqfrk" });
+ } else {
+ if (
+ !iconOnly &&
+ showPrice &&
+ item?.current_gift_offer?.price?.formatted != null
+ ) {
+ return fbt._(
+ "Gift | {price}",
+ [fbt._param("price", item?.current_gift_offer?.price?.formatted)],
+ { hk: "3GTnGE" }
+ );
+ } else {
+ if (!iconOnly && !showPrice) {
+ return fbt._("Gift", null, { hk: "3fqfrk" });
+ }
+ }
}
};
$[0] = t0;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/nested-function-shadowed-identifiers.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/nested-function-shadowed-identifiers.expect.md
index 920c0b9f38..f773e12499 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/nested-function-shadowed-identifiers.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/nested-function-shadowed-identifiers.expect.md
@@ -25,8 +25,7 @@ function Component(props) {
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = (e) => {
- let x_0 = null; // intentionally shadow the original x
- setX((currentX) => currentX + x_0); // intentionally refer to shadowed x
+ setX((currentX) => currentX + null);
};
$[0] = t0;
} else {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/prop-capturing-function-1.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/prop-capturing-function-1.expect.md
index aad034ab9f..75916c7f26 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/prop-capturing-function-1.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/prop-capturing-function-1.expect.md
@@ -5,7 +5,7 @@
function component(a, b) {
let z = { a, b };
let x = function () {
- z;
+ console.log(z);
};
return x;
}
@@ -34,7 +34,7 @@ function component(a, b) {
let t1;
if (c_3) {
t1 = function () {
- z;
+ console.log(z);
};
$[3] = z;
$[4] = t1;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/prop-capturing-function-1.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/prop-capturing-function-1.js
index 0817daa5d1..24690f84fa 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/prop-capturing-function-1.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/prop-capturing-function-1.js
@@ -1,7 +1,7 @@
function component(a, b) {
let z = { a, b };
let x = function () {
- z;
+ console.log(z);
};
return x;
}
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassign-object-in-context.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassign-object-in-context.expect.md
index 09ba32a349..0056d5b9bf 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassign-object-in-context.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassign-object-in-context.expect.md
@@ -25,6 +25,7 @@ function Component(props) {
const foo = () => {
x = {};
};
+
foo();
$[0] = x;
} else {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassign-primitive-in-context.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassign-primitive-in-context.expect.md
index 9a86508d0c..c84aefe702 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassign-primitive-in-context.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassign-primitive-in-context.expect.md
@@ -25,6 +25,7 @@ function Component(props) {
const foo = () => {
x = {};
};
+
foo();
$[0] = x;
} else {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.expect.md
index 13e811b62f..3b093b9fa1 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.expect.md
@@ -2,7 +2,6 @@
## Input
```javascript
-// @enableOptimizeFunctionExpressions
function Component(props) {
return () => {
let str;
@@ -20,7 +19,7 @@ function Component(props) {
## Code
```javascript
-import { unstable_useMemoCache as useMemoCache } from "react"; // @enableOptimizeFunctionExpressions
+import { unstable_useMemoCache as useMemoCache } from "react";
function Component(props) {
const $ = useMemoCache(2);
const c_0 = $[0] !== props.str;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.js
index dcf5ecc79c..51f1d3dd16 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/reassigned-phi-in-returned-function-expression.js
@@ -1,4 +1,3 @@
-// @enableOptimizeFunctionExpressions
function Component(props) {
return () => {
let str;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-no-added-to-dep.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-no-added-to-dep.expect.md
index 351873f98a..d5123308cf 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-no-added-to-dep.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-no-added-to-dep.expect.md
@@ -7,7 +7,7 @@ function VideoTab() {
const ref = useRef();
const t = ref.current;
let x = () => {
- t;
+ console.log(t);
};
return ;
@@ -26,7 +26,7 @@ function VideoTab() {
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => {
- t;
+ console.log(t);
};
$[0] = t0;
} else {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-no-added-to-dep.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-no-added-to-dep.js
index e11fb47247..e3ff619ffa 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-no-added-to-dep.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-aliased-no-added-to-dep.js
@@ -3,7 +3,7 @@ function VideoTab() {
const ref = useRef();
const t = ref.current;
let x = () => {
- t;
+ console.log(t);
};
return ;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-not-added-to-dep.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-not-added-to-dep.expect.md
index bb151446f6..0eb838997a 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-not-added-to-dep.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-not-added-to-dep.expect.md
@@ -6,7 +6,7 @@
function VideoTab() {
const ref = useRef();
let x = () => {
- ref.current.x;
+ console.log(ref.current.x);
};
return ;
@@ -24,7 +24,7 @@ function VideoTab() {
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => {
- ref.current.x;
+ console.log(ref.current.x);
};
$[0] = t0;
} else {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-not-added-to-dep.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-not-added-to-dep.js
index fd5c43cdba..7aaee3b21a 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-not-added-to-dep.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-field-not-added-to-dep.js
@@ -2,7 +2,7 @@
function VideoTab() {
const ref = useRef();
let x = () => {
- ref.current.x;
+ console.log(ref.current.x);
};
return ;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep.expect.md
index 9f8e8a776d..2f826ef998 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep.expect.md
@@ -5,7 +5,7 @@
function VideoTab() {
const ref = useRef();
let x = () => {
- ref.current;
+ console.log(ref.current);
};
return ;
@@ -23,7 +23,7 @@ function VideoTab() {
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => {
- ref.current;
+ console.log(ref.current);
};
$[0] = t0;
} else {
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep.js
index f3d6f574fe..0b08ef7b87 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep.js
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-current-not-added-to-dep.js
@@ -1,7 +1,7 @@
function VideoTab() {
const ref = useRef();
let x = () => {
- ref.current;
+ console.log(ref.current);
};
return ;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/remove-memoization-kitchen-sink.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/remove-memoization-kitchen-sink.expect.md
index e2449aadab..12b9c8d682 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/remove-memoization-kitchen-sink.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/remove-memoization-kitchen-sink.expect.md
@@ -26,6 +26,7 @@ function Component(props) {
const onChange = (e) => {
setX(e.target.value);
};
+
const object = { x, onChange };
const { x: x_0, onChange: onChange_0 } = object;
diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-scope-missing-mutable-range.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-scope-missing-mutable-range.expect.md
index 30f86b01b9..3014745db0 100644
--- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-scope-missing-mutable-range.expect.md
+++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-scope-missing-mutable-range.expect.md
@@ -26,7 +26,7 @@ function HomeDiscoStoreItemTileRating(props) {
count = 0;
const aggregates = item?.aggregates || [];
aggregates.forEach((aggregate) => {
- count += aggregate.count || 0;
+ count = count + (aggregate.count || 0);
});
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
diff --git a/compiler/forget/packages/snap/src/compiler-worker.ts b/compiler/forget/packages/snap/src/compiler-worker.ts
index a644ccc413..67c37f0e78 100644
--- a/compiler/forget/packages/snap/src/compiler-worker.ts
+++ b/compiler/forget/packages/snap/src/compiler-worker.ts
@@ -98,7 +98,7 @@ export async function compile(
let disableAllMemoization = false;
let validateRefAccessDuringRender = true;
let enableEmitFreeze = null;
- let enableOptimizeFunctionExpressions = false;
+ let enableOptimizeFunctionExpressions = true;
if (firstLine.indexOf("@forgetDirective") !== -1) {
enableOnlyOnUseForgetDirective = true;
}
@@ -132,8 +132,8 @@ export async function compile(
if (firstLine.includes("@validateRefAccessDuringRender false")) {
validateRefAccessDuringRender = false;
}
- if (firstLine.includes("@enableOptimizeFunctionExpressions")) {
- enableOptimizeFunctionExpressions = true;
+ if (firstLine.includes("@enableOptimizeFunctionExpressions false")) {
+ enableOptimizeFunctionExpressions = false;
}
if (firstLine.includes("@enableEmitFreeze")) {
enableEmitFreeze = {