@samitouri / QOS-React-2 / commits / 721b6a4f91

[patch] Compile hooks with any number of args in infer mode

Sathya Gunasekaran committed Dec 18, 2023 at 13:35 UTC 721b6a4f91b883f353217f42e5d90f4e4efbf1da
1 file changed +5 -4
compiler/packages/babel-plugin-react-forget/scripts/babel-plugin-annotate-react-code.ts
+5 -4
@@ -105,10 +105,7 @@ function isComponentOrHookLike(
105 ): boolean {
106 const functionName = getFunctionName(node);
107 // Check if the name is component or hook like:
108 - if (
109 - functionName !== null &&
110 - (isComponentName(functionName) || isHook(functionName))
111 - ) {
108 + if (functionName !== null && isComponentName(functionName)) {
109 return (
110 // As an added check we also look for hook invocations or JSX
111 callsHooksOrCreatesJsx(node) &&
@@ -119,7 +116,11 @@ function isComponentOrHookLike(
116 */
117 node.get("params").length <= 1
118 );
119 + } else if (functionName !== null && isHook(functionName)) {
120 + // Hooks have hook invocations or JSX, but can take any # of arguments
121 + return callsHooksOrCreatesJsx(node);
122 }
123 +
124 /*
125 * Otherwise for function or arrow function expressions, check if they
126 * appear as the argument to React.forwardRef() or React.memo():