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:
Joe Savona committed 2024-03-22 11:53:29 -07:00
1 parent e7d0c81d13
commit fb0f7e5c39
4 files changed
+70

No files matched your search

@@ -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 |
```
@@ -0,0 +1,8 @@
function Component() {
let callback = () => {
onClick = () => {};
};
let onClick;
return <div onClick={callback} />;
}
@@ -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 | }
```
@@ -0,0 +1,6 @@
function Component() {
let callback = () => {
callback = null;
};
return <div onClick={callback} />;
}