From 20252c6483ae8a0c404250dbe8b07713002fae57 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 17 Apr 2022 23:38:08 +0100 Subject: [PATCH] fix corner case in `merge_vars` (#5421) fixes #5420 --- lib/compress.js | 3 --- test/compress/merge_vars.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 1462cf5f..e3dec09a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6246,9 +6246,7 @@ Compressor.prototype.compress = function(node) { if (node instanceof AST_Try) { var save_try = in_try; in_try = node; - var save = segment; walk_body(node, tw); - segment = save; if (node.bcatch) { if (node.bcatch.argname) node.bcatch.argname.mark_symbol(function(node) { if (node instanceof AST_SymbolCatch) { @@ -6266,7 +6264,6 @@ Compressor.prototype.compress = function(node) { } } in_try = save_try; - segment = save; if (node.bfinally) node.bfinally.walk(tw); return true; } diff --git a/test/compress/merge_vars.js b/test/compress/merge_vars.js index 8d69731b..67635436 100644 --- a/test/compress/merge_vars.js +++ b/test/compress/merge_vars.js @@ -3702,3 +3702,33 @@ issue_5182: { ] node_version: ">=4" } + +issue_5420: { + options = { + merge_vars: true, + toplevel: true, + } + input: { + do { + var a = "FAIL 1"; + a && a.p; + a = "FAIL 2"; + try { + continue; + } catch (e) {} + var b = "FAIL 3"; + } while (console.log(b || "PASS")); + } + expect: { + do { + var a = "FAIL 1"; + a && a.p; + a = "FAIL 2"; + try { + continue; + } catch (e) {} + var b = "FAIL 3"; + } while (console.log(b || "PASS")); + } + expect_stdout: "PASS" +}