mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[patch] Compile hooks with any number of args in infer mode
This commit is contained in:
@@ -489,10 +489,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) &&
|
||||
@@ -503,7 +500,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():
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @compilationMode(infer)
|
||||
import { useNoAlias } from "shared-runtime";
|
||||
|
||||
// This should be compiled by Forget
|
||||
function useFoo(value1, value2) {
|
||||
return {
|
||||
value: useNoAlias(value1 + value2),
|
||||
};
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: useFoo,
|
||||
params: [1, 2],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react"; // @compilationMode(infer)
|
||||
import { useNoAlias } from "shared-runtime";
|
||||
|
||||
// This should be compiled by Forget
|
||||
function useFoo(value1, value2) {
|
||||
const $ = useMemoCache(2);
|
||||
|
||||
const t0 = useNoAlias(value1 + value2);
|
||||
let t1;
|
||||
if ($[0] !== t0) {
|
||||
t1 = { value: t0 };
|
||||
$[0] = t0;
|
||||
$[1] = t1;
|
||||
} else {
|
||||
t1 = $[1];
|
||||
}
|
||||
return t1;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: useFoo,
|
||||
params: [1, 2],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) {"value":{}}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// @compilationMode(infer)
|
||||
import { useNoAlias } from "shared-runtime";
|
||||
|
||||
// This should be compiled by Forget
|
||||
function useFoo(value1, value2) {
|
||||
return {
|
||||
value: useNoAlias(value1 + value2),
|
||||
};
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: useFoo,
|
||||
params: [1, 2],
|
||||
};
|
||||
Reference in New Issue
Block a user