Repro for destructure declaration of context variable

We don't have a `DestructureContext` equivalent of `StoreContext`, so variables 
that are declared via destructuring and later reassigned trigger the invariant 
that all mentions of a variable must be consistently local or context. The next 
PR adds a todo for this case.
This commit is contained in:
Joe Savona
2024-03-21 17:12:09 -07:00
parent 231f29f6f3
commit e8073ff16c
2 changed files with 45 additions and 0 deletions
@@ -0,0 +1,33 @@
## Input
```javascript
import { Stringify } from "shared-runtime";
function Component({ foo }) {
let bar = foo.bar;
return (
<Stringify
handler={() => {
foo = true;
}}
/>
);
}
```
## Error
```
2 |
3 | function Component({ foo }) {
> 4 | let bar = foo.bar;
| ^^^ [ReactForget] Invariant: Expected all references to a variable to be consistently local or context references. Identifier <unknown> foo$1 is referenced as a context variable, but was previously referenced as a local variable (4:4)
5 | return (
6 | <Stringify
7 | handler={() => {
```
@@ -0,0 +1,12 @@
import { Stringify } from "shared-runtime";
function Component({ foo }) {
let bar = foo.bar;
return (
<Stringify
handler={() => {
foo = true;
}}
/>
);
}