Skip to content

Commit

Permalink
fix corner case in unused (#5706)
Browse files Browse the repository at this point in the history
fixes #5705
  • Loading branch information
alexlamsl authored Oct 10, 2022
1 parent ed7051b commit bccb1c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
7 changes: 3 additions & 4 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -7251,15 +7251,13 @@ Compressor.prototype.compress = function(node) {
node.name = null;
}
if (node instanceof AST_Lambda) {
descend_scope();
if (drop_funcs && node !== self && node instanceof AST_LambdaDefinition) {
var def = node.name.definition();
if (!(def.id in in_use_ids)) {
log(node.name, "Dropping unused function {name}");
def.eliminated++;
if (parent instanceof AST_ExportDefault) {
descend_scope();
return to_func_expr(node, true);
}
if (parent instanceof AST_ExportDefault) return to_func_expr(node, true);
return in_list ? List.skip : make_node(AST_EmptyStatement, node);
}
}
Expand Down Expand Up @@ -7357,6 +7355,7 @@ Compressor.prototype.compress = function(node) {
}
fns_with_marked_args.push(node);
}
return node;
}
if (node instanceof AST_Catch && node.argname instanceof AST_Destructured) {
node.argname.transform(trimmer);
Expand Down
18 changes: 18 additions & 0 deletions test/compress/rests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1624,3 +1624,21 @@ issue_5552_4: {
expect_stdout: "PASS"
node_version: ">=6"
}

issue_5705: {
options = {
reduce_vars: true,
rests: true,
unused: true,
}
input: {
(function(...a) {
var b = { ...a };
})(console.log("PASS"));
}
expect: {
(function() {})(console.log("PASS"));
}
expect_stdout: "PASS"
node_version: ">=8.3.0"
}
4 changes: 1 addition & 3 deletions test/compress/side_effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,7 @@ issue_4668: {
}
expect: {
console.log(function f() {
(function g() {
0;
})();
(function g() {})();
}());
}
expect_stdout: "undefined"
Expand Down

0 comments on commit bccb1c3

Please sign in to comment.