From 5ae04b35452693e886a7f836e62e3290b08016a1 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 16 Mar 2017 13:22:26 +0800 Subject: make `collapse_vars` consistent with `toplevel` (#1608) fixes #1605 --- test/compress/collapse_vars.js | 47 +++++++++++++++++++++++++++++++++++++++++- test/compress/issue-973.js | 1 + test/mocha/cli.js | 2 +- test/mocha/minify.js | 1 + 4 files changed, 49 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 6d7e2d9f..558a9ee0 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -1152,7 +1152,8 @@ collapse_vars_arguments: { options = { collapse_vars:true, sequences:true, properties:true, dead_code:true, conditionals:true, comparisons:true, evaluate:true, booleans:true, loops:true, unused:true, hoist_funs:true, - keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true + keep_fargs:true, if_return:true, join_vars:true, cascade:true, side_effects:true, + toplevel:true } input: { var outer = function() { @@ -1335,6 +1336,7 @@ issue_1537: { issue_1562: { options = { collapse_vars: true, + toplevel: true, } input: { var v = 1, B = 2; @@ -1363,3 +1365,46 @@ issue_1562: { for (; f(z + 2) ;) bar(30); } } + +issue_1605_1: { + options = { + collapse_vars: true, + toplevel: false, + } + input: { + function foo(x) { + var y = x; + return y; + } + var o = new Object; + o.p = 1; + } + expect: { + function foo(x) { + return x; + } + var o = new Object; + o.p = 1; + } +} + +issue_1605_2: { + options = { + collapse_vars: true, + toplevel: "vars", + } + input: { + function foo(x) { + var y = x; + return y; + } + var o = new Object; + o.p = 1; + } + expect: { + function foo(x) { + return x; + } + (new Object).p = 1; + } +} diff --git a/test/compress/issue-973.js b/test/compress/issue-973.js index 0e040922..30f886a8 100644 --- a/test/compress/issue-973.js +++ b/test/compress/issue-973.js @@ -50,6 +50,7 @@ this_binding_conditionals: { this_binding_collapse_vars: { options = { collapse_vars: true, + toplevel: true, }; input: { var c = a; c(); diff --git a/test/mocha/cli.js b/test/mocha/cli.js index fa952d91..2b44c901 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -152,7 +152,7 @@ describe("bin/uglifyjs", function () { }); }); it("Should process inline source map", function(done) { - var command = uglifyjscmd + ' test/input/issue-520/input.js -cm toplevel --in-source-map inline --source-map-inline'; + var command = uglifyjscmd + ' test/input/issue-520/input.js -mc toplevel --in-source-map inline --source-map-inline'; exec(command, function (err, stdout) { if (err) throw err; diff --git a/test/mocha/minify.js b/test/mocha/minify.js index 51c46b28..a4587cb7 100644 --- a/test/mocha/minify.js +++ b/test/mocha/minify.js @@ -78,6 +78,7 @@ describe("minify", function() { }); it("Should process inline source map", function() { var code = Uglify.minify("./test/input/issue-520/input.js", { + compress: { toplevel: true }, inSourceMap: "inline", sourceMapInline: true }).code + "\n"; -- cgit v1.2.3