Skip to content

Commit

Permalink
fix argument/atom collision by properties (#2514)
Browse files Browse the repository at this point in the history
fixes #2513
  • Loading branch information
alexlamsl committed Nov 25, 2017
1 parent 97c464d commit c141ae6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/compress.js
Expand Up @@ -4708,6 +4708,17 @@ merge(Compressor.prototype, {
if (compressor.option("properties")) {
var key = prop.evaluate(compressor);
if (key !== prop) {
if (typeof key == "string") {
if (key == "undefined") {
key = undefined;
} else {
var value = parseFloat(key);
if (value.toString() == key) {
key = value;
}
}
}
prop = self.property = best_of_expression(prop, make_node_from_constant(key, prop).transform(compressor));
var property = "" + key;
if (is_identifier_string(property)
&& property.length <= prop.print_to_string().length + 1) {
Expand All @@ -4716,14 +4727,6 @@ merge(Compressor.prototype, {
property: property
}).optimize(compressor);
}
if (!(prop instanceof AST_Number)) {
var value = parseFloat(property);
if (value.toString() == property) {
prop = self.property = make_node(AST_Number, prop, {
value: value
});
}
}
}
}
if (is_lhs(self, compressor.parent())) return self;
Expand Down
26 changes: 26 additions & 0 deletions test/compress/properties.js
Expand Up @@ -1028,3 +1028,29 @@ new_this: {
}(42);
}
}

issue_2513: {
options = {
evaluate: true,
properties: true,
}
input: {
!function(Infinity, NaN, undefined) {
console.log("a"[1/0], "b"["Infinity"]);
console.log("c"[0/0], "d"["NaN"]);
console.log("e"[void 0], "f"["undefined"]);
}(0, 0, 0);
}
expect: {
!function(Infinity, NaN, undefined) {
console.log("a"[1/0], "b"[1/0]);
console.log("c".NaN, "d".NaN);
console.log("e"[void 0], "f"[void 0]);
}(0, 0, 0);
}
expect_stdout: [
"undefined undefined",
"undefined undefined",
"undefined undefined",
]
}

0 comments on commit c141ae6

Please sign in to comment.