[test cases] Add failing / bug tests for destructuring assignment
Mofei Zhang committed
May 12, 2023 at 12:48 UTC
dda3e61347fde65b62ed2b17ead463685cb35814
4 files changed
+66
compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-assignment-to-global.expect.md
new
+29
@@ -0,0 +1,29 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function useFoo(props) {
6
+ [x] = props;
7
+ return { x };
8
+}
9
+
10
+```
11
+
12
+## Code
13
+
14
+```javascript
15
+import { unstable_useMemoCache as useMemoCache } from "react";
16
+function useFoo(props) {
17
+ const $ = useMemoCache(1);
18
+ let t0;
19
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
20
+ t0 = { x };
21
+ $[0] = t0;
22
+ } else {
23
+ t0 = $[0];
24
+ }
25
+ return t0;
26
+}
27
+
28
+```
29
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/_bug.destructure-assignment-to-global.js
new
+4
@@ -0,0 +1,4 @@
1
+function useFoo(props) {
2
+ [x] = props;
3
+ return { x };
4
+}
compiler/forget/src/__tests__/fixtures/compiler/error.todo.destructure-assignment-to-context-var.expect.md
new
+24
@@ -0,0 +1,24 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function useFoo(props) {
6
+ let x;
7
+ [x] = props;
8
+ const foo = () => {
9
+ x = getX(props);
10
+ };
11
+ foo();
12
+ return { x };
13
+}
14
+
15
+```
16
+
17
+
18
+## Error
19
+
20
+```
21
+[InferReferenceEffects] Context variables are always mutable.
22
+```
23
+
24
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/error.todo.destructure-assignment-to-context-var.js
new
+9
@@ -0,0 +1,9 @@
1
+function useFoo(props) {
2
+ let x;
3
+ [x] = props;
4
+ const foo = () => {
5
+ x = getX(props);
6
+ };
7
+ foo();
8
+ return { x };
9
+}