drop local assign-only variable in return (#2587)

This commit is contained in:
Alex Lam S.L
2017-12-14 02:59:59 +08:00
committed by GitHub
parent ef618332ea
commit 9a137e8613
3 changed files with 113 additions and 5 deletions

View File

@@ -4666,6 +4666,24 @@ merge(Compressor.prototype, {
var ASSIGN_OPS = [ '+', '-', '/', '*', '%', '>>', '<<', '>>>', '|', '^', '&' ];
var ASSIGN_OPS_COMMUTATIVE = [ '*', '|', '^', '&' ];
OPT(AST_Assign, function(self, compressor){
if (compressor.option("dead_code")
&& self.left instanceof AST_SymbolRef
&& self.left.definition().scope === compressor.find_parent(AST_Lambda)) {
var level = 0, node, parent = self;
do {
node = parent;
parent = compressor.parent(level++);
if (parent instanceof AST_Exit) {
if (self.operator == "=") return self.right;
return make_node(AST_Binary, self, {
operator: self.operator.slice(0, -1),
left: self.left,
right: self.right
}).optimize(compressor);
}
} while (parent instanceof AST_Binary && parent.right === node
|| parent instanceof AST_Sequence && parent.tail_node() === node);
}
self = self.lift_sequences(compressor);
if (self.operator == "=" && self.left instanceof AST_SymbolRef && self.right instanceof AST_Binary) {
// x = expr1 OP expr2