[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
This commit is contained in:
Mofei Zhang
2023-12-14 19:42:24 -05:00
parent 651d3448ac
commit 06376b906d
2 changed files with 6 additions and 5 deletions
@@ -1019,7 +1019,8 @@ function createCallExpression(
const hookGuard = config.enableEmitHookGuards;
if (hookGuard != null && isHook) {
const iife = t.arrowFunctionExpression(
const iife = t.functionExpression(
null,
[],
t.blockStatement([
createHookGuard(
@@ -66,7 +66,7 @@ function Component(t47) {
} else {
t0 = $[0];
}
const [state, setState] = (() => {
const [state, setState] = (function () {
try {
$dispatcherGuard(2);
return useState(t0);
@@ -92,7 +92,7 @@ function Component(t47) {
t1 = $[2];
t2 = $[3];
}
(() => {
(function () {
try {
$dispatcherGuard(2);
return useEffect(t1, t2);
@@ -101,11 +101,11 @@ function Component(t47) {
}
})();
print(identity(value + state));
return (() => {
return (function () {
try {
$dispatcherGuard(2);
return ObjectWithHooks.useIdentity(
(() => {
(function () {
try {
$dispatcherGuard(2);
return useContext(MyContext);