[valueblocks] ternary tests showing assignment bug
A ternary that reassigns the same variable in both branches causes some weirdness with LeaveSSA, this PR just adds the failing case.
Joe Savona committed
Jan 31, 2023 at 13:39 UTC
8c13c91f274c140ec7b233d4e567b630469f248a
4 files changed
+77
compiler/forget/src/__tests__/fixtures/hir/ternary-assignment-expression.expect.md
new
+13
@@ -0,0 +1,13 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+
6
+```
7
+
8
+## Code
9
+
10
+```javascript
11
+
12
+```
13
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/ternary-assignment-expression.js
new
+6
@@ -0,0 +1,6 @@
1
+// @only
2
+function ternary(props) {
3
+ let x = 0;
4
+ const y = props.a ? (x = 1) : (x = 2);
5
+ return x + y;
6
+}
compiler/forget/src/__tests__/fixtures/hir/ternary-expression.expect.md
new
+53
@@ -0,0 +1,53 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function ternary(props) {
6
+ const a = props.a && props.b ? props.c || props.d : props.e ?? props.f;
7
+ const b = props.a ? (props.b && props.c ? props.d : props.e) : props.f;
8
+ return a ? b : null;
9
+}
10
+
11
+```
12
+
13
+## Code
14
+
15
+```javascript
16
+function ternary(props) {
17
+ const $ = React.useMemoCache();
18
+ const c_0 = $[0] !== props;
19
+ let t1;
20
+ if (c_0) {
21
+ t1 = props.a && props.b ? props.c || props.d : props.e ?? props.f;
22
+ $[0] = props;
23
+ $[1] = t1;
24
+ } else {
25
+ t1 = $[1];
26
+ }
27
+ const a = t1;
28
+ const c_2 = $[2] !== props;
29
+ let t3;
30
+ if (c_2) {
31
+ t3 = props.a ? (props.b && props.c ? props.d : props.e) : props.f;
32
+ $[2] = props;
33
+ $[3] = t3;
34
+ } else {
35
+ t3 = $[3];
36
+ }
37
+ const b = t3;
38
+ const c_4 = $[4] !== a;
39
+ const c_5 = $[5] !== b;
40
+ let t6;
41
+ if (c_4 || c_5) {
42
+ t6 = a ? b : null;
43
+ $[4] = a;
44
+ $[5] = b;
45
+ $[6] = t6;
46
+ } else {
47
+ t6 = $[6];
48
+ }
49
+ return t6;
50
+}
51
+
52
+```
53
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/ternary-expression.js
new
+5
@@ -0,0 +1,5 @@
1
+function ternary(props) {
2
+ const a = props.a && props.b ? props.c || props.d : props.e ?? props.f;
3
+ const b = props.a ? (props.b && props.c ? props.d : props.e) : props.f;
4
+ return a ? b : null;
5
+}