From 0a1e523cd5de9b96946b05bd70b3f125a4bfb4cc Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 15 Jun 2017 01:00:03 +0800 Subject: [PATCH 1/5] fix parsing of `expect_stdout` (#2096) fixes #2095 --- test/run-tests.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/test/run-tests.js b/test/run-tests.js index 188532ea..71ffe72a 100755 --- a/test/run-tests.js +++ b/test/run-tests.js @@ -294,24 +294,22 @@ function parse_test(file) { if (label.name == "expect_exact" || label.name == "node_version") { test[label.name] = read_string(stat); } else if (label.name == "expect_stdout") { - if (stat.TYPE == "SimpleStatement") { - var body = stat.body; - if (body instanceof U.AST_Boolean) { - test[label.name] = body.value; - } else if (body instanceof U.AST_Call) { - var ctor = global[body.expression.name]; - assert.ok(ctor === Error || ctor.prototype instanceof Error, tmpl("Unsupported expect_stdout format [{line},{col}]", { + var body = stat.body; + if (body instanceof U.AST_Boolean) { + test[label.name] = body.value; + } else if (body instanceof U.AST_Call) { + var ctor = global[body.expression.name]; + assert.ok(ctor === Error || ctor.prototype instanceof Error, tmpl("Unsupported expect_stdout format [{line},{col}]", { + line: label.start.line, + col: label.start.col + })); + test[label.name] = ctor.apply(null, body.args.map(function(node) { + assert.ok(node instanceof U.AST_Constant, tmpl("Unsupported expect_stdout format [{line},{col}]", { line: label.start.line, col: label.start.col })); - test[label.name] = ctor.apply(null, body.args.map(function(node) { - assert.ok(node instanceof U.AST_Constant, tmpl("Unsupported expect_stdout format [{line},{col}]", { - line: label.start.line, - col: label.start.col - })); - return node.value; - })); - } + return node.value; + })); } else { test[label.name] = read_string(stat) + "\n"; } From 3f961bbba04a8cec0ab74f4a13deb4be217da877 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 15 Jun 2017 03:28:26 +0800 Subject: [PATCH 2/5] compute `uses_arguments` correctly in `figure_out_scope()` (#2099) fixes #2097 --- lib/scope.js | 5 ++--- test/compress/functions.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/scope.js b/lib/scope.js index ea43f752..82a935a2 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -197,11 +197,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ } } var sym = node.scope.find_variable(name); - if (node.scope instanceof AST_Lambda && name == "arguments") { - node.scope.uses_arguments = true; - } if (!sym) { sym = self.def_global(node); + } else if (sym.scope instanceof AST_Lambda && name == "arguments") { + sym.scope.uses_arguments = true; } node.thedef = sym; node.reference(options); diff --git a/test/compress/functions.js b/test/compress/functions.js index 1359670e..909a57dd 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -336,3 +336,32 @@ issue_2084: { } expect_stdout: "0" } + +issue_2097: { + options = { + negate_iife: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + function f() { + try { + throw 0; + } catch (e) { + console.log(arguments[0]); + } + } + f(1); + } + expect: { + !function() { + try { + throw 0; + } catch (e) { + console.log(arguments[0]); + } + }(1); + } + expect_stdout: "1" +} From 43697958f368b41aee3cd704473ad6c1ea53ae8c Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 15 Jun 2017 04:47:57 +0800 Subject: [PATCH 3/5] avoid intermittent test time-out failures (#2100) --- test/mocha/cli.js | 2 +- test/mocha/release.js | 2 +- test/mocha/spidermonkey.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/mocha/cli.js b/test/mocha/cli.js index fa6f1464..b54044eb 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -9,7 +9,7 @@ function read(path) { describe("bin/uglifyjs", function () { var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs'; it("should produce a functional build when using --self", function (done) { - this.timeout(15000); + this.timeout(30000); var command = uglifyjscmd + ' --self -cm --wrap WrappedUglifyJS'; diff --git a/test/mocha/release.js b/test/mocha/release.js index 1bf6e87b..063d0fc7 100644 --- a/test/mocha/release.js +++ b/test/mocha/release.js @@ -14,7 +14,7 @@ function run(command, args, done) { } describe("test/benchmark.js", function() { - this.timeout(5 * 60 * 1000); + this.timeout(10 * 60 * 1000); [ "-b", "-b bracketize", diff --git a/test/mocha/spidermonkey.js b/test/mocha/spidermonkey.js index 9bddb537..ccd11c43 100644 --- a/test/mocha/spidermonkey.js +++ b/test/mocha/spidermonkey.js @@ -4,7 +4,7 @@ var uglify = require("../node"); describe("spidermonkey export/import sanity test", function() { it("should produce a functional build when using --self with spidermonkey", function(done) { - this.timeout(30000); + this.timeout(60000); var uglifyjs = '"' + process.argv[0] + '" bin/uglifyjs'; var command = uglifyjs + " --self -cm --wrap SpiderUglify -o spidermonkey | " + From b85a358deb70615596bf5ffc668e2ac282453f88 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 15 Jun 2017 12:14:16 +0800 Subject: [PATCH 4/5] suppress `inline` of `this` (#2103) fixes #2101 --- lib/compress.js | 7 +++++- test/compress/functions.js | 49 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 4d768781..f5989341 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3209,10 +3209,15 @@ merge(Compressor.prototype, { if (!value) return make_node(AST_Undefined, self); value.walk(new TreeWalker(function(node) { if (value === self) return true; - if (node instanceof AST_SymbolRef && exp.variables.has(node.name)) { + if (node instanceof AST_SymbolRef && matches(node.scope.find_variable(node)) + || node instanceof AST_This && matches(node)) { value = self; return true; } + + function matches(ref) { + return ref && ref.scope.parent_scope === fn.parent_scope; + } })); if (value !== self) value = best_of(compressor, value, self); } else { diff --git a/test/compress/functions.js b/test/compress/functions.js index 909a57dd..c2794f26 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -365,3 +365,52 @@ issue_2097: { } expect_stdout: "1" } + +issue_2101: { + options = { + inline: true, + } + input: { + a = {}; + console.log(function() { + return function() { + return this.a; + }(); + }() === function() { + return a; + }()); + } + expect: { + a = {}; + console.log(function() { + return this.a; + }() === a); + } + expect_stdout: "true" +} + +inner_ref: { + options = { + inline: true, + unused: true, + } + input: { + console.log(function(a) { + return function() { + return a; + }(); + }(1), function(a) { + return function(a) { + return a; + }(); + }(2)); + } + expect: { + console.log(function(a) { + return a; + }(1), function(a) { + return a; + }()); + } + expect_stdout: "1 undefined" +} From 57dc4fb32f04b167581f247d5a3d59986c0c2724 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 15 Jun 2017 18:59:37 +0800 Subject: [PATCH 5/5] v3.0.17 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fde98e7a..f78fcca7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "homepage": "http://lisperator.net/uglifyjs", "author": "Mihai Bazon (http://lisperator.net/)", "license": "BSD-2-Clause", - "version": "3.0.16", + "version": "3.0.17", "engines": { "node": ">=0.8.0" },