diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-09-15 12:18:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-15 19:18:12 +0800 |
commit | d64d0b0bec426f77e0ca73d2463de3c1a2e71c98 (patch) | |
tree | 278cb0c3bbc16184e4789ddd2e6e7c64a38e4ece | |
parent | 3ac575f2e81630d560b6353831761a7f11037d93 (diff) | |
download | tracifyjs-d64d0b0bec426f77e0ca73d2463de3c1a2e71c98.tar.gz tracifyjs-d64d0b0bec426f77e0ca73d2463de3c1a2e71c98.zip |
fix corner case in `merge_vars` (#4102)
fixes #4101
-rw-r--r-- | lib/compress.js | 11 | ||||
-rw-r--r-- | test/compress/merge_vars.js | 29 |
2 files changed, 40 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index c39c0da6..171746ac 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4403,6 +4403,17 @@ merge(Compressor.prototype, { mark(node); return true; } + if (node instanceof AST_Try) { + var save = segment; + segment = node; + node.body.forEach(function(branch) { + branch.walk(tw); + }); + if (node.bcatch) node.bcatch.walk(tw); + segment = save; + if (node.bfinally) node.bfinally.walk(tw); + return true; + } if (node instanceof AST_Unary) { if (!unary_arithmetic[node.operator]) return; var sym = node.expression; diff --git a/test/compress/merge_vars.js b/test/compress/merge_vars.js index 8ef186cf..076668e5 100644 --- a/test/compress/merge_vars.js +++ b/test/compress/merge_vars.js @@ -182,6 +182,35 @@ switch_branch: { expect_stdout: "PASS" } +try_branch: { + options = { + merge_vars: true, + } + input: { + console.log(function(a) { + var b = "FAIL", c; + try { + a && F(); + } catch (e) { + c = b; + } + return c || "PASS"; + }()); + } + expect: { + console.log(function(a) { + var b = "FAIL", c; + try { + a && F(); + } catch (e) { + c = b; + } + return c || "PASS"; + }()); + } + expect_stdout: "PASS" +} + read_before_assign_1: { options = { inline: true, |