diff --git a/lib/compress.js b/lib/compress.js index ab8b5f3a..fe8be762 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3383,10 +3383,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/lib/scope.js b/lib/scope.js index 345a3a09..68dc2b5a 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -246,11 +246,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/package.json b/package.json index 863399c4..a6a54d10 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony", "author": "Mihai Bazon (http://lisperator.net/)", "license": "BSD-2-Clause", - "version": "3.0.16", + "version": "3.0.17", "engines": { "node": ">=0.8.0" }, diff --git a/test/compress/functions.js b/test/compress/functions.js index 045ce5fe..ae8dfb07 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -336,3 +336,81 @@ 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" +} + +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" +} diff --git a/test/mocha/cli.js b/test/mocha/cli.js index aed30925..5ae0e5a0 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 | " +