From: Alex Lam S.L Date: Sun, 29 Dec 2019 00:57:59 +0000 (+0000) Subject: fix corner case in `collapse_vars` (#3652) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=2f3930d1b92746be6a3b3e1d371b0ae25e56777e;p=UglifyJS.git fix corner case in `collapse_vars` (#3652) fixes #3651 --- diff --git a/lib/compress.js b/lib/compress.js index 77f5d47c..70dafe99 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3635,7 +3635,7 @@ merge(Compressor.prototype, { return !this.is_declared(compressor); }); def(AST_Try, function(compressor) { - return this.bcatch ? this.bcatch.may_throw(compressor) : any(this.body, compressor) + return (this.bcatch ? this.bcatch.may_throw(compressor) : any(this.body, compressor)) || this.bfinally && this.bfinally.may_throw(compressor); }); def(AST_Unary, function(compressor) { diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index edb5d57f..796fdb3f 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -7422,3 +7422,45 @@ issue_3641: { } expect_stdout: "foo undefined" } + +issue_3651: { + options = { + collapse_vars: true, + toplevel: true, + } + input: { + var a, b = "PASS"; + try { + a = function() { + try { + var c = 1; + while (0 < --c); + } catch (e) {} finally { + throw 42; + } + }(); + b = "FAIL"; + a.p; + } catch (e) { + console.log(b); + } + } + expect: { + var a, b = "PASS"; + try { + a = function() { + try { + var c = 1; + while (0 < --c); + } catch (e) {} finally { + throw 42; + } + }(); + b = "FAIL"; + a.p; + } catch (e) { + console.log(b); + } + } + expect_stdout: "PASS" +}