fix corner case in unused (#5392)

fixes #5391
This commit is contained in:
Alex Lam S.L
2022-03-27 22:46:43 +01:00
committed by GitHub
parent c624b43739
commit 15a4074d1a
2 changed files with 48 additions and 1 deletions

View File

@@ -6847,7 +6847,14 @@ Compressor.prototype.compress = function(node) {
});
}
}
if (node instanceof AST_Call) calls_to_drop_args.push(node);
if (node instanceof AST_Call) {
calls_to_drop_args.push(node);
node.args = node.args.map(function(arg) {
return arg.transform(tt);
});
node.expression = node.expression.transform(tt);
return node;
}
if (scope !== self) return;
if (drop_funcs && node !== self && node instanceof AST_DefClass) {
var def = node.name.definition();

View File

@@ -1323,3 +1323,43 @@ issue_5370: {
expect_stdout: true
node_version: ">=6"
}
issue_5391: {
options = {
evaluate: true,
keep_fargs: false,
objects: true,
pure_getters: "strict",
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
var a, b = function f({
p: {},
...c
}) {
while (c.q);
}({
p: {
r: a++,
r: 0,
}
});
console.log(a);
}
expect: {
(function({
p: {},
...c
}) {
while (c.q);
})({
p: 0,
});
console.log(NaN);
}
expect_stdout: "NaN"
node_version: ">=8.3.0"
}