mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Restore React.useMemo validation
This got lost by moving the validation earlier.
This commit is contained in:
@@ -10,6 +10,7 @@ import { FunctionExpression, HIRFunction, IdentifierId } from "../HIR";
|
||||
|
||||
export function validateUseMemo(fn: HIRFunction): void {
|
||||
const useMemos = new Set<IdentifierId>();
|
||||
const react = new Set<IdentifierId>();
|
||||
const functions = new Map<IdentifierId, FunctionExpression>();
|
||||
for (const [, block] of fn.body.blocks) {
|
||||
for (const { lvalue, value } of block.instructions) {
|
||||
@@ -17,6 +18,16 @@ export function validateUseMemo(fn: HIRFunction): void {
|
||||
case "LoadGlobal": {
|
||||
if (value.name === "useMemo") {
|
||||
useMemos.add(lvalue.identifier.id);
|
||||
} else if (value.name === "React") {
|
||||
react.add(lvalue.identifier.id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "PropertyLoad": {
|
||||
if (react.has(value.object.identifier.id)) {
|
||||
if (value.property === "useMemo") {
|
||||
useMemos.add(lvalue.identifier.id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function component(a, b) {
|
||||
let x = React.useMemo(async () => {
|
||||
await a;
|
||||
}, []);
|
||||
return x;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
[ReactForget] InvalidReact: useMemo callbacks may not be async or generator functions (2:4)
|
||||
```
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
function component(a, b) {
|
||||
let x = React.useMemo(async () => {
|
||||
await a;
|
||||
}, []);
|
||||
return x;
|
||||
}
|
||||
Reference in New Issue
Block a user