From: Alex Lam S.L Date: Mon, 17 Apr 2017 06:03:29 +0000 (+0800) Subject: fix `reduce_vars` within try-block (#1818) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=71a8d0d236d29015df2d1df18de11d661d17af2e;p=UglifyJS.git fix `reduce_vars` within try-block (#1818) Possible partial execution due to exceptions. --- diff --git a/lib/compress.js b/lib/compress.js index 640fcecc..cc42c46e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -382,7 +382,19 @@ merge(Compressor.prototype, { pop(); return true; } - if (node instanceof AST_Catch || node instanceof AST_SwitchBranch) { + if (node instanceof AST_Try) { + push(); + walk_body(node, tw); + pop(); + if (node.bcatch) { + push(); + node.bcatch.walk(tw); + pop(); + } + if (node.bfinally) node.bfinally.walk(tw); + return true; + } + if (node instanceof AST_SwitchBranch) { push(); descend(); pop(); diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 6e079c1a..405dbc23 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -2187,3 +2187,34 @@ issue_1814_2: { } expect_stdout: "0 '321'" } + +try_abort: { + options = { + evaluate: true, + reduce_vars: true, + unused: true, + } + input: { + !function() { + try { + var a = 1; + throw ""; + var b = 2; + } catch (e) { + } + console.log(a, b); + }(); + } + expect: { + !function() { + try { + var a = 1; + throw ""; + var b = 2; + } catch (e) { + } + console.log(a, b); + }(); + } + expect_stdout: "1 undefined" +}