handle duplicate argument names in collapse_vars (#2215)

This commit is contained in:
Alex Lam S.L
2017-07-08 04:42:35 +08:00
committed by GitHub
parent 4f70d2e28c
commit 71ee91e716
2 changed files with 29 additions and 3 deletions

View File

@@ -820,7 +820,11 @@ merge(Compressor.prototype, {
&& !fn.uses_eval
&& (iife = compressor.parent()) instanceof AST_Call
&& iife.expression === fn) {
fn.argnames.forEach(function(sym, i) {
var names = Object.create(null);
for (var i = fn.argnames.length; --i >= 0;) {
var sym = fn.argnames[i];
if (sym.name in names) continue;
names[sym.name] = true;
var arg = iife.args[i];
if (!arg) arg = make_node(AST_Undefined, sym);
else {
@@ -840,11 +844,11 @@ merge(Compressor.prototype, {
});
arg.walk(tw);
}
if (arg) candidates.push(make_node(AST_VarDef, sym, {
if (arg) candidates.unshift(make_node(AST_VarDef, sym, {
name: sym,
value: arg
}));
});
}
}
}