diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-01-19 20:13:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-19 20:13:50 +0800 |
commit | e21bab7ce65e6a4db0ea966b3336eaab2a634e6e (patch) | |
tree | 23bd5d47a7ed3f9f0efcb925c8025b4e8139330d /lib | |
parent | ac9a168fba726d9ab437478c81626f098997d116 (diff) | |
download | tracifyjs-e21bab7ce65e6a4db0ea966b3336eaab2a634e6e.tar.gz tracifyjs-e21bab7ce65e6a4db0ea966b3336eaab2a634e6e.zip |
avoid duplicate property names in object literals under "use strict" (#2818)
fixes #2816
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 12 |
1 files changed, 9 insertions, 3 deletions
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]; |