Skip to content

Commit

Permalink
fix corner case in unused (#5225)
Browse files Browse the repository at this point in the history
fixes #5224
  • Loading branch information
alexlamsl committed Dec 19, 2021
1 parent 9e927ec commit 86406e7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/compress.js
Expand Up @@ -8076,7 +8076,11 @@ Compressor.prototype.compress = function(node) {
exprs = trim(exprs, compressor, first_in_statement, array_spread);
return exprs && make_sequence(self, exprs.map(convert_spread));
}
if (!fn.contains_this()) self = make_node(AST_Call, self, self);
if (!fn.contains_this()) {
self = make_node(AST_Call, self, self);
self.expression = self.expression.clone();
self.args = self.args.slice();
}
}
}
self.call_only = true;
Expand Down Expand Up @@ -9565,7 +9569,7 @@ Compressor.prototype.compress = function(node) {
expression: exp.expression,
property: "call",
}),
args: args
args: args,
}).optimize(compressor);
}
break;
Expand All @@ -9579,11 +9583,11 @@ Compressor.prototype.compress = function(node) {
self.args[0],
make_node(AST_Call, self, {
expression: exp.expression,
args: self.args.slice(1)
})
args: self.args.slice(1),
}),
]) : make_node(AST_Call, self, {
expression: exp.expression,
args: []
args: [],
})).optimize(compressor);
}
break;
Expand Down
44 changes: 44 additions & 0 deletions test/compress/drop-unused.js
Expand Up @@ -3516,3 +3516,47 @@ issue_5079: {
}
expect_stdout: "PASS"
}

issue_5224: {
options = {
evaluate: true,
keep_fargs: false,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
function f() {
try {
var b = function() {
var a = "FAIL 1";
null && a;
a = console.log(a);
}(new function(c, d) {
console.log(d);
a;
}("FAIL 2", Infinity));
} finally {
return f;
}
}
f();
}
expect: {
(function f() {
try {
(function() {
var a = "FAIL 1";
null;
a = console.log(a);
})(function() {
console.log(1 / 0);
a;
}());
} finally {
return f;
}
})();
}
expect_stdout: "Infinity"
}

0 comments on commit 86406e7

Please sign in to comment.