Merge branch 'master' into harmony-v3.3.4

This commit is contained in:
alexlamsl
2017-12-31 00:05:32 +08:00
4 changed files with 32 additions and 8 deletions

View File

@@ -5148,7 +5148,7 @@ merge(Compressor.prototype, {
return self; return self;
}); });
function is_reachable(node, defs) { function is_reachable(self, defs) {
var reachable = false; var reachable = false;
var find_ref = new TreeWalker(function(node) { var find_ref = new TreeWalker(function(node) {
if (reachable) return true; if (reachable) return true;
@@ -5158,7 +5158,7 @@ merge(Compressor.prototype, {
}); });
var scan_scope = new TreeWalker(function(node) { var scan_scope = new TreeWalker(function(node) {
if (reachable) return true; if (reachable) return true;
if (node instanceof AST_Scope) { if (node instanceof AST_Scope && node !== self) {
var parent = scan_scope.parent(); var parent = scan_scope.parent();
if (!(parent instanceof AST_Call && parent.expression === node)) { if (!(parent instanceof AST_Call && parent.expression === node)) {
node.walk(find_ref); node.walk(find_ref);
@@ -5166,7 +5166,7 @@ merge(Compressor.prototype, {
return true; return true;
} }
}); });
node.walk(scan_scope); self.walk(scan_scope);
return reachable; return reachable;
} }
@@ -5183,7 +5183,7 @@ merge(Compressor.prototype, {
parent = compressor.parent(level++); parent = compressor.parent(level++);
if (parent instanceof AST_Exit) { if (parent instanceof AST_Exit) {
if (in_try(level, parent instanceof AST_Throw)) break; if (in_try(level, parent instanceof AST_Throw)) break;
if (is_reachable(self, [ def ])) break; if (is_reachable(def.scope, [ def ])) break;
if (self.operator == "=") return self.right; if (self.operator == "=") return self.right;
return make_node(AST_Binary, self, { return make_node(AST_Binary, self, {
operator: self.operator.slice(0, -1), operator: self.operator.slice(0, -1),

View File

@@ -699,9 +699,7 @@ function OutputStream(options) {
} }
}; };
PARENS(AST_Node, function(){ PARENS(AST_Node, return_false);
return false;
});
// a function expression needs parens around it when it's provably // a function expression needs parens around it when it's provably
// the first token to appear in a statement. // the first token to appear in a statement.

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.3.3", "version": "3.3.4",
"engines": { "engines": {
"node": ">=0.8.0" "node": ">=0.8.0"
}, },

View File

@@ -1074,3 +1074,29 @@ issue_2666: {
} }
expect_stdout: "object" expect_stdout: "object"
} }
issue_2692: {
options = {
dead_code: true,
reduce_vars: false,
}
input: {
function f(a) {
return a = g;
function g() {
return a;
}
}
console.log(typeof f()());
}
expect: {
function f(a) {
return a = g;
function g() {
return a;
}
}
console.log(typeof f()());
}
expect_stdout: "function"
}