@samitouri / QOS-React-2 / commits / 1df89e992a

Remove unnecessary temporary in tests

We previously didn't support ternaries whose value was unused, so we had an extraneous temporary and console.log call to ensure the value counted as used. We now special-case ternary/conditional expressions which are in an ExpressionStatement to not prune them, so the temporary and log are now unnecessary.

Joe Savona committed Apr 27, 2023 at 10:43 UTC 1df89e992a7260d4690c3c82437d6d0ddd992d90
12 files changed +18 -48
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md
+2 -7
@@ -5,10 +5,7 @@
5 function foo(props) {
6 let x = [];
7 x.push(props.bar);
8 - const _ = props.cond
9 - ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo))
10 - : null;
11 - console.log(_);
8 + props.cond ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) : null;
9 mut(x);
10 return x;
11 }
@@ -26,9 +23,7 @@ function foo(props) {
23 if (c_0) {
24 x = [];
25 x.push(props.bar);
29 - const _ = props.cond ? (([x] = [[]]), x.push(props.foo)) : null;
30 -
31 - console.log(_);
26 + props.cond ? (([x] = [[]]), x.push(props.foo)) : null;
27 mut(x);
28 $[0] = props;
29 $[1] = x;
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.js
+1 -4
@@ -1,10 +1,7 @@
1 function foo(props) {
2 let x = [];
3 x.push(props.bar);
4 - const _ = props.cond
5 - ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo))
6 - : null;
7 - console.log(_);
4 + props.cond ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) : null;
5 mut(x);
6 return x;
7 }
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.expect.md
+2 -7
@@ -5,10 +5,7 @@
5 function foo(props) {
6 let x = [];
7 x.push(props.bar);
8 - const _ = props.cond
9 - ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo))
10 - : null;
11 - console.log(_);
8 + props.cond ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) : null;
9 return x;
10 }
11
@@ -41,9 +38,7 @@ function foo(props) {
38 t0 = $[3];
39 x = $[4];
40 }
44 - const _ = t0;
45 -
46 - console.log(_);
41 + t0;
42 return x;
43 }
44
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.js
+1 -4
@@ -1,9 +1,6 @@
1 function foo(props) {
2 let x = [];
3 x.push(props.bar);
4 - const _ = props.cond
5 - ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo))
6 - : null;
7 - console.log(_);
4 + props.cond ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) : null;
5 return x;
6 }
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md
+2 -4
@@ -5,8 +5,7 @@
5 function foo(props) {
6 let x = [];
7 x.push(props.bar);
8 - const _ = props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
9 - console.log(_);
8 + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
9 mut(x);
10 return x;
11 }
@@ -24,8 +23,7 @@ function foo(props) {
23 if (c_0) {
24 x = [];
25 x.push(props.bar);
27 - const _ = props.cond ? ((x = []), x.push(props.foo)) : null;
28 - console.log(_);
26 + props.cond ? ((x = []), x.push(props.foo)) : null;
27 mut(x);
28 $[0] = props;
29 $[1] = x;
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.js
+1 -2
@@ -1,8 +1,7 @@
1 function foo(props) {
2 let x = [];
3 x.push(props.bar);
4 - const _ = props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
5 - console.log(_);
4 + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
5 mut(x);
6 return x;
7 }
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary.expect.md
+2 -4
@@ -5,8 +5,7 @@
5 function foo(props) {
6 let x = [];
7 x.push(props.bar);
8 - const _ = props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
9 - console.log(_);
8 + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
9 return x;
10 }
11
@@ -39,8 +38,7 @@ function foo(props) {
38 t0 = $[3];
39 x = $[4];
40 }
42 - const _ = t0;
43 - console.log(_);
41 + t0;
42 return x;
43 }
44
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary.js
+1 -2
@@ -1,7 +1,6 @@
1 function foo(props) {
2 let x = [];
3 x.push(props.bar);
4 - const _ = props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
5 - console.log(_);
4 + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
5 return x;
6 }
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md
+2 -6
@@ -5,10 +5,9 @@
5 function foo(props) {
6 let x = [];
7 x.push(props.bar);
8 - const _ = props.cond
8 + props.cond
9 ? ((x = {}), (x = []), x.push(props.foo))
10 : ((x = []), (x = []), x.push(props.bar));
11 - console.log(_);
11 mut(x);
12 return x;
13 }
@@ -26,10 +25,7 @@ function foo(props) {
25 if (c_0) {
26 x = [];
27 x.push(props.bar);
29 - const _ = props.cond
30 - ? ((x = []), x.push(props.foo))
31 - : ((x = []), x.push(props.bar));
32 - console.log(_);
28 + props.cond ? ((x = []), x.push(props.foo)) : ((x = []), x.push(props.bar));
29 mut(x);
30 $[0] = props;
31 $[1] = x;
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.js
+1 -2
@@ -1,10 +1,9 @@
1 function foo(props) {
2 let x = [];
3 x.push(props.bar);
4 - const _ = props.cond
4 + props.cond
5 ? ((x = {}), (x = []), x.push(props.foo))
6 : ((x = []), (x = []), x.push(props.bar));
7 - console.log(_);
7 mut(x);
8 return x;
9 }
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.expect.md
+2 -4
@@ -5,10 +5,9 @@
5 function foo(props) {
6 let x = [];
7 x.push(props.bar);
8 - const _ = props.cond
8 + props.cond
9 ? ((x = {}), (x = []), x.push(props.foo))
10 : ((x = []), (x = []), x.push(props.bar));
11 - console.log(_);
11 return x;
12 }
13
@@ -43,8 +42,7 @@ function foo(props) {
42 t0 = $[3];
43 x = $[4];
44 }
46 - const _ = t0;
47 - console.log(_);
45 + t0;
46 return x;
47 }
48
compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.js
+1 -2
@@ -1,9 +1,8 @@
1 function foo(props) {
2 let x = [];
3 x.push(props.bar);
4 - const _ = props.cond
4 + props.cond
5 ? ((x = {}), (x = []), x.push(props.foo))
6 : ((x = []), (x = []), x.push(props.bar));
7 - console.log(_);
7 return x;
8 }