From 57105b299ec582bc731b58002703faa297f10063 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 10 Dec 2020 22:59:21 +0000 Subject: fix corner cases with spread syntax (#4358) --- test/compress/objects.js | 27 +++++ test/compress/spread.js | 273 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 288 insertions(+), 12 deletions(-) (limited to 'test/compress') 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, -- cgit v1.2.3 se.scm?id=e9fa17eb98efbd6211ab44ab49b8c078d4b73e04'>services: udev: Use a fixed location for the rules directory and config....Maxim Cournoyer 2022-01-20services: guix-publish: Add negative-ttl parameter....Guillaume Le Vaillant 2022-01-18daemon: Always default to gzip for log compression....Ludovic Courtès 2022-01-16services: guix: Add tar and gzip to PATH....Timothy Sample 2022-01-08services: networking: Add netmask to loopback address....Ludovic Courtès 2021-12-21services: static-networking: Enable multicast by default....Mathieu Othacehe 2021-12-20services: static-networking: Sanitize <network-address> values....Ludovic Courtès 2021-12-12services: Define '%loopback-static-networking'....Ludovic Courtès 2021-12-12services: Define '%qemu-static-networking'....Ludovic Courtès 2021-12-12services: static-networking: Change interface to mimic netlink....Ludovic Courtès 2021-12-12services: static-networking: Use Guile-Netlink on GNU/Linux....Ludovic Courtès 2021-11-30services: Accept <inferior-package>s in lieu of <package>s....Tobias Geerinckx-Rice 2021-11-23gnu: system: Make old-style swap use default flags....Josselin Poiret 2021-11-23system: Add swap flags....Josselin Poiret 2021-11-23system: Rework swap space support, add dependencies....Josselin Poiret 2021-08-29services: base: Honor file-system-create-mount-point? at all times....Maxim Cournoyer 2021-08-07services: pam-limits: fix limits.conf location...muradm 2021-08-04services: guix: Use "match-record" in activation....Brice Waegeneire 2021-07-13services: gpm: Use "make-forkexec-contstructor"....Brice Waegeneire 2021-06-29services: kmscon: Add keyboard-layout fields....luhui 2021-06-19services: guix: Authorize 'bordeaux.guix.gnu.org.pub' by default....Jack Hill 2021-06-14services: Remove deprecated service procedures....Ludovic Courtès 2021-04-03services: guix-publish: Add zstd compression by default....Ludovic Courtès 2021-04-01services: kmscon: Add font-engine and font-size fields....qblade 2021-03-18services: Enable "protected hardlinks" and "protected symlinks" by default....Leo Famulari 2021-01-13services: shepherd: 'shepherd-service-type' requires documentation....Ludovic Courtès 2020-12-15services: 'references-file' depends on Guile-Gcrypt....Ludovic Courtès