From 8961c242c1e25526364130f0150a075a6dbd736e Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Fri, 1 Jul 2022 20:47:16 +0800 Subject: [PATCH] fix corner case in `inline` fixes #5536 --- lib/compress.js | 8 ++++---- test/compress/default-values.js | 29 ++++++++++++++++++++++++++--- test/compress/destructured.js | 2 +- test/compress/rests.js | 2 +- test/compress/yields.js | 2 +- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index b94b50403e2..3b735b96ccd 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1598,8 +1598,7 @@ Compressor.prototype.compress = function(node) { AST_Destructured.DEFMETHOD("convert_symbol", convert_destructured); function convert_symbol(type, process) { var node = make_node(type, this, this); - process(node, this); - return node; + return process(node, this) || node; } AST_SymbolDeclaration.DEFMETHOD("convert_symbol", convert_symbol); AST_SymbolRef.DEFMETHOD("convert_symbol", convert_symbol); @@ -10548,9 +10547,9 @@ Compressor.prototype.compress = function(node) { return try_evaluate(compressor, self); function make_void_lhs(orig) { - return make_node(AST_Dot, orig, { + return make_node(AST_Sub, orig, { expression: make_node(AST_Array, orig, { elements: [] }), - property: "e", + property: make_node(AST_Number, orig, { value: 0 }), }); } @@ -10905,6 +10904,7 @@ Compressor.prototype.compress = function(node) { })); function process(ref, name) { + if (name.unused) return make_void_lhs(name); var def = name.definition(); def.assignments++; def.references.push(ref); diff --git a/test/compress/default-values.js b/test/compress/default-values.js index 50bfd9588fe..bb1a1133819 100644 --- a/test/compress/default-values.js +++ b/test/compress/default-values.js @@ -541,7 +541,7 @@ inline_side_effects_2: { } expect: { var a = 42; - [ [].e = --a ] = [ console ]; + [ [][0] = --a ] = [ console ]; console.log(a); } expect_stdout: "42" @@ -1558,7 +1558,7 @@ issue_4502_4: { (function(a, b = console.log("FAIL")) {})(..."" + console.log(42)); } expect: { - [ , [].e = console.log("FAIL") ] = [ ..."" + console.log(42) ]; + [ , [][0] = console.log("FAIL") ] = [ ..."" + console.log(42) ]; } expect_stdout: "42" node_version: ">=6" @@ -2183,7 +2183,7 @@ issue_5340_2: { } expect: { var a; - [ [].e = 0 ] = [ ({ p: a } = true).q ]; + [ [][0] = 0 ] = [ ({ p: a } = true).q ]; console.log(a); } expect_stdout: "undefined" @@ -2806,3 +2806,26 @@ issue_5533_4_drop_fargs: { expect_stdout: "PASS" node_version: ">=6" } + +issue_5536: { + options = { + inline: true, + keep_fargs: true, + unused: true, + } + input: { + (function*() { + (([], a = 42) => {})([]); + console.log(typeof a); + })().next(); + } + expect: { + (function*() { + [ , [][0] = 0 ] = [ [] ], + void 0; + console.log(typeof a); + })().next(); + } + expect_stdout: "undefined" + node_version: ">=6" +} diff --git a/test/compress/destructured.js b/test/compress/destructured.js index 9b49da3419a..4f615e92145 100644 --- a/test/compress/destructured.js +++ b/test/compress/destructured.js @@ -3497,7 +3497,7 @@ issue_5314_2: { A = this; new function() { [ { - [console.log(this === A ? "FAIL" : "PASS")]: [].e, + [console.log(this === A ? "FAIL" : "PASS")]: [][0], } ] = [ 42 ]; }(); } diff --git a/test/compress/rests.js b/test/compress/rests.js index 752b81c4760..b736a055cf1 100644 --- a/test/compress/rests.js +++ b/test/compress/rests.js @@ -648,7 +648,7 @@ drop_new_function: { } expect: { void ([ ... { - [console.log("PASS")]: [].e, + [console.log("PASS")]: [][0], }] = []); } expect_stdout: "PASS" diff --git a/test/compress/yields.js b/test/compress/yields.js index 10f76940c04..e4ca2bd8491 100644 --- a/test/compress/yields.js +++ b/test/compress/yields.js @@ -907,7 +907,7 @@ drop_body: { })([ console.log("baz") ]); } expect: { - [ [ , [].e = console.log("foo") ] ] = [ [ console.log("baz") ] ]; + [ [ , [][0] = console.log("foo") ] ] = [ [ console.log("baz") ] ]; } expect_stdout: [ "baz",