diff options
author | kzc <kzc@users.noreply.github.com> | 2017-03-02 02:11:40 -0500 |
---|---|---|
committer | Alex Lam S.L <alexlamsl@gmail.com> | 2017-03-02 15:11:40 +0800 |
commit | ee3b39b909c279a0115c7562cab2c9b37fb37c21 (patch) | |
tree | eec94f77b7187dd161d077f3b4478143cf67577f /test/compress/functions.js | |
parent | 9699ffb1afc8bead9fbc3643c6b90b14169ef02c (diff) | |
download | tracifyjs-ee3b39b909c279a0115c7562cab2c9b37fb37c21.tar.gz tracifyjs-ee3b39b909c279a0115c7562cab2c9b37fb37c21.zip |
optimize trivial IIFEs returning constants (#1530)
Diffstat (limited to 'test/compress/functions.js')
-rw-r--r-- | test/compress/functions.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/compress/functions.js b/test/compress/functions.js index 3a8701b7..d3d99b57 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -6,3 +6,71 @@ non_ascii_function_identifier_name: { } expect_exact: "function fooλ(δλ){}function λ(δλ){}(function λ(δλ){})();" } + +iifes_returning_constants_keep_fargs_true: { + options = { + keep_fargs : true, + side_effects : true, + evaluate : true, + unused : true, + dead_code : true, + conditionals : true, + comparisons : true, + booleans : true, + if_return : true, + join_vars : true, + reduce_vars : true, + cascade : true, + } + input: { + (function(){ return -1.23; }()); + console.log( function foo(){ return "okay"; }() ); + console.log( function foo(x, y, z){ return 123; }() ); + console.log( function(x, y, z){ return z; }() ); + console.log( function(x, y, z){ if (x) return y; return z; }(1, 2, 3) ); + console.log( function(x, y){ return x * y; }(2, 3) ); + console.log( function(x, y){ return x * y; }(2, 3, a(), b()) ); + } + expect: { + console.log("okay"); + console.log(123); + console.log(void 0); + console.log(function(x,y,z){return 2}(1,2,3)); + console.log(function(x,y){return 6}(2,3)); + console.log(function(x, y){return 6}(2,3,a(),b())); + } +} + +iifes_returning_constants_keep_fargs_false: { + options = { + keep_fargs : false, + side_effects : true, + evaluate : true, + unused : true, + dead_code : true, + conditionals : true, + comparisons : true, + booleans : true, + if_return : true, + join_vars : true, + reduce_vars : true, + cascade : true, + } + input: { + (function(){ return -1.23; }()); + console.log( function foo(){ return "okay"; }() ); + console.log( function foo(x, y, z){ return 123; }() ); + console.log( function(x, y, z){ return z; }() ); + console.log( function(x, y, z){ if (x) return y; return z; }(1, 2, 3) ); + console.log( function(x, y){ return x * y; }(2, 3) ); + console.log( function(x, y){ return x * y; }(2, 3, a(), b()) ); + } + expect: { + console.log("okay"); + console.log(123); + console.log(void 0); + console.log(2); + console.log(6); + console.log(function(){return 6}(a(),b())); + } +} |