From ac002b6338a65d2323c092e34815d4db252da19a Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 18 Aug 2022 19:31:48 +0100 Subject: [PATCH] fix corner case in `reduce_vars` (#5624) fixes #5623 --- lib/compress.js | 1 + test/compress/reduce_vars.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index 6473da50444..bcfee5a48d4 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1016,6 +1016,7 @@ Compressor.prototype.compress = function(node) { } function walk_prop(lhs) { + reset_flags(lhs); if (lhs instanceof AST_Dot) { walk_prop(lhs.expression); } else if (lhs instanceof AST_Sub) { diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 348d2c9eba4..002202617dc 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -7896,3 +7896,33 @@ issue_5434: { } expect_stdout: "PASS" } + +issue_5623: { + options = { + collapse_vars: true, + evaluate: true, + passes: 2, + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + var a = 0; + function f() { + var b = a; + a = b; + } + f && f((a++ && a).toString()); + console.log(a); + } + expect: { + var a = 0; + function f() { + var b; + a = a; + } + f((a++ && a).toString()); + console.log(a); + } + expect_stdout: "1" +}