var ASSIGN_OPS = [ '+', '-', '/', '*', '%', '>>', '<<', '>>>', '|', '^', '&' ];
var ASSIGN_OPS_COMMUTATIVE = [ '*', '|', '^', '&' ];
OPT(AST_Assign, function(self, compressor){
+ var def;
if (compressor.option("dead_code")
&& self.left instanceof AST_SymbolRef
- && self.left.definition().scope === compressor.find_parent(AST_Lambda)) {
+ && (def = 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 (in_try(level, parent instanceof AST_Throw)) break;
+ if (is_reachable(def)) break;
if (self.operator == "=") return self.right;
return make_node(AST_Binary, self, {
operator: self.operator.slice(0, -1),
}
}
}
+
+ function is_reachable(def) {
+ var reachable = false;
+ var find_ref = new TreeWalker(function(node) {
+ if (reachable) return true;
+ if (node instanceof AST_SymbolRef && node.definition() === def) {
+ return reachable = true;
+ }
+ });
+ self.right.walk(new TreeWalker(function(node) {
+ if (reachable) return true;
+ if (node instanceof AST_Scope) {
+ node.walk(find_ref);
+ return true;
+ }
+ }));
+ return reachable;
+ }
});
OPT(AST_Conditional, function(self, compressor){