diff options
author | kzc <zaxxon2011@gmail.com> | 2016-05-22 11:35:41 -0400 |
---|---|---|
committer | Richard van Velzen <rvanvelzen@experty.com> | 2016-05-24 17:54:08 +0200 |
commit | 1e390269d47e2a555f511556590d826938d572f9 (patch) | |
tree | 91c10054828f2bd6e2b0674f4765481fde8a54e5 /test | |
parent | bc49dfd27a800cfa2070464c236a1d56ed30bfca (diff) | |
download | tracifyjs-1e390269d47e2a555f511556590d826938d572f9.tar.gz tracifyjs-1e390269d47e2a555f511556590d826938d572f9.zip |
Optimize if_return for single if/return cases.
Fixes #1089
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/if_return.js | 207 |
1 files changed, 207 insertions, 0 deletions
diff --git a/test/compress/if_return.js b/test/compress/if_return.js new file mode 100644 index 00000000..78a6e818 --- /dev/null +++ b/test/compress/if_return.js @@ -0,0 +1,207 @@ +if_return_1: { + options = { + if_return : true, + sequences : true, + conditionals : true, + comparisons : true, + evaluate : true, + booleans : true, + unused : true, + side_effects : true, + dead_code : true, + } + input: { + function f(x) { + if (x) { + return true; + } + } + } + expect: { + function f(x){if(x)return!0} + } +} + +if_return_2: { + options = { + if_return : true, + sequences : true, + conditionals : true, + comparisons : true, + evaluate : true, + booleans : true, + unused : true, + side_effects : true, + dead_code : true, + } + input: { + function f(x, y) { + if (x) + return 3; + if (y) + return c(); + } + } + expect: { + function f(x,y){return x?3:y?c():void 0} + } +} + +if_return_3: { + options = { + if_return : true, + sequences : true, + conditionals : true, + comparisons : true, + evaluate : true, + booleans : true, + unused : true, + side_effects : true, + dead_code : true, + } + input: { + function f(x) { + a(); + if (x) { + b(); + return false; + } + } + } + expect: { + function f(x){if(a(),x)return b(),!1} + } +} + +if_return_4: { + options = { + if_return : true, + sequences : true, + conditionals : true, + comparisons : true, + evaluate : true, + booleans : true, + unused : true, + side_effects : true, + dead_code : true, + } + input: { + function f(x, y) { + a(); + if (x) return 3; + b(); + if (y) return c(); + } + } + expect: { + function f(x,y){return a(),x?3:(b(),y?c():void 0)} + } +} + +if_return_5: { + options = { + if_return : true, + sequences : true, + conditionals : true, + comparisons : true, + evaluate : true, + booleans : true, + unused : true, + side_effects : true, + dead_code : true, + } + input: { + function f() { + if (x) + return; + return 7; + if (y) + return j; + } + } + expect: { + function f(){if(!x)return 7} + } +} + +if_return_6: { + options = { + if_return : true, + sequences : true, + conditionals : true, + comparisons : true, + evaluate : true, + booleans : true, + unused : true, + side_effects : true, + dead_code : true, + } + input: { + function f(x) { + return x ? true : void 0; + return y; + } + } + expect: { + // suboptimal + function f(x){return!!x||void 0} + } +} + +if_return_7: { + options = { + if_return : true, + sequences : true, + conditionals : true, + comparisons : true, + evaluate : true, + booleans : true, + unused : true, + side_effects : true, + dead_code : true, + } + input: { + function f(x) { + if (x) { + return true; + } + foo(); + bar(); + } + } + expect: { + // suboptimal + function f(x){return!!x||(foo(),void bar())} + } +} + +issue_1089: { + options = { + if_return : true, + sequences : true, + conditionals : true, + comparisons : true, + evaluate : true, + booleans : true, + unused : true, + side_effects : true, + dead_code : true, + } + input: { + function x() { + var f = document.getElementById("fname"); + if (f.files[0].size > 12345) { + alert("alert"); + f.focus(); + return false; + } + } + } + expect: { + function x() { + var f = document.getElementById("fname"); + if (f.files[0].size > 12345) + return alert("alert"), f.focus(), !1; + } + } +} |