[hir] Add invariant to check if useMemo callback accepts args

This commit is contained in:
Sathya Gunasekaran
2023-04-11 15:00:30 +01:00
parent 74f5e26e00
commit fd252e42ab
3 changed files with 33 additions and 0 deletions
@@ -100,6 +100,14 @@ export function inlineUseMemo(fn: HIRFunction): void {
lambda.loc
);
}
if (body.loweredFunc.params.length > 0) {
CompilerError.invariant(
"Did not expect any arguments to useMemo callback",
body.loc
);
}
// We know this function is used for useMemo and can prune it later
useMemoFunctions.add(lambda.identifier.id);
@@ -0,0 +1,20 @@
## Input
```javascript
// @inlineUseMemo
function component(a, b) {
let x = useMemo((c) => a, []);
return x;
}
```
## Error
```
[ReactForget] Invariant: Did not expect any arguments to useMemo callback (3:3)
```
@@ -0,0 +1,5 @@
// @inlineUseMemo
function component(a, b) {
let x = useMemo((c) => a, []);
return x;
}