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.
Joe Savona committed
Mar 21, 2024 at 17:12 UTC
e8073ff16cc75e0e5be098a1ee0870544725bd60
2 files changed
+45
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-const.expect.md
new
+33
@@ -0,0 +1,33 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+import { Stringify } from "shared-runtime";
6
+
7
+function Component({ foo }) {
8
+ let bar = foo.bar;
9
+ return (
10
+ <Stringify
11
+ handler={() => {
12
+ foo = true;
13
+ }}
14
+ />
15
+ );
16
+}
17
+
18
+```
19
+
20
+
21
+## Error
22
+
23
+```
24
+ 2 |
25
+ 3 | function Component({ foo }) {
26
+> 4 | let bar = foo.bar;
27
+ | ^^^ [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)
28
+ 5 | return (
29
+ 6 | <Stringify
30
+ 7 | handler={() => {
31
+```
32
+
33
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-const.js
new
+12
@@ -0,0 +1,12 @@
1
+import { Stringify } from "shared-runtime";
2
+
3
+function Component({ foo }) {
4
+ let bar = foo.bar;
5
+ return (
6
+ <Stringify
7
+ handler={() => {
8
+ foo = true;
9
+ }}
10
+ />
11
+ );
12
+}