mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Repro for closures reassigning hoisted let variables
Adds examples for closures that reassign hoisted let bindings. We currently compile these as context variables without hoisting, so we hit an invariant in InferReferenceEffects when the variable is referenced before being declared.
This commit is contained in:
1 parent
e7d0c81d13
commit
fb0f7e5c39
4 files changed
+70
No files matched your search
+29
@@ -0,0 +1,29 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component() {
|
||||
let callback = () => {
|
||||
onClick = () => {};
|
||||
};
|
||||
let onClick;
|
||||
|
||||
return <div onClick={callback} />;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
1 | function Component() {
|
||||
2 | let callback = () => {
|
||||
> 3 | onClick = () => {};
|
||||
| ^^^^^^^ [ReactForget] Invariant: [hoisting] Expected value kind to be initialized. read onClick$0_@1 (3:3)
|
||||
4 | };
|
||||
5 | let onClick;
|
||||
6 |
|
||||
```
|
||||
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
function Component() {
|
||||
let callback = () => {
|
||||
onClick = () => {};
|
||||
};
|
||||
let onClick;
|
||||
|
||||
return <div onClick={callback} />;
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
function Component() {
|
||||
let callback = () => {
|
||||
callback = null;
|
||||
};
|
||||
return <div onClick={callback} />;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
1 | function Component() {
|
||||
2 | let callback = () => {
|
||||
> 3 | callback = null;
|
||||
| ^^^^^^^^ [ReactForget] Invariant: [hoisting] Expected value kind to be initialized. read callback$0_@0 (3:3)
|
||||
4 | };
|
||||
5 | return <div onClick={callback} />;
|
||||
6 | }
|
||||
```
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
function Component() {
|
||||
let callback = () => {
|
||||
callback = null;
|
||||
};
|
||||
return <div onClick={callback} />;
|
||||
}
|
||||
Reference in new issue
Block a user