From dda3e61347fde65b62ed2b17ead463685cb35814 Mon Sep 17 00:00:00 2001 From: Mofei Zhang Date: Fri, 12 May 2023 12:48:18 -0400 Subject: [PATCH] [test cases] Add failing / bug tests for destructuring assignment --- ...destructure-assignment-to-global.expect.md | 29 +++++++++++++++++++ .../_bug.destructure-assignment-to-global.js | 4 +++ ...ucture-assignment-to-context-var.expect.md | 24 +++++++++++++++ ...o.destructure-assignment-to-context-var.js | 9 ++++++ 4 files changed, 66 insertions(+) create mode 100644 compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-assignment-to-global.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-assignment-to-global.js create mode 100644 compiler/forget/src/__tests__/fixtures/compiler/error.todo.destructure-assignment-to-context-var.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/compiler/error.todo.destructure-assignment-to-context-var.js 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 }; +}