From a06e20304b042ab5cd2ad051fb60cf50a7934bb7 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 27 Apr 2021 15:52:37 +0100 Subject: [PATCH] fix corner case in `pure_getters` (#4877) fixes #4876 --- lib/compress.js | 7 +++++-- test/compress/assignments.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 150b554ee5..3847015dbe 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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); diff --git a/test/compress/assignments.js b/test/compress/assignments.js index 3973e2f57a..fba763d35a 100644 --- a/test/compress/assignments.js +++ b/test/compress/assignments.js @@ -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" +}