diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-09-07 15:18:32 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-09-07 15:18:32 +0300 |
commit | 919b2733ab52d3072bb4276210fe442bc0ade5fd (patch) | |
tree | 662eff0fbadc5c2b31fdda06e764f0f10c94eb6e /test/compress/conditionals.js | |
parent | b77574ea1c25e2630dcde000ae0fa32b01f8311e (diff) | |
download | tracifyjs-919b2733ab52d3072bb4276210fe442bc0ade5fd.tar.gz tracifyjs-919b2733ab52d3072bb4276210fe442bc0ade5fd.zip |
always keep declarations found in unreachable code
a few more tests and some cleanups.
Diffstat (limited to 'test/compress/conditionals.js')
-rw-r--r-- | test/compress/conditionals.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js new file mode 100644 index 00000000..ba5e674d --- /dev/null +++ b/test/compress/conditionals.js @@ -0,0 +1,74 @@ +ifs_1: { + options = { + conditionals: true + }; + input: { + if (foo) bar(); + if (!foo); else bar(); + if (foo); else bar(); + if (foo); else; + } + expect: { + foo&&bar(); + foo&&bar(); + foo||bar(); + foo; + } +} + +ifs_2: { + options = { + conditionals: true + }; + input: { + if (foo) { + x(); + } else if (bar) { + y(); + } else if (baz) { + z(); + } + + if (foo) { + x(); + } else if (bar) { + y(); + } else if (baz) { + z(); + } else { + t(); + } + } + expect: { + foo ? x() : bar ? y() : baz && z(); + foo ? x() : bar ? y() : baz ? z() : t(); + } +} + +ifs_3_should_warn: { + options = { + conditionals : true, + dead_code : true, + evaluate : true, + booleans : true + }; + input: { + if (x && !(x + "1") && y) { // 1 + var qq; + foo(); + } else { + bar(); + } + + if (x || !!(x + "1") || y) { // 2 + foo(); + } else { + var jj; + bar(); + } + } + expect: { + var qq; bar(); // 1 + var jj; foo(); // 2 + } +} |