diff --git a/lib/compress.js b/lib/compress.js index c5d75d427b2..6d1f93d4ead 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7276,6 +7276,7 @@ merge(Compressor.prototype, { } function retain_lhs(node) { + if (node instanceof AST_DefaultValue) return retain_lhs(node.name); if (node instanceof AST_Destructured) { if (value === null) { value = make_node(AST_Number, node, { value: 0 }); @@ -7289,7 +7290,6 @@ merge(Compressor.prototype, { } return make_node(AST_DestructuredObject, node, { properties: [] }); } - if (node instanceof AST_DefaultValue) node = node.name; node.__unused = null; return node; } diff --git a/test/compress/loops.js b/test/compress/loops.js index 034537a6a55..d5f9269a630 100644 --- a/test/compress/loops.js +++ b/test/compress/loops.js @@ -193,9 +193,9 @@ evaluate: { } while (false); } expect: { - for(;;) + for (;;) a(); - for(;;) + for (;;) c(); d(); } diff --git a/test/compress/rests.js b/test/compress/rests.js index 18064603e8a..f6878aa8865 100644 --- a/test/compress/rests.js +++ b/test/compress/rests.js @@ -943,10 +943,63 @@ issue_4666: { expect: { var a = 0, b = 0; var o = (c => +a + c)([ b ]); - for(var k in o) + for (var k in o) b++; console.log(1, b); } expect_stdout: "1 2" node_version: ">=6" } + +issue_5089_1: { + options = { + unused: true, + } + input: { + var { + p: [] = 42, + ...o + } = { + p: [], + }; + console.log(o.p); + } + expect: { + var { + p: {}, + ...o + } = { + p: 0, + }; + console.log(o.p); + } + expect_stdout: "undefined" + node_version: ">=8" +} + +issue_5089_2: { + options = { + pure_getters: "strict", + unused: true, + } + input: { + var { + p: {} = null, + ...o + } = { + p: {}, + }; + console.log(o.p); + } + expect: { + var { + p: {}, + ...o + } = { + p: 0, + }; + console.log(o.p); + } + expect_stdout: "undefined" + node_version: ">=8" +} diff --git a/test/compress/transform.js b/test/compress/transform.js index d8e1ee79006..1bee8da990f 100644 --- a/test/compress/transform.js +++ b/test/compress/transform.js @@ -95,7 +95,7 @@ while_if_break: { } } expect: { - for(; a && (b && c && d, !e);); + for (; a && (b && c && d, !e);); } }