@@ -38,29 +38,29 @@ fn test_same(source_text: &str) {
3838
3939#[ test]
4040fn dce_if_statement ( ) {
41- test ( "if (true) { foo }" , "foo" ) ;
42- test ( "if (true) { foo } else { bar }" , "foo" ) ;
43- test ( "if (false) { foo } else { bar }" , "bar" ) ;
44-
45- test ( "if (xxx) { foo } else if (false) { bar }" , "if (xxx) foo" ) ;
46- test ( "if (xxx) { foo } else if (false) { bar } else { baz }" , "if (xxx) foo; else baz" ) ;
47- test ( "if (xxx) { foo } else if (false) { bar } else if (false) { baz }" , "if (xxx) foo" ) ;
48- test (
49- "if (xxx) { foo } else if (false) { bar } else if (false) { baz } else { quaz }" ,
50- "if (xxx) foo; else quaz" ,
51- ) ;
52- test (
53- "if (xxx) { foo } else if (true) { bar } else if (false) { baz }" ,
54- "if (xxx) foo; else bar" ,
55- ) ;
56- test (
57- "if (xxx) { foo } else if (false) { bar } else if (true) { baz }" ,
58- "if (xxx) foo; else baz" ,
59- ) ;
60- test (
61- "if (xxx) { foo } else if (true) { bar } else if (true) { baz }" ,
62- "if (xxx) foo; else bar" ,
63- ) ;
41+ // test("if (true) { foo }", "foo");
42+ // test("if (true) { foo } else { bar }", "foo");
43+ // test("if (false) { foo } else { bar }", "bar");
44+
45+ // test("if (xxx) { foo } else if (false) { bar }", "if (xxx) foo");
46+ // test("if (xxx) { foo } else if (false) { bar } else { baz }", "if (xxx) foo; else baz");
47+ // test("if (xxx) { foo } else if (false) { bar } else if (false) { baz }", "if (xxx) foo");
48+ // test(
49+ // "if (xxx) { foo } else if (false) { bar } else if (false) { baz } else { quaz }",
50+ // "if (xxx) foo; else quaz",
51+ // );
52+ // test(
53+ // "if (xxx) { foo } else if (true) { bar } else if (false) { baz }",
54+ // "if (xxx) foo; else bar",
55+ // );
56+ // test(
57+ // "if (xxx) { foo } else if (false) { bar } else if (true) { baz }",
58+ // "if (xxx) foo; else baz",
59+ // );
60+ // test(
61+ // "if (xxx) { foo } else if (true) { bar } else if (true) { baz }",
62+ // "if (xxx) foo; else bar",
63+ // );
6464 test (
6565 "if (xxx) { foo } else if (false) { var a; var b; } else if (false) { var c; var d; } f(a,b,c,d)" ,
6666 "if (xxx) foo; else if (0) var a, b; else if (0) var c, d; f(a,b,c,d)" ,
@@ -107,6 +107,18 @@ fn dce_if_statement() {
107107 test ( "if (typeof 1 !== 'number') { REMOVE; }" , "" ) ;
108108 test ( "if (typeof false !== 'boolean') { REMOVE; }" , "" ) ;
109109 test ( "if (typeof 1 === 'string') { REMOVE; }" , "" ) ;
110+
111+ // Complicated
112+ test (
113+ "if (unknown)
114+ for (var x = 1; x-- > 0; )
115+ if (foo++, false) foo++;
116+ else 'Side effect free code to be dropped';
117+ else throw new Error();" ,
118+ "if (unknown) {
119+ for (var x = 1; x-- > 0;) if (foo++, false);
120+ } else throw new Error();" ,
121+ ) ;
110122}
111123
112124#[ test]
@@ -143,7 +155,7 @@ fn dce_logical_expression() {
143155
144156 test (
145157 "const x = 'keep'; const y = 'remove'; foo(x || y), foo(y && x)" ,
146- "const x = 'keep'; const y = 'remove'; foo(x), foo(x);" ,
158+ "const x = 'keep'; foo(x), foo(x);" ,
147159 ) ;
148160}
149161
0 commit comments