Skip to content

Commit 9699ffb

Browse files
authoredMar 2, 2017
trim unused invocation parameters (#1526)
1 parent fdc9b94 commit 9699ffb

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
 

‎lib/compress.js

+14
Original file line numberDiff line numberDiff line change
@@ -2481,6 +2481,20 @@ merge(Compressor.prototype, {
24812481
});
24822482

24832483
OPT(AST_Call, function(self, compressor){
2484+
if (compressor.option("unused")
2485+
&& self.expression instanceof AST_Function
2486+
&& !self.expression.uses_arguments
2487+
&& !self.expression.uses_eval
2488+
&& self.args.length > self.expression.argnames.length) {
2489+
var end = self.expression.argnames.length;
2490+
for (var i = end, len = self.args.length; i < len; i++) {
2491+
var node = self.args[i].drop_side_effect_free(compressor);
2492+
if (node) {
2493+
self.args[end++] = node;
2494+
}
2495+
}
2496+
self.args.length = end;
2497+
}
24842498
if (compressor.option("unsafe")) {
24852499
var exp = self.expression;
24862500
if (exp instanceof AST_SymbolRef && exp.undeclared()) {

‎test/compress/evaluate.js

+23
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,29 @@ call_args: {
646646
}
647647
}
648648

649+
call_args_drop_param: {
650+
options = {
651+
evaluate: true,
652+
keep_fargs: false,
653+
reduce_vars: true,
654+
unused: true,
655+
}
656+
input: {
657+
const a = 1;
658+
console.log(a);
659+
+function(a) {
660+
return a;
661+
}(a, b);
662+
}
663+
expect: {
664+
const a = 1;
665+
console.log(1);
666+
+function() {
667+
return 1;
668+
}(b);
669+
}
670+
}
671+
649672
in_boolean_context: {
650673
options = {
651674
booleans: true,

0 commit comments

Comments
 (0)
Please sign in to comment.