Merge branch 'master' into harmony-v3.0.17

This commit is contained in:
alexlamsl
2017-06-15 19:01:36 +08:00
7 changed files with 90 additions and 8 deletions

View File

@@ -3383,10 +3383,15 @@ merge(Compressor.prototype, {
if (!value) return make_node(AST_Undefined, self); if (!value) return make_node(AST_Undefined, self);
value.walk(new TreeWalker(function(node) { value.walk(new TreeWalker(function(node) {
if (value === self) return true; 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; value = self;
return true; return true;
} }
function matches(ref) {
return ref && ref.scope.parent_scope === fn.parent_scope;
}
})); }));
if (value !== self) value = best_of(compressor, value, self); if (value !== self) value = best_of(compressor, value, self);
} else { } else {

View File

@@ -246,11 +246,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
} }
} }
var sym = node.scope.find_variable(name); var sym = node.scope.find_variable(name);
if (node.scope instanceof AST_Lambda && name == "arguments") {
node.scope.uses_arguments = true;
}
if (!sym) { if (!sym) {
sym = self.def_global(node); sym = self.def_global(node);
} else if (sym.scope instanceof AST_Lambda && name == "arguments") {
sym.scope.uses_arguments = true;
} }
node.thedef = sym; node.thedef = sym;
node.reference(options); node.reference(options);

View File

@@ -4,7 +4,7 @@
"homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony", "homepage": "https://github.com/mishoo/UglifyJS2/tree/harmony",
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)", "author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"version": "3.0.16", "version": "3.0.17",
"engines": { "engines": {
"node": ">=0.8.0" "node": ">=0.8.0"
}, },

View File

@@ -336,3 +336,81 @@ issue_2084: {
} }
expect_stdout: "0" 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"
}

View File

@@ -9,7 +9,7 @@ function read(path) {
describe("bin/uglifyjs", function () { describe("bin/uglifyjs", function () {
var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs'; var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';
it("should produce a functional build when using --self", function (done) { it("should produce a functional build when using --self", function (done) {
this.timeout(15000); this.timeout(30000);
var command = uglifyjscmd + ' --self -cm --wrap WrappedUglifyJS'; var command = uglifyjscmd + ' --self -cm --wrap WrappedUglifyJS';

View File

@@ -14,7 +14,7 @@ function run(command, args, done) {
} }
describe("test/benchmark.js", function() { describe("test/benchmark.js", function() {
this.timeout(5 * 60 * 1000); this.timeout(10 * 60 * 1000);
[ [
"-b", "-b",
"-b bracketize", "-b bracketize",

View File

@@ -4,7 +4,7 @@ var uglify = require("../node");
describe("spidermonkey export/import sanity test", function() { describe("spidermonkey export/import sanity test", function() {
it("should produce a functional build when using --self with spidermonkey", function(done) { 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 uglifyjs = '"' + process.argv[0] + '" bin/uglifyjs';
var command = uglifyjs + " --self -cm --wrap SpiderUglify -o spidermonkey | " + var command = uglifyjs + " --self -cm --wrap SpiderUglify -o spidermonkey | " +