@samitouri / QOS-React-2 / commits / 06376b906d

[patch] Generate hook guards as function expressions

--- Arrow functions are not compatible with es3, which we sometimes target. This helps us make babel transform logic less complex

Mofei Zhang committed Dec 14, 2023 at 19:42 UTC 06376b906d173ee03e49bbbb6277393b9015cf0a
2 files changed +6 -5
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+2 -1
@@ -1019,7 +1019,8 @@ function createCallExpression(
1019
1020 const hookGuard = config.enableEmitHookGuards;
1021 if (hookGuard != null && isHook) {
1022 - const iife = t.arrowFunctionExpression(
1022 + const iife = t.functionExpression(
1023 + null,
1024 [],
1025 t.blockStatement([
1026 createHookGuard(
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/flag-enable-emit-hook-guards.expect.md
+4 -4
@@ -66,7 +66,7 @@ function Component(t47) {
66 } else {
67 t0 = $[0];
68 }
69 - const [state, setState] = (() => {
69 + const [state, setState] = (function () {
70 try {
71 $dispatcherGuard(2);
72 return useState(t0);
@@ -92,7 +92,7 @@ function Component(t47) {
92 t1 = $[2];
93 t2 = $[3];
94 }
95 - (() => {
95 + (function () {
96 try {
97 $dispatcherGuard(2);
98 return useEffect(t1, t2);
@@ -101,11 +101,11 @@ function Component(t47) {
101 }
102 })();
103 print(identity(value + state));
104 - return (() => {
104 + return (function () {
105 try {
106 $dispatcherGuard(2);
107 return ObjectWithHooks.useIdentity(
108 - (() => {
108 + (function () {
109 try {
110 $dispatcherGuard(2);
111 return useContext(MyContext);