From: Alex Lam S.L Date: Sun, 22 Oct 2017 07:00:36 +0000 (+0800) Subject: fix `unsafe` expansion of object literals (#2390) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=5fd723f14394b74f899e7b33bc9084317bf01d7d;p=UglifyJS.git fix `unsafe` expansion of object literals (#2390) --- diff --git a/lib/compress.js b/lib/compress.js index 6a40ef2a..8bc0e262 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4499,12 +4499,11 @@ merge(Compressor.prototype, { for (var i = values.length; --i >= 0;) { if (values[i].key === self.property) { var value = values[i].value; - if (value instanceof AST_Function ? !value.contains_this() : !value.has_side_effects(compressor)) { - var obj = self.expression.clone(); - obj.properties = obj.properties.slice(); - obj.properties.splice(i, 1); - return make_sequence(self, [ obj, value ]).optimize(compressor); - } + if (value instanceof AST_Function ? value.contains_this() : value.has_side_effects(compressor)) break; + var obj = self.expression.clone(); + obj.properties = obj.properties.slice(); + obj.properties.splice(i, 1); + return make_sequence(self, [ obj, value ]).optimize(compressor); } } } diff --git a/test/compress/properties.js b/test/compress/properties.js index 45f870df..496a43ca 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -841,3 +841,22 @@ lhs_prop_2: { "abc"[2] = "g"; } } + +literal_duplicate_key_side_effects: { + options = { + unsafe: true, + } + input: { + console.log({ + a: "FAIL", + a: console.log ? "PASS" : "FAIL" + }.a); + } + expect: { + console.log({ + a: "FAIL", + a: console.log ? "PASS" : "FAIL" + }.a); + } + expect_stdout: "PASS" +}