From ee632a5519078ac3fe97d0864731bea4bdad9365 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 31 Jul 2020 01:05:09 +0100 Subject: [PATCH] fix corner case in `reduce_vars` (#4031) fixes #4030 --- lib/compress.js | 5 ++++- test/compress/reduce_vars.js | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index d439ed4c..792d5ab2 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -587,7 +587,10 @@ merge(Compressor.prototype, { d.assignments++; var fixed = d.fixed; var value = eq ? node.right : node; - if (is_modified(compressor, tw, node, value, 0)) return; + if (is_modified(compressor, tw, node, value, 0)) { + d.fixed = false; + return; + } var safe = eq || safe_to_read(tw, d); node.right.walk(tw); if (safe && safe_to_assign(tw, d)) { diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 9010fb1e..85969f90 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -7383,3 +7383,26 @@ issue_3974: { } expect_stdout: "PASS" } + +issue_4030: { + options = { + collapse_vars: true, + evaluate: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var a; + { + delete (a = "PASS"); + A = "PASS"; + } + console.log(A); + } + expect: { + A = "PASS"; + console.log("PASS"); + } + expect_stdout: "PASS" +} -- 2.34.1