aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js58
1 files changed, 36 insertions, 22 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 3551655a..f63c1869 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -9046,6 +9046,7 @@ merge(Compressor.prototype, {
if (!all(stat.enclosed, function(def) {
return def.scope === stat || !defined[def.name];
})) return false;
+ if (in_loop) in_loop.push(stat.name.definition());
continue;
}
if (!(stat instanceof AST_Var)) continue;
@@ -9189,32 +9190,56 @@ merge(Compressor.prototype, {
}
}
+ function flatten_var(name) {
+ var redef = name.definition().redefined();
+ if (redef) {
+ name = name.clone();
+ name.thedef = redef;
+ }
+ return name;
+ }
+
function flatten_vars(decls, expressions) {
- var pos = expressions.length;
+ var args = [ insert, 0 ];
+ var decl_var = [], expr_var = [], expr_loop = [];
for (var i = 0; i < fn.body.length; i++) {
var stat = fn.body[i];
+ if (stat instanceof AST_LambdaDefinition) {
+ if (in_loop) {
+ var name = make_node(AST_SymbolVar, stat.name, flatten_var(stat.name));
+ name.definition().orig.push(name);
+ append_var(decls, expressions, name, to_func_expr(stat, true));
+ } else {
+ var def = stat.name.definition();
+ scope.functions.set(def.name, def);
+ scope.variables.set(def.name, def);
+ scope.enclosed.push(def);
+ scope.var_names()[def.name] = true;
+ args.push(stat);
+ }
+ continue;
+ }
if (!(stat instanceof AST_Var)) continue;
for (var j = 0; j < stat.definitions.length; j++) {
var var_def = stat.definitions[j];
- var name = var_def.name;
- var redef = name.definition().redefined();
- if (redef) {
- name = name.clone();
- name.thedef = redef;
- }
- append_var(decls, expressions, name, var_def.value);
+ var name = flatten_var(var_def.name);
+ append_var(decl_var, expr_var, name, var_def.value);
if (in_loop && !HOP(arg_used, name.name)) {
var def = fn.variables.get(name.name);
var sym = make_node(AST_SymbolRef, name, name);
def.references.push(sym);
- expressions.splice(pos++, 0, make_node(AST_Assign, var_def, {
+ expr_loop.push(make_node(AST_Assign, var_def, {
operator: "=",
left: sym,
- right: make_node(AST_Undefined, name)
+ right: make_node(AST_Undefined, name),
}));
}
}
}
+ [].push.apply(decls, decl_var);
+ [].push.apply(expressions, expr_loop);
+ [].push.apply(expressions, expr_var);
+ return args;
}
function flatten_fn() {
@@ -9225,19 +9250,8 @@ merge(Compressor.prototype, {
} else {
flatten_args(decls, expressions);
}
- flatten_vars(decls, expressions);
+ var args = flatten_vars(decls, expressions);
expressions.push(value);
- var args = fn.body.filter(function(stat) {
- if (stat instanceof AST_LambdaDefinition) {
- var def = stat.name.definition();
- scope.functions.set(def.name, def);
- scope.variables.set(def.name, def);
- scope.enclosed.push(def);
- scope.var_names()[def.name] = true;
- return true;
- }
- });
- args.unshift(insert, 0);
if (decls.length) args.push(make_node(AST_Var, fn, {
definitions: decls
}));