diff --git a/compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-assignment-to-global.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-assignment-to-global.expect.md new file mode 100644 index 0000000000..351aee8e97 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-assignment-to-global.expect.md @@ -0,0 +1,29 @@ + +## Input + +```javascript +function useFoo(props) { + [x] = props; + return { x }; +} + +``` + +## Code + +```javascript +import { unstable_useMemoCache as useMemoCache } from "react"; +function useFoo(props) { + const $ = useMemoCache(1); + let t0; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + t0 = { x }; + $[0] = t0; + } else { + t0 = $[0]; + } + return t0; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-assignment-to-global.js b/compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-assignment-to-global.js new file mode 100644 index 0000000000..9bd077cdef --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-assignment-to-global.js @@ -0,0 +1,4 @@ +function useFoo(props) { + [x] = props; + return { x }; +} diff --git a/compiler/forget/src/__tests__/fixtures/compiler/error.todo.destructure-assignment-to-context-var.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/error.todo.destructure-assignment-to-context-var.expect.md new file mode 100644 index 0000000000..86a7bd262a --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/error.todo.destructure-assignment-to-context-var.expect.md @@ -0,0 +1,24 @@ + +## Input + +```javascript +function useFoo(props) { + let x; + [x] = props; + const foo = () => { + x = getX(props); + }; + foo(); + return { x }; +} + +``` + + +## Error + +``` +[InferReferenceEffects] Context variables are always mutable. +``` + + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/error.todo.destructure-assignment-to-context-var.js b/compiler/forget/src/__tests__/fixtures/compiler/error.todo.destructure-assignment-to-context-var.js new file mode 100644 index 0000000000..6e2a09649d --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/error.todo.destructure-assignment-to-context-var.js @@ -0,0 +1,9 @@ +function useFoo(props) { + let x; + [x] = props; + const foo = () => { + x = getX(props); + }; + foo(); + return { x }; +}