mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[hir] Check if defined before looking up ValueKind
This handles globals now without throwing
This commit is contained in:
@@ -851,7 +851,9 @@ export function parseHookCall(place: Place): Hook | null {
|
||||
|
||||
function hasContextRefOperand(env: Environment, instrValue: InstructionValue) {
|
||||
for (const place of eachInstructionValueOperand(instrValue)) {
|
||||
if (env.kind(place) === ValueKind.Context) return true;
|
||||
if (env.isDefined(place) && env.kind(place) === ValueKind.Context) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
let someGlobal = {};
|
||||
function component(a) {
|
||||
let x = { a, someGlobal };
|
||||
return x;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
let someGlobal = {};
|
||||
function component(a) {
|
||||
const $ = React.unstable_useMemoCache();
|
||||
const c_0 = $[0] !== a;
|
||||
let x;
|
||||
if (c_0) {
|
||||
x = { a: a, someGlobal: someGlobal };
|
||||
$[0] = a;
|
||||
$[1] = x;
|
||||
} else {
|
||||
x = $[1];
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
let someGlobal = {};
|
||||
function component(a) {
|
||||
let x = { a, someGlobal };
|
||||
return x;
|
||||
}
|
||||
Reference in New Issue
Block a user