Skip to content

Commit bccb1c3

Browse files
authored
fix corner case in unused (#5706)
fixes #5705
1 parent ed7051b commit bccb1c3

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

lib/compress.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7251,15 +7251,13 @@ Compressor.prototype.compress = function(node) {
72517251
node.name = null;
72527252
}
72537253
if (node instanceof AST_Lambda) {
7254+
descend_scope();
72547255
if (drop_funcs && node !== self && node instanceof AST_LambdaDefinition) {
72557256
var def = node.name.definition();
72567257
if (!(def.id in in_use_ids)) {
72577258
log(node.name, "Dropping unused function {name}");
72587259
def.eliminated++;
7259-
if (parent instanceof AST_ExportDefault) {
7260-
descend_scope();
7261-
return to_func_expr(node, true);
7262-
}
7260+
if (parent instanceof AST_ExportDefault) return to_func_expr(node, true);
72637261
return in_list ? List.skip : make_node(AST_EmptyStatement, node);
72647262
}
72657263
}
@@ -7357,6 +7355,7 @@ Compressor.prototype.compress = function(node) {
73577355
}
73587356
fns_with_marked_args.push(node);
73597357
}
7358+
return node;
73607359
}
73617360
if (node instanceof AST_Catch && node.argname instanceof AST_Destructured) {
73627361
node.argname.transform(trimmer);

test/compress/rests.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,3 +1624,21 @@ issue_5552_4: {
16241624
expect_stdout: "PASS"
16251625
node_version: ">=6"
16261626
}
1627+
1628+
issue_5705: {
1629+
options = {
1630+
reduce_vars: true,
1631+
rests: true,
1632+
unused: true,
1633+
}
1634+
input: {
1635+
(function(...a) {
1636+
var b = { ...a };
1637+
})(console.log("PASS"));
1638+
}
1639+
expect: {
1640+
(function() {})(console.log("PASS"));
1641+
}
1642+
expect_stdout: "PASS"
1643+
node_version: ">=8.3.0"
1644+
}

test/compress/side_effects.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,7 @@ issue_4668: {
584584
}
585585
expect: {
586586
console.log(function f() {
587-
(function g() {
588-
0;
589-
})();
587+
(function g() {})();
590588
}());
591589
}
592590
expect_stdout: "undefined"

0 commit comments

Comments
 (0)