Repro of undefined expressioncontainer expression
Repro from T169063835. This works, but since it came up it seems good to add a test case for it just in case there's something funny here that we could regress on w/o realizing it.
Joe Savona committed
Nov 15, 2023 at 14:23 UTC
6a1343c82be8382cfa46605233334b7d1707dea9
2 files changed
+148
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-undefined-expression-of-jsxexpressioncontainer.expect.md
new
+114
@@ -0,0 +1,114 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component(props) {
6
+ const { buttons } = props;
7
+ const [primaryButton, ...nonPrimaryButtons] = buttons;
8
+
9
+ const renderedNonPrimaryButtons = nonPrimaryButtons.map((buttonProps, i) => (
10
+ <Button
11
+ {...buttonProps}
12
+ key={`button-${i}`}
13
+ style={
14
+ i % 2 === 0 ? styles.leftSecondaryButton : styles.rightSecondaryButton
15
+ }
16
+ />
17
+ ));
18
+
19
+ return <View>{renderedNonPrimaryButtons}</View>;
20
+}
21
+
22
+const styles = {
23
+ leftSecondaryButton: { left: true },
24
+ rightSecondaryButton: { right: true },
25
+};
26
+
27
+export const FIXTURE_ENTRYPOINT = {
28
+ fn: Component,
29
+ params: [
30
+ {
31
+ buttons: [
32
+ {},
33
+ { type: "submit", children: ["Submit!"] },
34
+ { type: "button", children: ["Reset"] },
35
+ ],
36
+ },
37
+ ],
38
+};
39
+
40
+```
41
+
42
+## Code
43
+
44
+```javascript
45
+import { unstable_useMemoCache as useMemoCache } from "react";
46
+function Component(props) {
47
+ const $ = useMemoCache(7);
48
+ const { buttons } = props;
49
+ let nonPrimaryButtons;
50
+ if ($[0] !== buttons) {
51
+ const [primaryButton, ...t79] = buttons;
52
+ nonPrimaryButtons = t79;
53
+ $[0] = buttons;
54
+ $[1] = nonPrimaryButtons;
55
+ } else {
56
+ nonPrimaryButtons = $[1];
57
+ }
58
+ let t1;
59
+ if ($[2] !== nonPrimaryButtons) {
60
+ let t0;
61
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
62
+ t0 = (buttonProps, i) => (
63
+ <Button
64
+ {...buttonProps}
65
+ key={`button-${i}`}
66
+ style={
67
+ i % 2 === 0
68
+ ? styles.leftSecondaryButton
69
+ : styles.rightSecondaryButton
70
+ }
71
+ />
72
+ );
73
+ $[4] = t0;
74
+ } else {
75
+ t0 = $[4];
76
+ }
77
+ t1 = nonPrimaryButtons.map(t0);
78
+ $[2] = nonPrimaryButtons;
79
+ $[3] = t1;
80
+ } else {
81
+ t1 = $[3];
82
+ }
83
+ const renderedNonPrimaryButtons = t1;
84
+ let t2;
85
+ if ($[5] !== renderedNonPrimaryButtons) {
86
+ t2 = <View>{renderedNonPrimaryButtons}</View>;
87
+ $[5] = renderedNonPrimaryButtons;
88
+ $[6] = t2;
89
+ } else {
90
+ t2 = $[6];
91
+ }
92
+ return t2;
93
+}
94
+
95
+const styles = {
96
+ leftSecondaryButton: { left: true },
97
+ rightSecondaryButton: { right: true },
98
+};
99
+
100
+export const FIXTURE_ENTRYPOINT = {
101
+ fn: Component,
102
+ params: [
103
+ {
104
+ buttons: [
105
+ {},
106
+ { type: "submit", children: ["Submit!"] },
107
+ { type: "button", children: ["Reset"] },
108
+ ],
109
+ },
110
+ ],
111
+};
112
+
113
+```
114
+
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/repro-undefined-expression-of-jsxexpressioncontainer.js
new
+34
@@ -0,0 +1,34 @@
1
+function Component(props) {
2
+ const { buttons } = props;
3
+ const [primaryButton, ...nonPrimaryButtons] = buttons;
4
+
5
+ const renderedNonPrimaryButtons = nonPrimaryButtons.map((buttonProps, i) => (
6
+ <Button
7
+ {...buttonProps}
8
+ key={`button-${i}`}
9
+ style={
10
+ i % 2 === 0 ? styles.leftSecondaryButton : styles.rightSecondaryButton
11
+ }
12
+ />
13
+ ));
14
+
15
+ return <View>{renderedNonPrimaryButtons}</View>;
16
+}
17
+
18
+const styles = {
19
+ leftSecondaryButton: { left: true },
20
+ rightSecondaryButton: { right: true },
21
+};
22
+
23
+export const FIXTURE_ENTRYPOINT = {
24
+ fn: Component,
25
+ params: [
26
+ {
27
+ buttons: [
28
+ {},
29
+ { type: "submit", children: ["Submit!"] },
30
+ { type: "button", children: ["Reset"] },
31
+ ],
32
+ },
33
+ ],
34
+};