diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-03-16 06:12:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-16 06:12:59 +0800 |
commit | 20ca0f5906c68df11d2f44e8b381212672afc6e1 (patch) | |
tree | 2a2fd0feb19255c26d3cd8167776804d10beb04c /test/compress | |
parent | b29d435bb5bc4d883a23efaabd76e95092352b6c (diff) | |
download | tracifyjs-20ca0f5906c68df11d2f44e8b381212672afc6e1.tar.gz tracifyjs-20ca0f5906c68df11d2f44e8b381212672afc6e1.zip |
improve truthy compression (#3009)
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/conditionals.js | 7 | ||||
-rw-r--r-- | test/compress/evaluate.js | 42 | ||||
-rw-r--r-- | test/compress/issue-1261.js | 2 | ||||
-rw-r--r-- | test/compress/negate-iife.js | 4 | ||||
-rw-r--r-- | test/compress/reduce_vars.js | 27 | ||||
-rw-r--r-- | test/compress/transform.js | 2 |
6 files changed, 66 insertions, 18 deletions
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js index abb39697..03386d18 100644 --- a/test/compress/conditionals.js +++ b/test/compress/conditionals.js @@ -703,10 +703,11 @@ ternary_boolean_alternative: { trivial_boolean_ternary_expressions : { options = { + booleans: true, conditionals: true, - evaluate : true, - booleans : true - }; + evaluate: true, + side_effects: true, + } input: { f('foo' in m ? true : false); f('foo' in m ? false : true); diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 0547e6d9..9d35ffa3 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -745,7 +745,7 @@ in_boolean_context: { !b("foo"), !b([1, 2]), !b(/foo/), - ![1, foo()], + (foo(), !1), (foo(), !1) ); } @@ -1566,3 +1566,43 @@ issue_2968: { } expect_stdout: "PASS" } + +truthy_conditionals: { + options = { + conditionals: true, + evaluate: true, + } + input: { + if (a = {}) x(); + (b = /foo/) && y(); + (c = function() {}) || z(); + } + expect: { + a = {}, x(); + b = /foo/, y(); + c = function() {}; + } +} + +truthy_loops: { + options = { + evaluate: true, + loops: true, + } + input: { + while ([]) x(); + do { + y(); + } while(a = {}); + } + expect: { + for (;;) { + []; + x(); + } + for (;;) { + y(); + a = {}; + } + } +} diff --git a/test/compress/issue-1261.js b/test/compress/issue-1261.js index 9f4f466f..888fde40 100644 --- a/test/compress/issue-1261.js +++ b/test/compress/issue-1261.js @@ -175,8 +175,8 @@ should_warn: { "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:141,31]", "WARN: Condition always true [test/compress/issue-1261.js:141,8]", "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:142,23]", - "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:143,24]", "WARN: Condition always true [test/compress/issue-1261.js:143,8]", + "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:143,24]", "WARN: Dropping __PURE__ call [test/compress/issue-1261.js:144,31]", "WARN: Condition always false [test/compress/issue-1261.js:144,8]", ] diff --git a/test/compress/negate-iife.js b/test/compress/negate-iife.js index 66d24270..17148cad 100644 --- a/test/compress/negate-iife.js +++ b/test/compress/negate-iife.js @@ -67,7 +67,7 @@ negate_iife_3_evaluate: { (function(){ return true })() ? console.log(true) : console.log(false); } expect: { - console.log(true); + true, console.log(true); } expect_stdout: true } @@ -110,7 +110,7 @@ negate_iife_3_off_evaluate: { (function(){ return true })() ? console.log(true) : console.log(false); } expect: { - console.log(true); + true, console.log(true); } expect_stdout: true } diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 815dff32..3d11ba42 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -55,7 +55,7 @@ reduce_vars: { console.log(a - 5); eval("console.log(a);"); })(eval); - "yes"; + true, "yes"; console.log(A + 1); } expect_stdout: true @@ -147,7 +147,7 @@ modified: { } function f4() { var b = 2, c = 3; - b = c; + 1, b = c; console.log(1 + b); console.log(b + c); console.log(1 + c); @@ -715,10 +715,12 @@ passes: { passes: 2, reduce_funcs: true, reduce_vars: true, + sequences: true, + side_effects: true, unused: true, } input: { - function f() { + (function() { var a = 1, b = 2, c = 3; if (a) { b = c; @@ -729,17 +731,22 @@ passes: { console.log(b + c); console.log(a + c); console.log(a + b + c); - } + })(); } expect: { - function f() { - 3; - console.log(4); - console.log(6); - console.log(4); + (function() { + console.log(4), + console.log(6), + console.log(4), console.log(7); - } + })(); } + expect_stdout: [ + "4", + "6", + "4", + "7", + ] } iife: { diff --git a/test/compress/transform.js b/test/compress/transform.js index 58874cd6..867b8ade 100644 --- a/test/compress/transform.js +++ b/test/compress/transform.js @@ -59,7 +59,7 @@ if_else_empty: { if ({} ? a : b); else {} } expect: { - !{} ? b : a; + ({}), a; } } |