From bccb1c3bd9155e1045e2fcac7dff2245250f7bcb Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 10 Oct 2022 01:02:23 +0100 Subject: [PATCH] fix corner case in `unused` (#5706) fixes #5705 --- lib/compress.js | 7 +++---- test/compress/rests.js | 18 ++++++++++++++++++ test/compress/side_effects.js | 4 +--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 26daf3e2aa..58f083226d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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); } } @@ -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); diff --git a/test/compress/rests.js b/test/compress/rests.js index b18ab0b457..4d020d23eb 100644 --- a/test/compress/rests.js +++ b/test/compress/rests.js @@ -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" +} diff --git a/test/compress/side_effects.js b/test/compress/side_effects.js index 090a656620..3c09448d08 100644 --- a/test/compress/side_effects.js +++ b/test/compress/side_effects.js @@ -584,9 +584,7 @@ issue_4668: { } expect: { console.log(function f() { - (function g() { - 0; - })(); + (function g() {})(); }()); } expect_stdout: "undefined"