diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/collapse_vars.js | 40 | ||||
-rw-r--r-- | test/compress/drop-unused.js | 12 | ||||
-rw-r--r-- | test/compress/evaluate.js | 14 | ||||
-rw-r--r-- | test/compress/reduce_vars.js | 193 |
4 files changed, 233 insertions, 26 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 631f5b29..7d66f7c6 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -1268,22 +1268,21 @@ collapse_vars_short_circuited_conditions: { collapse_vars_regexp: { options = { + booleans: true, + cascade: true, collapse_vars: true, - loops: false, - sequences: true, - dead_code: true, - conditionals: true, comparisons: true, + conditionals: true, + dead_code: true, evaluate: true, - booleans: true, - unused: true, - hoist_funs: true, - keep_fargs: true, if_return: true, join_vars: true, - cascade: true, - side_effects: true, + hoist_funs: true, + keep_fargs: true, + loops: false, reduce_vars: true, + side_effects: true, + unused: true, } input: { function f1() { @@ -1292,12 +1291,12 @@ collapse_vars_regexp: { return [rx, k]; } function f2() { - var rx = /[abc123]+/; + var rx = /ab*/g; return function(s) { return rx.exec(s); }; } - (function(){ + (function() { var result; var s = 'acdabcdeabbb'; var rx = /ab*/g; @@ -1305,22 +1304,35 @@ collapse_vars_regexp: { console.log(result[0]); } })(); + (function() { + var result; + var s = 'acdabcdeabbb'; + var rx = f2(); + while (result = rx(s)) { + console.log(result[0]); + } + })(); } expect: { function f1() { return [/[A-Z]+/, 9]; } function f2() { - var rx = /[abc123]+/; + var rx = /ab*/g; return function(s) { return rx.exec(s); }; } - (function(){ + (function() { var result, rx = /ab*/g; while (result = rx.exec("acdabcdeabbb")) console.log(result[0]); })(); + (function() { + var result, rx = f2(); + while (result = rx("acdabcdeabbb")) + console.log(result[0]); + })(); } expect_stdout: true } diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index c9048540..4ce8d2eb 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -751,12 +751,12 @@ issue_1583: { expect: { function m(t) { (function(e) { - t = e(); - })(function() { - return (function(a) { - return a; - })(function(a) {}); - }); + t = function() { + return (function(a) { + return function(a) {}; + })(); + }(); + })(); } } } diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 1c737060..5f5a4a93 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -1021,6 +1021,7 @@ issue_1964_1: { input: { function f() { var long_variable_name = /\s/; + console.log(long_variable_name.source); return "a b c".split(long_variable_name)[1]; } console.log(f()); @@ -1028,11 +1029,15 @@ issue_1964_1: { expect: { function f() { var long_variable_name = /\s/; + console.log(long_variable_name.source); return "a b c".split(long_variable_name)[1]; } console.log(f()); } - expect_stdout: "b" + expect_stdout: [ + "\\s", + "b", + ] } issue_1964_2: { @@ -1045,17 +1050,22 @@ issue_1964_2: { input: { function f() { var long_variable_name = /\s/; + console.log(long_variable_name.source); return "a b c".split(long_variable_name)[1]; } console.log(f()); } expect: { function f() { + console.log(/\s/.source); return "a b c".split(/\s/)[1]; } console.log(f()); } - expect_stdout: "b" + expect_stdout: [ + "\\s", + "b", + ] } array_slice_index: { diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 4e096d9d..c1da2991 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -172,6 +172,7 @@ unsafe_evaluate: { options = { evaluate : true, reduce_vars : true, + side_effects : true, unsafe : true, unused : true } @@ -1898,10 +1899,7 @@ redefine_farg_3: { console.log(f([]), g([]), h([])); } expect: { - console.log(function(a) { - var a; - return typeof a; - }([]), "number", "undefined"); + console.log(typeof [], "number", "undefined"); } expect_stdout: "object number undefined" } @@ -2629,3 +2627,190 @@ for_in_prop: { } expect_stdout: "1" } + +obj_var_1: { + options = { + evaluate: true, + passes: 2, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var C = 1; + var obj = { + bar: function() { + return C + C; + } + }; + console.log(obj.bar()); + } + expect: { + console.log({ + bar: function() { + return 2; + } + }.bar()); + } + expect_stdout: "2" +} + +obj_var_2: { + options = { + evaluate: true, + inline: true, + passes: 2, + reduce_vars: true, + side_effects: true, + toplevel: true, + unsafe: true, + unused: true, + } + input: { + var C = 1; + var obj = { + bar: function() { + return C + C; + } + }; + console.log(obj.bar()); + } + expect: { + console.log(2); + } + expect_stdout: "2" +} + +obj_arg_1: { + options = { + evaluate: true, + inline: true, + passes: 2, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var C = 1; + function f(obj) { + return obj.bar(); + } + console.log(f({ + bar: function() { + return C + C; + } + })); + } + expect: { + console.log({ + bar: function() { + return 2; + } + }.bar()); + } + expect_stdout: "2" +} + +obj_arg_2: { + options = { + evaluate: true, + inline: true, + passes: 2, + reduce_vars: true, + side_effects: true, + toplevel: true, + unsafe: true, + unused: true, + } + input: { + var C = 1; + function f(obj) { + return obj.bar(); + } + console.log(f({ + bar: function() { + return C + C; + } + })); + } + expect: { + console.log(2); + } + expect_stdout: "2" +} + +func_arg_1: { + options = { + evaluate: true, + inline: true, + passes: 2, + reduce_vars: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + var a = 42; + !function(a) { + console.log(a()); + }(function() { + return a; + }); + } + expect: { + console.log(42); + } + expect_stdout: "42" +} + +func_arg_2: { + options = { + evaluate: true, + inline: true, + passes: 2, + reduce_vars: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + var a = 42; + !function(a) { + console.log(a()); + }(function(a) { + return a; + }); + } + expect: { + console.log(void 0); + } + expect_stdout: "undefined" +} + +regex_loop: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + function f(x) { + for (var r, s = "acdabcdeabbb"; r = x().exec(s);) + console.log(r[0]); + } + var a = /ab*/g; + f(function() { + return a; + }); + } + expect: { + var a = /ab*/g; + (function(x) { + for (var r, s = "acdabcdeabbb"; r = x().exec(s);) + console.log(r[0]); + })(function() { + return a; + }); + } + expect_stdout: true +} |