Skip to content

Commit

Permalink
fix corner case in ie8 (#5040)
Browse files Browse the repository at this point in the history
fixes #5039
  • Loading branch information
alexlamsl committed Jun 29, 2021
1 parent 798121c commit 4ba8b66
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -7861,11 +7861,13 @@ merge(Compressor.prototype, {
var prop = this.property;
if (expr.may_throw_on_access(compressor)) {
if (!this.optional) return this;
prop = prop.drop_side_effect_free(compressor);
if (!prop) return expr.drop_side_effect_free(compressor, first_in_statement);
var node = this.clone();
node.property = prop;
return node;
if (prop.has_side_effects(compressor)) {
prop = prop.drop_side_effect_free(compressor);
if (!prop) return expr.drop_side_effect_free(compressor, first_in_statement);
var node = this.clone();
node.property = prop;
return node;
}
}
expr = expr.drop_side_effect_free(compressor, first_in_statement);
if (!expr) return prop.drop_side_effect_free(compressor, first_in_statement);
Expand Down
22 changes: 22 additions & 0 deletions test/compress/optional-chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,25 @@ issue_4947_2: {
expect_stdout: "PASS"
node_version: ">=14"
}

issue_5039: {
options = {
ie8: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
var a = a?.[function f() {
f;
a;
}];
console.log("PASS");
}
expect: {
(function f() {});
console.log("PASS");
}
expect_stdout: "PASS"
node_version: ">=14"
}

0 comments on commit 4ba8b66

Please sign in to comment.