Repro for for..of scoping bug
ghstack-source-id: 6147b6e70d24203350664e8ab24691d1ec5c5b2a Pull Request resolved: https://github.com/facebook/react-forget/pull/2891
Joe Savona committed
Apr 24, 2024 at 14:59 UTC
6304e98902a451b53f3e2ce9315584252443e6ac
5 files changed
+222
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/for-of-immutable-collection.expect.md
new
+81
@@ -0,0 +1,81 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Router({ title, mapping }) {
6
+ const array = [];
7
+ for (let [, entry] of mapping) {
8
+ array.push([title, entry]);
9
+ }
10
+ return array;
11
+}
12
+
13
+const routes = new Map([
14
+ ["about", "/about"],
15
+ ["contact", "/contact"],
16
+]);
17
+
18
+export const FIXTURE_ENTRYPOINT = {
19
+ fn: Router,
20
+ params: [],
21
+ sequentialRenders: [
22
+ {
23
+ title: "Foo",
24
+ mapping: routes,
25
+ },
26
+ {
27
+ title: "Bar",
28
+ mapping: routes,
29
+ },
30
+ ],
31
+};
32
+
33
+```
34
+
35
+## Code
36
+
37
+```javascript
38
+import { unstable_useMemoCache as useMemoCache } from "react";
39
+function Router(t0) {
40
+ const $ = useMemoCache(3);
41
+ const { title, mapping } = t0;
42
+ let array;
43
+ if ($[0] !== mapping || $[1] !== title) {
44
+ array = [];
45
+ for (const [, entry] of mapping) {
46
+ array.push([title, entry]);
47
+ }
48
+ $[0] = mapping;
49
+ $[1] = title;
50
+ $[2] = array;
51
+ } else {
52
+ array = $[2];
53
+ }
54
+ return array;
55
+}
56
+
57
+const routes = new Map([
58
+ ["about", "/about"],
59
+ ["contact", "/contact"],
60
+]);
61
+
62
+export const FIXTURE_ENTRYPOINT = {
63
+ fn: Router,
64
+ params: [],
65
+ sequentialRenders: [
66
+ {
67
+ title: "Foo",
68
+ mapping: routes,
69
+ },
70
+ {
71
+ title: "Bar",
72
+ mapping: routes,
73
+ },
74
+ ],
75
+};
76
+
77
+```
78
+
79
+### Eval output
80
+(kind: ok) [["Foo","/about"],["Foo","/contact"]]
81
+[["Bar","/about"],["Bar","/contact"]]
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/for-of-immutable-collection.js
new
+27
@@ -0,0 +1,27 @@
1
+function Router({ title, mapping }) {
2
+ const array = [];
3
+ for (let [, entry] of mapping) {
4
+ array.push([title, entry]);
5
+ }
6
+ return array;
7
+}
8
+
9
+const routes = new Map([
10
+ ["about", "/about"],
11
+ ["contact", "/contact"],
12
+]);
13
+
14
+export const FIXTURE_ENTRYPOINT = {
15
+ fn: Router,
16
+ params: [],
17
+ sequentialRenders: [
18
+ {
19
+ title: "Foo",
20
+ mapping: routes,
21
+ },
22
+ {
23
+ title: "Bar",
24
+ mapping: routes,
25
+ },
26
+ ],
27
+};
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/for-of-iterator-of-immutable-collection.expect.md
new
+86
@@ -0,0 +1,86 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Router({ title, mapping }) {
6
+ const array = [];
7
+ for (let entry of mapping.values()) {
8
+ array.push([title, entry]);
9
+ }
10
+ return array;
11
+}
12
+
13
+const routes = new Map([
14
+ ["about", "/about"],
15
+ ["contact", "/contact"],
16
+]);
17
+
18
+export const FIXTURE_ENTRYPOINT = {
19
+ fn: Router,
20
+ params: [],
21
+ sequentialRenders: [
22
+ {
23
+ title: "Foo",
24
+ mapping: routes,
25
+ },
26
+ {
27
+ title: "Bar",
28
+ mapping: routes,
29
+ },
30
+ ],
31
+};
32
+
33
+```
34
+
35
+## Code
36
+
37
+```javascript
38
+import { unstable_useMemoCache as useMemoCache } from "react";
39
+function Router(t0) {
40
+ const $ = useMemoCache(5);
41
+ const { title, mapping } = t0;
42
+ let array;
43
+ if ($[0] !== mapping || $[1] !== title) {
44
+ array = [];
45
+ let t1;
46
+ if ($[3] !== mapping) {
47
+ t1 = mapping.values();
48
+ $[3] = mapping;
49
+ $[4] = t1;
50
+ } else {
51
+ t1 = $[4];
52
+ }
53
+ for (const entry of t1) {
54
+ array.push([title, entry]);
55
+ }
56
+ $[0] = mapping;
57
+ $[1] = title;
58
+ $[2] = array;
59
+ } else {
60
+ array = $[2];
61
+ }
62
+ return array;
63
+}
64
+
65
+const routes = new Map([
66
+ ["about", "/about"],
67
+ ["contact", "/contact"],
68
+]);
69
+
70
+export const FIXTURE_ENTRYPOINT = {
71
+ fn: Router,
72
+ params: [],
73
+ sequentialRenders: [
74
+ {
75
+ title: "Foo",
76
+ mapping: routes,
77
+ },
78
+ {
79
+ title: "Bar",
80
+ mapping: routes,
81
+ },
82
+ ],
83
+};
84
+
85
+```
86
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/for-of-iterator-of-immutable-collection.js
new
+27
@@ -0,0 +1,27 @@
1
+function Router({ title, mapping }) {
2
+ const array = [];
3
+ for (let entry of mapping.values()) {
4
+ array.push([title, entry]);
5
+ }
6
+ return array;
7
+}
8
+
9
+const routes = new Map([
10
+ ["about", "/about"],
11
+ ["contact", "/contact"],
12
+]);
13
+
14
+export const FIXTURE_ENTRYPOINT = {
15
+ fn: Router,
16
+ params: [],
17
+ sequentialRenders: [
18
+ {
19
+ title: "Foo",
20
+ mapping: routes,
21
+ },
22
+ {
23
+ title: "Bar",
24
+ mapping: routes,
25
+ },
26
+ ],
27
+};
compiler/packages/snap/src/SproutTodoFilter.ts
+1
@@ -489,6 +489,7 @@ const skipFilter = new Set([
489
490
// bugs
491
"bug-invalid-reactivity-value-block",
492
+ "for-of-iterator-of-immutable-collection",
493
494
// 'react-forget-runtime' not yet supported
495
"flag-enable-emit-hook-guards",