@@ -281,6 +281,9 @@ merge(Compressor.prototype, {
281281 if (node instanceof AST_Function
282282 && (iife = tw.parent()) instanceof AST_Call
283283 && iife.expression === node) {
284+ // Virtually turn IIFE parameters into variable definitions:
285+ // (function(a,b) {...})(c,d) => (function() {var a=c,b=d; ...})()
286+ // So existing transformation rules can work on them.
284287 node.argnames.forEach(function(arg, i) {
285288 var d = arg.definition();
286289 d.fixed = iife.args[i] || make_node(AST_Undefined, iife);
@@ -1810,10 +1813,12 @@ merge(Compressor.prototype, {
18101813 node.name = null;
18111814 }
18121815 if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
1813- if (!compressor.option("keep_fargs")) {
1814- for (var a = node.argnames, i = a.length; --i >= 0;) {
1815- var sym = a[i];
1816- if (!(sym.definition().id in in_use_ids)) {
1816+ var trim = !compressor.option("keep_fargs");
1817+ for (var a = node.argnames, i = a.length; --i >= 0;) {
1818+ var sym = a[i];
1819+ if (!(sym.definition().id in in_use_ids)) {
1820+ sym.__unused = true;
1821+ if (trim) {
18171822 a.pop();
18181823 compressor.warn("Dropping unused function argument {name} [{file}:{line},{col}]", {
18191824 name : sym.name,
@@ -1822,7 +1827,9 @@ merge(Compressor.prototype, {
18221827 col : sym.start.col
18231828 });
18241829 }
1825- else break;
1830+ }
1831+ else {
1832+ trim = false;
18261833 }
18271834 }
18281835 }
@@ -2609,6 +2616,9 @@ merge(Compressor.prototype, {
26092616 exp = def.fixed;
26102617 if (compressor.option("unused")
26112618 && def.references.length == 1
2619+ && !(def.scope.uses_arguments
2620+ && def.orig[0] instanceof AST_SymbolFunarg)
2621+ && !def.scope.uses_eval
26122622 && compressor.find_parent(AST_Scope) === def.scope) {
26132623 self.expression = exp;
26142624 }
@@ -2617,16 +2627,26 @@ merge(Compressor.prototype, {
26172627 if (compressor.option("unused")
26182628 && exp instanceof AST_Function
26192629 && !exp.uses_arguments
2620- && !exp.uses_eval
2621- && self.args.length > exp.argnames.length) {
2622- var end = exp.argnames.length;
2623- for (var i = end, len = self.args.length; i < len; i++) {
2624- var node = self.args[i].drop_side_effect_free(compressor);
2625- if (node) {
2626- self.args[end++] = node;
2630+ && !exp.uses_eval) {
2631+ var pos = 0, last = 0;
2632+ for (var i = 0, len = self.args.length; i < len; i++) {
2633+ var trim = i >= exp.argnames.length;
2634+ if (trim || exp.argnames[i].__unused) {
2635+ var node = self.args[i].drop_side_effect_free(compressor);
2636+ if (node) {
2637+ self.args[pos++] = node;
2638+ } else if (!trim) {
2639+ self.args[pos++] = make_node(AST_Number, self.args[i], {
2640+ value: 0
2641+ });
2642+ continue;
2643+ }
2644+ } else {
2645+ self.args[pos++] = self.args[i];
26272646 }
2647+ last = pos;
26282648 }
2629- self.args.length = end ;
2649+ self.args.length = last ;
26302650 }
26312651 if (compressor.option("unsafe")) {
26322652 if (exp instanceof AST_SymbolRef && exp.undeclared()) {
0 commit comments