diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/collapse_vars.js | 56 | ||||
-rw-r--r-- | test/compress/const.js | 166 | ||||
-rw-r--r-- | test/compress/dead-code.js | 125 | ||||
-rw-r--r-- | test/compress/drop-unused.js | 64 | ||||
-rw-r--r-- | test/compress/evaluate.js | 9 | ||||
-rw-r--r-- | test/compress/global_defs.js | 4 | ||||
-rw-r--r-- | test/compress/issue-1041.js | 13 | ||||
-rw-r--r-- | test/compress/issue-1588.js | 12 | ||||
-rw-r--r-- | test/compress/issue-208.js | 6 | ||||
-rw-r--r-- | test/compress/loops.js | 44 | ||||
-rw-r--r-- | test/compress/reduce_vars.js | 8 | ||||
-rw-r--r-- | test/compress/sequences.js | 24 | ||||
-rw-r--r-- | test/input/invalid/const.js | 8 | ||||
-rw-r--r-- | test/mocha/cli.js | 15 |
14 files changed, 19 insertions, 535 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 0d578d7d..90d7ac93 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -583,8 +583,8 @@ collapse_vars_assignment: { return a = a; } function f1(c) { - const a = 3 / c; - const b = 1 - a; + var a = 3 / c; + var b = 1 - a; return b; } function f2(c) { @@ -724,10 +724,10 @@ collapse_vars_misc1: { return t; } function f1(x) { var y = 5 - x; return y; } - function f2(x) { const z = foo(), y = z / (5 - x); return y; } + function f2(x) { var z = foo(), y = z / (5 - x); return y; } function f3(x) { var z = foo(), y = (5 - x) / z; return y; } function f4(x) { var z = foo(), y = (5 - u) / z; return y; } - function f5(x) { const z = foo(), y = (5 - window.x) / z; return y; } + function f5(x) { var z = foo(), y = (5 - window.x) / z; return y; } function f6() { var b = window.a * window.z; return b && zap(); } function f7() { var b = window.a * window.z; return b + b; } function f8() { var b = window.a * window.z; var c = b + 5; return b + c; } @@ -744,7 +744,7 @@ collapse_vars_misc1: { function f2(x) { return foo() / (5 - x) } function f3(x) { return (5 - x) / foo() } function f4(x) { var z = foo(); return (5 - u) / z } - function f5(x) { const z = foo(); return (5 - window.x) / z } + function f5(x) { var z = foo(); return (5 - window.x) / z } function f6() { return window.a * window.z && zap() } function f7() { var b = window.a * window.z; return b + b } function f8() { var b = window.a * window.z; return b + (b + 5) } @@ -2186,49 +2186,3 @@ compound_assignment: { } expect_stdout: "4" } - -reassign_const_1: { - options = { - collapse_vars: true, - } - input: { - function f() { - const a = 1; - a = 2; - return a; - } - console.log(f()); - } - expect: { - function f() { - const a = 1; - a = 2; - return a; - } - console.log(f()); - } - expect_stdout: true -} - -reassign_const_2: { - options = { - collapse_vars: true, - } - input: { - function f() { - const a = 1; - ++a; - return a; - } - console.log(f()); - } - expect: { - function f() { - const a = 1; - ++a; - return a; - } - console.log(f()); - } - expect_stdout: true -} diff --git a/test/compress/const.js b/test/compress/const.js deleted file mode 100644 index a88d5946..00000000 --- a/test/compress/const.js +++ /dev/null @@ -1,166 +0,0 @@ -issue_1191: { - options = { - evaluate : true, - booleans : true, - comparisons : true, - dead_code : true, - conditionals : true, - side_effects : true, - unused : true, - hoist_funs : true, - if_return : true, - join_vars : true, - sequences : false, - collapse_vars : false, - reduce_vars : true, - } - input: { - function foo(rot) { - const rotTol = 5; - if (rot < -rotTol || rot > rotTol) - bar(); - baz(); - } - } - expect: { - function foo(rot) { - (rot < -5 || rot > 5) && bar(); - baz(); - } - } -} - -issue_1194: { - options = { - evaluate : true, - booleans : true, - comparisons : true, - dead_code : true, - conditionals : true, - side_effects : true, - unused : true, - hoist_funs : true, - if_return : true, - join_vars : true, - sequences : false, - collapse_vars : false, - reduce_vars : true, - } - input: { - function f1() {const a = "X"; return a + a;} - function f2() {const aa = "X"; return aa + aa;} - function f3() {const aaa = "X"; return aaa + aaa;} - } - expect: { - function f1(){return"XX"} - function f2(){return"XX"} - function f3(){return"XX"} - } -} - -issue_1396: { - options = { - evaluate : true, - booleans : true, - comparisons : true, - dead_code : true, - conditionals : true, - side_effects : true, - unused : true, - hoist_funs : true, - if_return : true, - join_vars : true, - sequences : false, - collapse_vars : false, - reduce_vars : true, - } - input: { - function foo(a) { - const VALUE = 1; - console.log(2 | VALUE); - console.log(VALUE + 1); - console.log(VALUE); - console.log(a & VALUE); - } - function bar() { - const s = "01234567890123456789"; - console.log(s + s + s + s + s); - - const CONSTANT = "abc"; - console.log(CONSTANT + CONSTANT + CONSTANT + CONSTANT + CONSTANT); - } - } - expect: { - function foo(a) { - console.log(3); - console.log(2); - console.log(1); - console.log(1 & a); - } - function bar() { - const s = "01234567890123456789"; - console.log(s + s + s + s + s); - - console.log("abcabcabcabcabc"); - } - } -} - -unused_regexp_literal: { - options = { - evaluate : true, - booleans : true, - comparisons : true, - dead_code : true, - conditionals : true, - side_effects : true, - unused : true, - hoist_funs : true, - if_return : true, - join_vars : true, - sequences : false, - collapse_vars : false, - } - input: { - function f(){ var a = /b/; } - } - expect: { - function f(){} - } -} - -regexp_literal_not_const: { - options = { - evaluate : true, - booleans : true, - comparisons : true, - dead_code : true, - conditionals : true, - side_effects : true, - unused : true, - hoist_funs : true, - if_return : true, - join_vars : true, - sequences : false, - collapse_vars : false, - reduce_vars : true, - } - input: { - (function(){ - var result; - const s = 'acdabcdeabbb'; - const REGEXP_LITERAL = /ab*/g; - while (result = REGEXP_LITERAL.exec(s)) { - console.log(result[0]); - } - })(); - } - expect: { - (function() { - var result; - const REGEXP_LITERAL = /ab*/g; - while (result = REGEXP_LITERAL.exec("acdabcdeabbb")) console.log(result[0]); - })(); - } - expect_stdout: true -} diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js index bb72451c..31d0664a 100644 --- a/test/compress/dead-code.js +++ b/test/compress/dead-code.js @@ -90,131 +90,6 @@ dead_code_constant_boolean_should_warn_more: { expect_stdout: true } -dead_code_const_declaration: { - options = { - dead_code : true, - loops : true, - booleans : true, - conditionals : true, - evaluate : true, - reduce_vars : true, - }; - input: { - var unused; - const CONST_FOO = false; - if (CONST_FOO) { - console.log("unreachable"); - var moo; - function bar() {} - } - } - expect: { - var unused; - const CONST_FOO = !1; - var moo; - function bar() {} - } - expect_stdout: true -} - -dead_code_const_annotation: { - options = { - dead_code : true, - loops : true, - booleans : true, - conditionals : true, - evaluate : true, - reduce_vars : true, - toplevel : true, - }; - input: { - var unused; - /** @const */ var CONST_FOO_ANN = false; - if (CONST_FOO_ANN) { - console.log("unreachable"); - var moo; - function bar() {} - } - } - expect: { - var unused; - var CONST_FOO_ANN = !1; - var moo; - function bar() {} - } - expect_stdout: true -} - -dead_code_const_annotation_regex: { - options = { - dead_code : true, - loops : true, - booleans : true, - conditionals : true, - evaluate : true - }; - input: { - var unused; - // @constraint this shouldn't be a constant - var CONST_FOO_ANN = false; - if (CONST_FOO_ANN) { - console.log("reachable"); - } - } - expect: { - var unused; - var CONST_FOO_ANN = !1; - CONST_FOO_ANN && console.log('reachable'); - } - expect_stdout: true -} - -dead_code_const_annotation_complex_scope: { - options = { - dead_code : true, - loops : true, - booleans : true, - conditionals : true, - evaluate : true, - reduce_vars : true, - toplevel : true, - }; - input: { - var unused_var; - /** @const */ var test = 'test'; - // @const - var CONST_FOO_ANN = false; - var unused_var_2; - if (CONST_FOO_ANN) { - console.log("unreachable"); - var moo; - function bar() {} - } - if (test === 'test') { - var beef = 'good'; - /** @const */ var meat = 'beef'; - var pork = 'bad'; - if (meat === 'pork') { - console.log('also unreachable'); - } else if (pork === 'good') { - console.log('reached, not const'); - } - } - } - expect: { - var unused_var; - var test = 'test'; - var CONST_FOO_ANN = !1; - var unused_var_2; - var moo; - function bar() {} - var beef = 'good'; - var meat = 'beef'; - var pork = 'bad'; - } - expect_stdout: true -} - try_catch_finally: { options = { conditionals: true, diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index 96bd336c..2ef6f796 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -649,37 +649,6 @@ drop_value: { } } -const_assign: { - options = { - evaluate: true, - reduce_vars: true, - unused: true, - } - input: { - function f() { - const b = 2; - return 1 + b; - } - - function g() { - const b = 2; - b = 3; - return 1 + b; - } - } - expect: { - function f() { - return 3; - } - - function g() { - const b = 2; - b = 3; - return 1 + b; - } - } -} - issue_1539: { options = { cascade: true, @@ -816,10 +785,6 @@ issue_1709: { var x = 1; return x; }(), - function y() { - const y = 2; - return y; - }(), function z() { function z() {} return z; @@ -833,10 +798,6 @@ issue_1709: { return x; }(), function() { - const y = 2; - return y; - }(), - function() { function z() {} return z; }() @@ -1147,28 +1108,3 @@ var_catch_toplevel: { }(); } } - -reassign_const: { - options = { - cascade: true, - sequences: true, - side_effects: true, - unused: true, - } - input: { - function f() { - const a = 1; - a = 2; - return a; - } - console.log(f()); - } - expect: { - function f() { - const a = 1; - return a = 2, a; - } - console.log(f()); - } - expect_stdout: true -} diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 585ee2b9..b8077564 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -645,16 +645,17 @@ call_args: { options = { evaluate: true, reduce_vars: true, + toplevel: true, } input: { - const a = 1; + var a = 1; console.log(a); +function(a) { return a; }(a); } expect: { - const a = 1; + var a = 1; console.log(1); +(1, 1); } @@ -666,17 +667,17 @@ call_args_drop_param: { evaluate: true, keep_fargs: false, reduce_vars: true, + toplevel: true, unused: true, } input: { - const a = 1; + var a = 1; console.log(a); +function(a) { return a; }(a, b); } expect: { - const a = 1; console.log(1); +(b, 1); } diff --git a/test/compress/global_defs.js b/test/compress/global_defs.js index f1ba8f32..bfd1d5f6 100644 --- a/test/compress/global_defs.js +++ b/test/compress/global_defs.js @@ -120,7 +120,7 @@ mixed: { properties: true, } input: { - const FOO = { BAR: 0 }; + var FOO = { BAR: 0 }; console.log(FOO.BAR); console.log(++CONFIG.DEBUG); console.log(++CONFIG.VALUE); @@ -130,7 +130,7 @@ mixed: { console.log(CONFIG); } expect: { - const FOO = { BAR: 0 }; + var FOO = { BAR: 0 }; console.log("moo"); console.log(++CONFIG.DEBUG); console.log(++CONFIG.VALUE); diff --git a/test/compress/issue-1041.js b/test/compress/issue-1041.js index cdbc22cc..cc351405 100644 --- a/test/compress/issue-1041.js +++ b/test/compress/issue-1041.js @@ -1,16 +1,3 @@ -const_declaration: { - options = { - evaluate: true - }; - - input: { - const goog = goog || {}; - } - expect: { - const goog = goog || {}; - } -} - const_pragma: { options = { evaluate: true, diff --git a/test/compress/issue-1588.js b/test/compress/issue-1588.js index 4e20a21d..187d9f6c 100644 --- a/test/compress/issue-1588.js +++ b/test/compress/issue-1588.js @@ -85,15 +85,3 @@ unsafe_undefined: { } expect_stdout: true } - -runtime_error: { - input: { - const a = 1; - console.log(a++); - } - expect: { - const a = 1; - console.log(a++); - } - expect_stdout: true -} diff --git a/test/compress/issue-208.js b/test/compress/issue-208.js index fb9861f6..faaf4139 100644 --- a/test/compress/issue-208.js +++ b/test/compress/issue-208.js @@ -38,7 +38,7 @@ mixed: { } } input: { - const ENV = 3; + var ENV = 3; var FOO = 4; f(ENV * 10); --FOO; @@ -49,7 +49,7 @@ mixed: { x = DEBUG; } expect: { - const ENV = 3; + var ENV = 3; var FOO = 4; f(10); --FOO; @@ -60,7 +60,7 @@ mixed: { x = 0; } expect_warnings: [ - 'WARN: global_defs ENV redefined [test/compress/issue-208.js:41,14]', + 'WARN: global_defs ENV redefined [test/compress/issue-208.js:41,12]', 'WARN: global_defs FOO redefined [test/compress/issue-208.js:42,12]', 'WARN: global_defs FOO redefined [test/compress/issue-208.js:44,10]', 'WARN: global_defs DEBUG redefined [test/compress/issue-208.js:45,8]', diff --git a/test/compress/loops.js b/test/compress/loops.js index 4d354bcf..89c7e7e9 100644 --- a/test/compress/loops.js +++ b/test/compress/loops.js @@ -146,50 +146,6 @@ parse_do_while_without_semicolon: { } } - -keep_collapse_const_in_own_block_scope: { - options = { - join_vars: true, - loops: true - } - input: { - var i=2; - const c=5; - while(i--) - console.log(i); - console.log(c); - } - expect: { - var i=2; - const c=5; - for(;i--;) - console.log(i); - console.log(c); - } - expect_stdout: true -} - -keep_collapse_const_in_own_block_scope_2: { - options = { - join_vars: true, - loops: true - } - input: { - const c=5; - var i=2; // Moves to loop, while it did not in previous test - while(i--) - console.log(i); - console.log(c); - } - expect: { - const c=5; - for(var i=2;i--;) - console.log(i); - console.log(c); - } - expect_stdout: true -} - evaluate: { options = { loops: true, diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index d3b3d425..a0433b5d 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -2190,10 +2190,11 @@ issue_1814_1: { options = { evaluate: true, reduce_vars: true, + toplevel: true, unused: true, } input: { - const a = 42; + var a = 42; !function() { var b = a; !function(a) { @@ -2202,7 +2203,6 @@ issue_1814_1: { }(); } expect: { - const a = 42; !function() { !function(a) { console.log(a++, 42); @@ -2216,10 +2216,11 @@ issue_1814_2: { options = { evaluate: true, reduce_vars: true, + toplevel: true, unused: true, } input: { - const a = "32"; + var a = "32"; !function() { var b = a + 1; !function(a) { @@ -2228,7 +2229,6 @@ issue_1814_2: { }(); } expect: { - const a = "32"; !function() { !function(a) { console.log(a++, "321"); diff --git a/test/compress/sequences.js b/test/compress/sequences.js index 9edf627e..10492565 100644 --- a/test/compress/sequences.js +++ b/test/compress/sequences.js @@ -710,27 +710,3 @@ issue_27: { })(jQuery); } } - -reassign_const: { - options = { - cascade: true, - sequences: true, - side_effects: true, - } - input: { - function f() { - const a = 1; - a++; - return a; - } - console.log(f()); - } - expect: { - function f() { - const a = 1; - return a++, a; - } - console.log(f()); - } - expect_stdout: true -} diff --git a/test/input/invalid/const.js b/test/input/invalid/const.js deleted file mode 100644 index 7a2bfd3d..00000000 --- a/test/input/invalid/const.js +++ /dev/null @@ -1,8 +0,0 @@ -function f() { - const a; -} - -function g() { - "use strict"; - const a; -} diff --git a/test/mocha/cli.js b/test/mocha/cli.js index 8cf53ab4..38f61f39 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -379,21 +379,6 @@ describe("bin/uglifyjs", function () { done(); }); }); - it("Should throw syntax error (const a)", function(done) { - var command = uglifyjscmd + ' test/input/invalid/const.js'; - - exec(command, function (err, stdout, stderr) { - assert.ok(err); - assert.strictEqual(stdout, ""); - assert.strictEqual(stderr.split(/\n/).slice(0, 4).join("\n"), [ - "Parse error at test/input/invalid/const.js:7,11", - " const a;", - " ^", - "ERROR: Missing initializer in const declaration" - ].join("\n")); - done(); - }); - }); it("Should throw syntax error (delete x)", function(done) { var command = uglifyjscmd + ' test/input/invalid/delete.js'; |