Skip to content

Commit

Permalink
fix corner case in properties (#5351)
Browse files Browse the repository at this point in the history
fixes #5350
  • Loading branch information
alexlamsl committed Feb 12, 2022
1 parent a14555a commit 63b92ea
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/compress.js
Expand Up @@ -12746,7 +12746,7 @@ Compressor.prototype.compress = function(node) {
if (flatten && value.has_side_effects(compressor)) flatten = false;
}
}
values.unshift(retValue);
if (!flatten) values.unshift(retValue);
while (--i >= 0) {
var value = elements[i].drop_side_effect_free(compressor);
if (value) {
Expand All @@ -12757,7 +12757,11 @@ Compressor.prototype.compress = function(node) {
index--;
}
}
return flatten ? make_sequence(self, values).optimize(compressor) : make_node(AST_Sub, self, {
if (flatten) {
values.push(retValue);
return make_sequence(self, values).optimize(compressor);
}
return make_node(AST_Sub, self, {
expression: make_node(AST_Array, expr, { elements: values }),
property: make_node(AST_Number, prop, { value: index }),
});
Expand Down
30 changes: 30 additions & 0 deletions test/compress/ie.js
Expand Up @@ -3444,3 +3444,33 @@ issue_5269_3_ie: {
"bar",
]
}

issue_5350: {
options = {
ie: false,
properties: true,
side_effects: true,
}
input: {
console.log(typeof f, [ 42, function f() {} ][0]);
}
expect: {
console.log(typeof f, 42);
}
expect_stdout: "undefined 42"
}

issue_5350_ie: {
options = {
ie: true,
properties: true,
side_effects: true,
}
input: {
console.log(typeof f, [ 42, function f() {} ][0]);
}
expect: {
console.log(typeof f, (function f() {}, 42));
}
expect_stdout: "undefined 42"
}

0 comments on commit 63b92ea

Please sign in to comment.