Repro for multiple declarations in for initializer codegen issue
Joe Savona committed
Mar 13, 2024 at 15:31 UTC
fe29f46de8ef57d30c29ccffde780927c1c986f5
3 files changed
+48
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/for-multiple-variable-declarations-in-initializer.expect.md
new
+38
@@ -0,0 +1,38 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component(props) {
6
+ const items = [];
7
+
8
+ for (let i = 0, length = props.items.length; i < length; i++) {
9
+ items.push(props.items[i]);
10
+ }
11
+
12
+ return items;
13
+}
14
+
15
+```
16
+
17
+## Code
18
+
19
+```javascript
20
+import { unstable_useMemoCache as useMemoCache } from "react";
21
+function Component(props) {
22
+ const $ = useMemoCache(2);
23
+ let items;
24
+ if ($[0] !== props.items) {
25
+ items = [];
26
+ for (let i = 0; i < length; i++) {
27
+ items.push(props.items[i]);
28
+ }
29
+ $[0] = props.items;
30
+ $[1] = items;
31
+ } else {
32
+ items = $[1];
33
+ }
34
+ return items;
35
+}
36
+
37
+```
38
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/for-multiple-variable-declarations-in-initializer.js
new
+9
@@ -0,0 +1,9 @@
1
+function Component(props) {
2
+ const items = [];
3
+
4
+ for (let i = 0, length = props.items.length; i < length; i++) {
5
+ items.push(props.items[i]);
6
+ }
7
+
8
+ return items;
9
+}
compiler/packages/snap/src/SproutTodoFilter.ts
+1
@@ -535,6 +535,7 @@ const skipFilter = new Set([
535
"bug-jsx-memberexpr-tag-in-lambda",
536
"bug-invalid-code-when-bailout",
537
"component-syntax-ref-gating.flow",
538
+ "for-multiple-variable-declarations-in-initializer",
539
540
// 'react-forget-runtime' not yet supported
541
"flag-enable-emit-hook-guards",