Skip to content

Commit

Permalink
fix corner case in pure_getters (#4877)
Browse files Browse the repository at this point in the history
fixes #4876
  • Loading branch information
alexlamsl committed Apr 27, 2021
1 parent 4cccc01 commit a06e203
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/compress.js
Expand Up @@ -3683,10 +3683,13 @@ merge(Compressor.prototype, {
def(AST_Node, is_strict);
def(AST_Array, return_false);
def(AST_Assign, function(compressor) {
if (this.operator != "=") return false;
var op = this.operator;
var sym = this.left;
var rhs = this.right;
if (op != "=") {
return lazy_op[op.slice(0, -1)] && (sym._dot_throw(compressor) || rhs._dot_throw(compressor));
}
if (!rhs._dot_throw(compressor)) return false;
var sym = this.left;
if (!(sym instanceof AST_SymbolRef)) return true;
if (rhs instanceof AST_Binary && rhs.operator == "||" && sym.name == rhs.left.name) {
return rhs.right._dot_throw(compressor);
Expand Down
29 changes: 29 additions & 0 deletions test/compress/assignments.js
Expand Up @@ -672,3 +672,32 @@ issue_4827_3: {
expect_stdout: "undefined"
node_version: ">=15"
}

issue_4876: {
options = {
pure_getters: "strict",
reduce_vars: true,
side_effects: true,
toplevel: true,
}
input: {
try {
var a = null;
var b = a &&= 42;
b.p;
} catch (e) {
console.log("PASS");
}
}
expect: {
try {
var a = null;
var b = a &&= 42;
b.p;
} catch (e) {
console.log("PASS");
}
}
expect_stdout: "PASS"
node_version: ">=15"
}

0 comments on commit a06e203

Please sign in to comment.