From e21bab7ce65e6a4db0ea966b3336eaab2a634e6e Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 19 Jan 2018 20:13:50 +0800 Subject: avoid duplicate property names in object literals under "use strict" (#2818) fixes #2816 --- lib/compress.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/compress.js b/lib/compress.js index bda5d7a6..00593e81 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -893,7 +893,7 @@ merge(Compressor.prototype, { sequencesize_2(statements, compressor); } if (compressor.option("join_vars")) { - join_consecutive_vars(statements, compressor); + join_consecutive_vars(statements); } if (compressor.option("collapse_vars")) { collapse(statements, compressor); @@ -1746,8 +1746,14 @@ merge(Compressor.prototype, { prop = prop.evaluate(compressor); } if (prop instanceof AST_Node) break; + prop = "" + prop; + if (compressor.has_directive("use strict")) { + if (!all(def.value.properties, function(node) { + return node.key != prop && node.key.name != prop; + })) break; + } def.value.properties.push(make_node(AST_ObjectKeyVal, node, { - key: "" + prop, + key: prop, value: node.right })); exprs.shift(); @@ -1756,7 +1762,7 @@ merge(Compressor.prototype, { return trimmed && exprs; } - function join_consecutive_vars(statements, compressor) { + function join_consecutive_vars(statements) { var defs; for (var i = 0, j = -1, len = statements.length; i < len; i++) { var stat = statements[i]; -- cgit v1.2.3