aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js30
1 files changed, 24 insertions, 6 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 6a76fc32..09019a74 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -5173,24 +5173,42 @@ merge(Compressor.prototype, {
&& !fn.uses_arguments
&& !fn.pinned()) {
var pos = 0, last = 0;
+ var side_effects = [];
for (var i = 0; i < self.args.length; i++) {
var trim = i >= fn.argnames.length;
if (trim || fn.argnames[i].__unused) {
var node = self.args[i].drop_side_effect_free(compressor);
- if (node) {
- self.args[pos++] = node;
+ if (exp === fn) {
+ fn.argnames.splice(i, 1);
+ self.args.splice(i, 1);
+ if (node) side_effects.push(node);
+ i--;
+ continue;
+ } else if (node) {
+ side_effects.push(node);
+ self.args[pos++] = make_sequence(self, side_effects);
+ side_effects = [];
} else if (!trim) {
- self.args[pos++] = make_node(AST_Number, self.args[i], {
- value: 0
- });
+ if (side_effects.length) {
+ node = make_sequence(self, side_effects);
+ side_effects = [];
+ } else {
+ node = make_node(AST_Number, self.args[i], {
+ value: 0
+ });
+ }
+ self.args[pos++] = node;
continue;
}
} else {
- self.args[pos++] = self.args[i];
+ side_effects.push(self.args[i]);
+ self.args[pos++] = make_sequence(self, side_effects);
+ side_effects = [];
}
last = pos;
}
self.args.length = last;
+ if (side_effects.length) self.args.push(make_sequence(self, side_effects));
}
if (compressor.option("unsafe")) {
if (is_undeclared_ref(exp)) switch (exp.name) {