From 721b6a4f91b883f353217f42e5d90f4e4efbf1da Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Mon, 18 Dec 2023 13:35:56 +0000 Subject: [PATCH] [patch] Compile hooks with any number of args in infer mode --- .../scripts/babel-plugin-annotate-react-code.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/packages/babel-plugin-react-forget/scripts/babel-plugin-annotate-react-code.ts b/compiler/packages/babel-plugin-react-forget/scripts/babel-plugin-annotate-react-code.ts index ea36f7f18e..454e6c5cf2 100644 --- a/compiler/packages/babel-plugin-react-forget/scripts/babel-plugin-annotate-react-code.ts +++ b/compiler/packages/babel-plugin-react-forget/scripts/babel-plugin-annotate-react-code.ts @@ -105,10 +105,7 @@ function isComponentOrHookLike( ): boolean { const functionName = getFunctionName(node); // Check if the name is component or hook like: - if ( - functionName !== null && - (isComponentName(functionName) || isHook(functionName)) - ) { + if (functionName !== null && isComponentName(functionName)) { return ( // As an added check we also look for hook invocations or JSX callsHooksOrCreatesJsx(node) && @@ -119,7 +116,11 @@ function isComponentOrHookLike( */ node.get("params").length <= 1 ); + } else if (functionName !== null && isHook(functionName)) { + // Hooks have hook invocations or JSX, but can take any # of arguments + return callsHooksOrCreatesJsx(node); } + /* * Otherwise for function or arrow function expressions, check if they * appear as the argument to React.forwardRef() or React.memo():