fix corner case in `side_effects` (#4541)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 12 Jan 2021 01:12:43 +0000 (01:12 +0000)
committerGitHub <noreply@github.com>
Tue, 12 Jan 2021 01:12:43 +0000 (09:12 +0800)
fixes #4540

lib/compress.js
test/compress/default-values.js

index e998554..578e73c 100644 (file)
@@ -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);
             }
index 23e3174..985651a 100644 (file)
@@ -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"
+}