fix corner case in pure_getters (#4877)

fixes #4876
This commit is contained in:
Alex Lam S.L
2021-04-27 15:52:37 +01:00
committed by GitHub
parent 4cccc01f3e
commit a06e20304b
2 changed files with 35 additions and 3 deletions

View File

@@ -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 rhs = this.right;
if (!rhs._dot_throw(compressor)) 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;
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);

View File

@@ -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"
}