From 18c2b1841bf0bfa6c827eed53238d0499c143b23 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 10 Dec 2019 09:45:51 +0000 Subject: [PATCH] fix corner case in `reduce_vars` (#3632) fixes #3631 --- lib/compress.js | 4 ++-- test/compress/reduce_vars.js | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index a34272ca..6d398de2 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -648,7 +648,7 @@ merge(Compressor.prototype, { tw.in_loop = this; push(tw); this.body.walk(tw); - if (has_break_or_continue(this)) { + if (has_break_or_continue(this, tw.parent())) { pop(tw); push(tw); } @@ -665,7 +665,7 @@ merge(Compressor.prototype, { if (this.condition) this.condition.walk(tw); this.body.walk(tw); if (this.step) { - if (has_break_or_continue(this)) { + if (has_break_or_continue(this, tw.parent())) { pop(tw); push(tw); } diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 443c347d..5984042f 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -6801,3 +6801,49 @@ issue_3622: { } expect_stdout: "PASS" } + +issue_3631_1: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + } + input: { + var c = 0; + L: do { + for (;;) continue L; + var b = 1; + } while (b && c++); + console.log(c); + } + expect: { + var c = 0; + L: do { + for (;;) continue L; + var b = 1; + } while (b && c++); + console.log(c); + } + expect_stdout: "0" +} + +issue_3631_2: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + L: for (var a = 1; a--; console.log(b)) { + for (;;) continue L; + var b = "FAIL"; + } + } + expect: { + L: for (var a = 1; a--; console.log(b)) { + for (;;) continue L; + var b = "FAIL"; + } + } + expect_stdout: "undefined" +} -- 2.34.1