@@ -638,15 +638,30 @@ Compressor.prototype.compress = function(node) {
|
||||
}
|
||||
|
||||
function push(tw, sequential) {
|
||||
var defined_ids = Object.create(tw.defined_ids);
|
||||
var safe_ids = Object.create(tw.safe_ids);
|
||||
if (!sequential) safe_ids.seq = {};
|
||||
if (!sequential) {
|
||||
defined_ids.seq = {};
|
||||
safe_ids.seq = {};
|
||||
}
|
||||
tw.defined_ids = defined_ids;
|
||||
tw.safe_ids = safe_ids;
|
||||
}
|
||||
|
||||
function pop(tw) {
|
||||
tw.defined_ids = Object.getPrototypeOf(tw.defined_ids);
|
||||
tw.safe_ids = Object.getPrototypeOf(tw.safe_ids);
|
||||
}
|
||||
|
||||
function access(tw, def) {
|
||||
tw.defined_ids[def.id] = [ tw.defined_ids.seq ];
|
||||
}
|
||||
|
||||
function assign(tw, def) {
|
||||
var defined = tw.defined_ids[def.id];
|
||||
if (defined) defined[0] = false;
|
||||
}
|
||||
|
||||
function mark(tw, def) {
|
||||
tw.safe_ids[def.id] = {};
|
||||
}
|
||||
@@ -939,9 +954,13 @@ Compressor.prototype.compress = function(node) {
|
||||
return fixed_node;
|
||||
}, visit);
|
||||
walk_lambda(fn, tw);
|
||||
var defined_ids = tw.defined_ids;
|
||||
var safe_ids = tw.safe_ids;
|
||||
pop_scope(tw, fn);
|
||||
if (!aborts) tw.safe_ids = safe_ids;
|
||||
if (!aborts) {
|
||||
tw.defined_ids = defined_ids;
|
||||
tw.safe_ids = safe_ids;
|
||||
}
|
||||
return true;
|
||||
|
||||
function visit(node, fixed) {
|
||||
@@ -966,10 +985,10 @@ Compressor.prototype.compress = function(node) {
|
||||
var scan = ld || left instanceof AST_Destructured;
|
||||
switch (node.operator) {
|
||||
case "=":
|
||||
if (ld) assign(tw, ld);
|
||||
if (left.equals(right) && !left.has_side_effects(compressor)) {
|
||||
right.walk(tw);
|
||||
walk_prop(left);
|
||||
node.redundant = true;
|
||||
return true;
|
||||
}
|
||||
if (ld && right instanceof AST_LambdaExpression) {
|
||||
@@ -990,6 +1009,7 @@ Compressor.prototype.compress = function(node) {
|
||||
case "||=":
|
||||
case "??=":
|
||||
var lazy = true;
|
||||
if (ld) assign(tw, ld);
|
||||
default:
|
||||
if (!scan) {
|
||||
mark_assignment_to_arguments(left);
|
||||
@@ -1103,7 +1123,7 @@ Compressor.prototype.compress = function(node) {
|
||||
def(AST_BlockScope, function(tw, descend, compressor) {
|
||||
reset_block_variables(tw, compressor, this);
|
||||
});
|
||||
def(AST_Call, function(tw, descend) {
|
||||
def(AST_Call, function(tw) {
|
||||
var node = this;
|
||||
var exp = node.expression;
|
||||
if (exp instanceof AST_LambdaExpression) {
|
||||
@@ -1134,6 +1154,7 @@ Compressor.prototype.compress = function(node) {
|
||||
if (fixed instanceof AST_Lambda) {
|
||||
mark_fn_def(tw, exp.definition(), fixed);
|
||||
} else {
|
||||
tw.defined_ids.seq = {};
|
||||
tw.find_parent(AST_Scope).may_call_this();
|
||||
}
|
||||
return true;
|
||||
@@ -1238,6 +1259,12 @@ Compressor.prototype.compress = function(node) {
|
||||
tw.in_loop = save_loop;
|
||||
return true;
|
||||
});
|
||||
def(AST_Dot, function(tw, descend) {
|
||||
descend();
|
||||
var expr = this.expression;
|
||||
if (expr instanceof AST_SymbolRef) access(tw, expr.definition());
|
||||
return true;
|
||||
});
|
||||
def(AST_For, function(tw, descend, compressor) {
|
||||
var node = this;
|
||||
reset_block_variables(tw, compressor, node);
|
||||
@@ -1336,10 +1363,13 @@ Compressor.prototype.compress = function(node) {
|
||||
return true;
|
||||
});
|
||||
def(AST_Sub, function(tw) {
|
||||
if (!this.optional) return;
|
||||
this.expression.walk(tw);
|
||||
var node = this;
|
||||
if (!node.optional) return;
|
||||
var expr = node.expression;
|
||||
expr.walk(tw);
|
||||
if (expr instanceof AST_SymbolRef) access(tw, expr.definition());
|
||||
push(tw, true);
|
||||
this.property.walk(tw);
|
||||
node.property.walk(tw);
|
||||
pop(tw);
|
||||
return true;
|
||||
});
|
||||
@@ -1390,6 +1420,8 @@ Compressor.prototype.compress = function(node) {
|
||||
var d = ref.definition();
|
||||
var fixed = d.fixed || d.last_ref && d.last_ref.fixed;
|
||||
push_ref(d, ref);
|
||||
var defined = tw.defined_ids[d.id];
|
||||
if (defined && defined[0] === tw.defined_ids.seq) ref.defined = true;
|
||||
if (d.references.length == 1 && !d.fixed && d.orig[0] instanceof AST_SymbolDefun) {
|
||||
tw.loop_ids[d.id] = tw.in_loop;
|
||||
}
|
||||
@@ -1618,6 +1650,9 @@ Compressor.prototype.compress = function(node) {
|
||||
reset_flags(node);
|
||||
return node.reduce_vars(tw, descend, compressor);
|
||||
} : reset_flags);
|
||||
// Side-effect tracking on sequential property access
|
||||
tw.defined_ids = Object.create(null);
|
||||
tw.defined_ids.seq = {};
|
||||
// Flow control for visiting lambda definitions
|
||||
tw.fn_scanning = null;
|
||||
tw.fn_visited = [];
|
||||
@@ -4712,6 +4747,7 @@ Compressor.prototype.compress = function(node) {
|
||||
return this.tail_node()._dot_throw(compressor);
|
||||
});
|
||||
def(AST_SymbolRef, function(compressor, force) {
|
||||
if (this.defined) return false;
|
||||
if (this.is_undefined) return true;
|
||||
if (!is_strict(compressor, force)) return false;
|
||||
if (is_undeclared_ref(this) && this.is_declared(compressor)) return false;
|
||||
@@ -12955,16 +12991,14 @@ Compressor.prototype.compress = function(node) {
|
||||
if (compressor.option("dead_code")) {
|
||||
if (self.left instanceof AST_PropAccess) {
|
||||
if (self.operator == "=") {
|
||||
if (self.redundant) {
|
||||
var exprs = [ self.left.expression ];
|
||||
if (self.left instanceof AST_Sub) exprs.push(self.left.property);
|
||||
exprs.push(self.right);
|
||||
return make_sequence(self, exprs).optimize(compressor);
|
||||
}
|
||||
if (self.left.equals(self.right) && !self.left.has_side_effects(compressor)) {
|
||||
return self.right;
|
||||
}
|
||||
var exp = self.left.expression;
|
||||
if (self.left.equals(self.right)) {
|
||||
var defined = exp.defined;
|
||||
exp.defined = false;
|
||||
var drop_lhs = !self.left.has_side_effects(compressor);
|
||||
exp.defined = defined;
|
||||
if (drop_lhs) return self.right;
|
||||
}
|
||||
if (exp instanceof AST_Lambda
|
||||
|| !compressor.has_directive("use strict")
|
||||
&& exp instanceof AST_Constant
|
||||
|
||||
Reference in New Issue
Block a user