var in_lambda = last_of(compressor, function(node) {
return node instanceof AST_Lambda;
});
- var in_loop, in_try, scope;
+ var block_scope, in_loop, in_try, scope;
find_loop_scope_try();
var changed, last_changed, max_iter = 10;
do {
function find_loop_scope_try() {
var node = compressor.self(), level = 0;
do {
+ if (!block_scope && node.variables) block_scope = node;
if (node instanceof AST_Catch) {
if (compressor.parent(level).bfinally) {
if (!in_try) in_try = {};
var inlined = make_node(AST_UnaryPrefix, stat, {
operator: "void",
expression: body,
- }).try_inline(compressor, scope);
+ }).try_inline(compressor, block_scope);
if (!inlined) return false;
statements[index] = inlined;
return true;
(function(def) {
def(AST_Node, noop);
- function process(sym, argname) {
- argname.definition().orig.push(sym);
- }
def(AST_Call, function(compressor, scope) {
if (compressor.option("inline") < 4) return;
var call = this;
if (fn.name) return;
if (fn.uses_arguments) return;
if (fn.contains_this()) return;
- if (!scope) scope = compressor.find_parent(AST_Scope);
+ if (!scope) scope = find_scope(compressor);
+ var defined = new Dictionary();
+ while (!(scope instanceof AST_Scope)) {
+ scope.variables.each(function(def) {
+ defined.set(def.name, true);
+ });
+ scope = scope.parent_scope;
+ }
var names = scope.var_names();
if (!fn.variables.all(function(def, name) {
- if (!names.has(name)) return true;
+ if (!defined.has(name) && !names.has(name)) return true;
if (name != "arguments") return false;
if (scope.uses_arguments) return false;
return def.references.length == def.replaced;
right: make_node(AST_Number, node, { value: 0 }),
});
}));
- var body = [];
+ var body = [], defs = Object.create(null), syms = new Dictionary();
if (fn.rest || !all(fn.argnames, function(argname) {
return argname instanceof AST_SymbolFunarg;
}) || !all(call.args, function(arg) {
body: make_sequence(call, values),
}));
}
+ syms.each(function(orig, id) {
+ [].unshift.apply(defs[id].orig, orig);
+ });
return make_node(AST_BlockStatement, call, {
body: body.concat(fn.body, make_node(AST_Return, call, { value: null })),
});
+
+ function process(sym, argname) {
+ var def = argname.definition();
+ defs[def.id] = def;
+ syms.add(def.id, sym);
+ }
});
def(AST_New, noop);
def(AST_Sequence, function(compressor, scope) {