diff --git a/lib/compress.js b/lib/compress.js index c7b1b792f01..1583e3556e3 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7937,7 +7937,14 @@ Compressor.prototype.compress = function(node) { drop = false; value = value.fixed_value(); } - var values = value instanceof AST_Array && value.elements; + var native, values; + if (value instanceof AST_Array) { + native = true; + values = value.elements; + } else { + native = value && value.is_string(compressor); + values = false; + } var elements = [], newValues = drop && [], pos = 0; node.elements.forEach(function(element, index) { value = values && values[index]; @@ -7988,8 +7995,9 @@ Compressor.prototype.compress = function(node) { value = value.clone(); value.elements = newValues; } - if (!node.rest && (value instanceof AST_Array - || value && value.is_string(compressor))) switch (elements.length) { + if (!native) { + elements.length = node.elements.length; + } else if (!node.rest) switch (elements.length) { case 0: if (node === root) break; if (drop) value = value.drop_side_effect_free(compressor); diff --git a/test/compress/default-values.js b/test/compress/default-values.js index 38f6552da13..6f0ba192905 100644 --- a/test/compress/default-values.js +++ b/test/compress/default-values.js @@ -2713,7 +2713,7 @@ issue_5533_2_drop_fargs: { try { (function() { for (;;) { - var [ [] = [] ] = []; + var [ [ , ] = [] ] = []; throw "PASS"; } })(); diff --git a/test/compress/destructured.js b/test/compress/destructured.js index f79570f35b0..6ef2c8f7333 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -1306,7 +1306,7 @@ keep_reference: { } expect: { var a = [ {}, 42 ]; - var [ b ] = a; + var b = a[0]; console.log(a[0] === b ? "PASS" : "FAIL"); } expect_stdout: "PASS" diff --git a/test/compress/yields.js b/test/compress/yields.js index 3be214e4b88..989a9fa70e0 100644 --- a/test/compress/yields.js +++ b/test/compress/yields.js @@ -1735,3 +1735,37 @@ issue_5576: { ] node_version: ">=10" } + +issue_5663: { + options = { + toplevel: true, + unused: true, + } + input: { + var [ , a ] = function*() { + console.log("foo"); + yield console.log("bar"); + console.log("baz"); + yield console.log("moo"); + console.log("moz"); + yield FAIL; + }(); + } + expect: { + var [ , , ] = function*() { + console.log("foo"); + yield console.log("bar"); + console.log("baz"); + yield console.log("moo"); + console.log("moz"); + yield FAIL; + }(); + } + expect_stdout: [ + "foo", + "bar", + "baz", + "moo", + ] + node_version: ">=6" +}