From 1e831df1f6a39ccc043384f04863aea58dbd7d9c Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 12 Jan 2021 01:12:43 +0000 Subject: [PATCH] fix corner case in `side_effects` (#4541) fixes #4540 --- lib/compress.js | 2 +- test/compress/default-values.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index e9985540..578e73cc 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -8226,7 +8226,7 @@ merge(Compressor.prototype, { if (compressor.option("side_effects") && can_drop && all(fn.body, is_empty) - && (fn !== exp || fn_name_unused(fn, compressor)) + && (fn === exp ? fn_name_unused(fn, compressor) : !has_default && !has_destructured) && !(is_arrow(fn) && fn.value)) { return make_sequence(self, convert_args()).optimize(compressor); } diff --git a/test/compress/default-values.js b/test/compress/default-values.js index 23e31748..985651a3 100644 --- a/test/compress/default-values.js +++ b/test/compress/default-values.js @@ -1549,3 +1549,24 @@ issue_4523: { expect_stdout: "PASS" node_version: ">=6" } + +issue_4540: { + options = { + reduce_vars: true, + side_effects: true, + } + input: { + console.log(function() { + function f([ a = 0 ]) {} + f([]); + }()); + } + expect: { + console.log(function() { + function f([ a = 0 ]) {} + f([]); + }()); + } + expect_stdout: "undefined" + node_version: ">=6" +} -- 2.34.1