From e8073ff16cc75e0e5be098a1ee0870544725bd60 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Thu, 21 Mar 2024 17:12:09 -0700 Subject: [PATCH] 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. --- .../error.todo-reassign-const.expect.md | 33 +++++++++++++++++++ .../compiler/error.todo-reassign-const.js | 12 +++++++ 2 files changed, 45 insertions(+) create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-const.expect.md create mode 100644 compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-const.js diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-const.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-const.expect.md new file mode 100644 index 0000000000..14a29be062 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-const.expect.md @@ -0,0 +1,33 @@ + +## Input + +```javascript +import { Stringify } from "shared-runtime"; + +function Component({ foo }) { + let bar = foo.bar; + return ( + { + 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 foo$1 is referenced as a context variable, but was previously referenced as a local variable (4:4) + 5 | return ( + 6 | { +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-const.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-const.js new file mode 100644 index 0000000000..3a54e0c599 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.todo-reassign-const.js @@ -0,0 +1,12 @@ +import { Stringify } from "shared-runtime"; + +function Component({ foo }) { + let bar = foo.bar; + return ( + { + foo = true; + }} + /> + ); +}