if (j < 0) return value;
return iife.args[j] || make_node(AST_Undefined, iife);
};
- d.fixed.reduce_arg = function() {
- var j = fn.argnames.indexOf(arg);
- if (j < 0 || j >= iife.args.length) return;
- iife.args[j] = make_node(AST_Number, iife.args[j], { value: 0 });
- };
tw.loop_ids[d.id] = tw.in_loop;
mark(tw, d, true);
} else {
value_def.replaced++;
return List.skip;
}
- return get_rvalue(candidate);
+ return rvalue;
case 1:
if (!assign_used && node.body === candidate) {
hit = true;
if (is_lhs(node, multi_replacer.parent())) return node;
def.replaced++;
value_def.replaced--;
- return get_rvalue(candidate).clone();
+ return rvalue.clone();
}
// Skip (non-executed) functions and (leading) default case in switch statements
if (node instanceof AST_Default || node instanceof AST_Scope) return node;
// Locate symbols which may execute code outside of scanning range
var lvalues = get_lvalues(candidate);
var lhs_local = is_lhs_local(lhs);
- if (!side_effects) side_effects = value_has_side_effects(candidate);
+ var rvalue = get_rvalue(candidate);
+ if (!side_effects) side_effects = value_has_side_effects();
var replace_all = replace_all_symbols(candidate);
var may_throw = candidate.may_throw(compressor) ? in_try ? function(node) {
return node.has_side_effects(compressor);
}
function should_stop(node, parent) {
+ if (node === rvalue) return true;
if (parent instanceof AST_For) return node !== parent.init;
if (node instanceof AST_Assign) {
return node.operator != "=" && lhs.equivalent_to(node.left);
if (node instanceof AST_Call) {
if (!(lhs instanceof AST_PropAccess)) return false;
if (!lhs.equivalent_to(node.expression)) return false;
- var rhs = get_rvalue(candidate);
- return !(rhs instanceof AST_Function && !rhs.contains_this());
+ return !(rvalue instanceof AST_Function && !rvalue.contains_this());
}
if (node instanceof AST_Debugger) return true;
if (node instanceof AST_Defun) return funarg && lhs.name === node.name.name;
|| candidate instanceof AST_Assign && candidate.operator != "="));
}
- function value_has_side_effects(expr) {
- if (expr instanceof AST_Unary) return false;
- return get_rvalue(expr).has_side_effects(compressor);
+ function value_has_side_effects() {
+ if (candidate instanceof AST_Unary) return false;
+ return rvalue.has_side_effects(compressor);
}
function replace_all_symbols(expr) {
}));
} else {
value = fixed.optimize(compressor);
- if (def.fixed.reduce_arg) def.fixed.reduce_arg();
+ if (value === fixed) value = value.transform(new TreeTransformer(function(node, descend) {
+ if (node instanceof AST_Scope) return node;
+ node = node.clone();
+ descend(node, this);
+ return node;
+ }));
}
def.replaced++;
return value;