From 2bf8216e506f2c447859e0e080b10f0341802463 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 13 Aug 2017 22:08:33 +0800 Subject: [PATCH] fix `pure_getters` on spread of objects (#2275) --- lib/compress.js | 7 +++- test/compress/pure_getters.js | 73 +++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 275503c0..ff7d0059 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1427,9 +1427,14 @@ merge(Compressor.prototype, { def(AST_Object, function(compressor) { if (!is_strict(compressor)) return false; for (var i = this.properties.length; --i >=0;) - if (this.properties[i].value instanceof AST_Accessor) return true; + if (this.properties[i]._dot_throw(compressor)) return true; return false; }); + def(AST_ObjectProperty, return_false); + def(AST_ObjectGetter, return_true); + def(AST_Expansion, function(compressor) { + return this.expression._dot_throw(compressor); + }); def(AST_Function, return_false); def(AST_Arrow, return_false); def(AST_UnaryPostfix, return_false); diff --git a/test/compress/pure_getters.js b/test/compress/pure_getters.js index dc56e19d..d7d3f381 100644 --- a/test/compress/pure_getters.js +++ b/test/compress/pure_getters.js @@ -385,3 +385,76 @@ set_mutable_2: { } expect_stdout: "PASS" } + +issue_2265_1: { + options = { + pure_getters: "strict", + side_effects: true, + } + input: { + ({ ...{} }).p; + ({ ...g }).p; + } + expect: { + ({ ...g }).p; + } +} + +issue_2265_2: { + options = { + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + var a = { + get b() { + throw 0; + } + }; + ({...a}).b; + } + expect: { + var a = { + get b() { + throw 0; + } + }; + ({...a}).b; + } +} + +issue_2265_3: { + options = { + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + var a = { + set b() { + throw 0; + } + }; + ({...a}).b; + } + expect: {} +} + +issue_2265_4: { + options = { + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + var a = { b: 1 }; + ({...a}).b; + } + expect: {} +}