diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-10 22:59:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-11 06:59:21 +0800 |
commit | 57105b299ec582bc731b58002703faa297f10063 (patch) | |
tree | 3e08387fd9e2e644e60461f47f9d782c51611692 /test/compress | |
parent | 77e1bda4265c9a3fe36937dd734fab85db38437c (diff) | |
download | tracifyjs-57105b299ec582bc731b58002703faa297f10063.tar.gz tracifyjs-57105b299ec582bc731b58002703faa297f10063.zip |
fix corner cases with spread syntax (#4358)
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/objects.js | 27 | ||||
-rw-r--r-- | test/compress/spread.js | 273 |
2 files changed, 288 insertions, 12 deletions
diff --git a/test/compress/objects.js b/test/compress/objects.js index 5d3653d0..5e59726d 100644 --- a/test/compress/objects.js +++ b/test/compress/objects.js @@ -360,3 +360,30 @@ issue_4269_4: { expect_stdout: "PASS" node_version: ">=4" } + +issue_4269_5: { + options = { + evaluate: true, + objects: true, + } + input: { + console.log({ + get 42() { + return "FAIL"; + }, + [console]: "bar", + 42: "PASS", + }[42]); + } + expect: { + console.log({ + get 42() { + return "FAIL"; + }, + [console]: "bar", + 42: "PASS", + }[42]); + } + expect_stdout: "PASS" + node_version: ">=4" +} diff --git a/test/compress/spread.js b/test/compress/spread.js index aaa8a7f7..32ed0b86 100644 --- a/test/compress/spread.js +++ b/test/compress/spread.js @@ -250,43 +250,119 @@ reduce_vars_2: { node_version: ">=6" } -drop_object: { +keep_getter_1: { options = { side_effects: true, } input: { - ({ ...console.log("PASS") }); + ({ + ...{ + get p() { + console.log("PASS"); + }, + }, + get q() { + console.log("FAIL"); + }, + }); } expect: { - console.log("PASS"); + ({ + ...{ + get p() { + console.log("PASS"); + }, + }, + }); } expect_stdout: "PASS" node_version: ">=8" } -keep_getter: { +keep_getter_2: { options = { side_effects: true, } input: { ({ - ...{ + ...(console.log("foo"), { get p() { - console.log("PASS"); + console.log("bar"); }, - }, - get q() { - console.log("FAIL"); - }, + }), }); } expect: { ({ - ...{ + ...(console.log("foo"), { get p() { - console.log("PASS"); + console.log("bar"); }, + }), + }); + } + expect_stdout: [ + "foo", + "bar", + ] + node_version: ">=8" +} + +keep_getter_3: { + options = { + side_effects: true, + } + input: { + ({ + ...function() { + return { + get p() { + console.log("PASS"); + }, + }; + }(), + }); + } + expect: { + ({ + ...function() { + return { + get p() { + console.log("PASS"); + }, + }; + }(), + }); + } + expect_stdout: "PASS" + node_version: ">=8" +} + +keep_getter_4: { + options = { + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + var o = { + get p() { + console.log("PASS"); + }, + }; + ({ + q: o, + ...o, + }); + } + expect: { + var o = { + get p() { + console.log("PASS"); }, + }; + ({ + ...o, }); } expect_stdout: "PASS" @@ -341,6 +417,179 @@ keep_accessor: { node_version: ">=8" } +object_key_order_1: { + options = { + objects: true, + spread: true, + } + input: { + var o = { + ...{}, + a: 1, + b: 2, + a: 3, + }; + for (var k in o) + console.log(k, o[k]); + } + expect: { + var o = { + a: (1, 3), + b: 2, + }; + for (var k in o) + console.log(k, o[k]); + } + expect_stdout: [ + "a 3", + "b 2", + ] + node_version: ">=8 <=10" +} + +object_key_order_2: { + options = { + objects: true, + spread: true, + } + input: { + var o = { + a: 1, + ...{}, + b: 2, + a: 3, + }; + for (var k in o) + console.log(k, o[k]); + } + expect: { + var o = { + a: (1, 3), + b: 2, + }; + for (var k in o) + console.log(k, o[k]); + } + expect_stdout: [ + "a 3", + "b 2", + ] + node_version: ">=8" +} + +object_key_order_3: { + options = { + objects: true, + spread: true, + } + input: { + var o = { + a: 1, + b: 2, + ...{}, + a: 3, + }; + for (var k in o) + console.log(k, o[k]); + } + expect: { + var o = { + a: (1, 3), + b: 2, + }; + for (var k in o) + console.log(k, o[k]); + } + expect_stdout: [ + "a 3", + "b 2", + ] + node_version: ">=8" +} + +object_key_order_4: { + options = { + objects: true, + spread: true, + } + input: { + var o = { + a: 1, + b: 2, + a: 3, + ...{}, + }; + for (var k in o) + console.log(k, o[k]); + } + expect: { + var o = { + a: (1, 3), + b: 2, + }; + for (var k in o) + console.log(k, o[k]); + } + expect_stdout: [ + "a 3", + "b 2", + ] + node_version: ">=8" +} + +object_spread_array: { + options = { + objects: true, + spread: true, + } + input: { + var o = { + ...[ "foo", "bar" ], + }; + for (var k in o) + console.log(k, o[k]); + } + expect: { + var o = { + ...[ "foo", "bar" ], + }; + for (var k in o) + console.log(k, o[k]); + } + expect_stdout: [ + "0 foo", + "1 bar", + ] + node_version: ">=8" +} + +object_spread_string: { + options = { + objects: true, + spread: true, + } + input: { + var o = { + ..."foo", + }; + for (var k in o) + console.log(k, o[k]); + } + expect: { + var o = { + ..."foo", + }; + for (var k in o) + console.log(k, o[k]); + } + expect_stdout: [ + "0 f", + "1 o", + "2 o", + ] + node_version: ">=8" +} + unused_var_side_effects: { options = { unused: true, |