diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-02-09 04:36:12 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 12:36:12 +0800 |
commit | fcee32527bd251febeb7b45251d33756fcee207e (patch) | |
tree | d1ee8ee66461e913e382e3db82988a38d0033eb4 | |
parent | e13d1e996909f68ee643df17fd7d87773c3e82a5 (diff) | |
download | tracifyjs-fcee32527bd251febeb7b45251d33756fcee207e.tar.gz tracifyjs-fcee32527bd251febeb7b45251d33756fcee207e.zip |
fix corner case in `merge_vars` (#4629)
fixes #4628
-rw-r--r-- | lib/compress.js | 9 | ||||
-rw-r--r-- | test/compress/merge_vars.js | 29 |
2 files changed, 36 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index 1d8c71c7..c822a8e7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5276,8 +5276,13 @@ merge(Compressor.prototype, { return true; } if (node instanceof AST_VarDef) { - if (node.value) node.value.walk(tw); - node.name.mark_symbol(node.value ? function(node) { + var assigned = node.value; + if (assigned) { + assigned.walk(tw); + } else { + assigned = segment.block instanceof AST_ForEnumeration && segment.block.init === tw.parent(); + } + node.name.mark_symbol(assigned ? function(node) { if (!(node instanceof AST_SymbolDeclaration)) return; if (node instanceof AST_SymbolVar) { mark(node); diff --git a/test/compress/merge_vars.js b/test/compress/merge_vars.js index 1212be93..02d17d31 100644 --- a/test/compress/merge_vars.js +++ b/test/compress/merge_vars.js @@ -3183,3 +3183,32 @@ issue_4257: { "1", ] } + +issue_4628: { + options = { + merge_vars: true, + } + input: { + (function() { + try { + console; + } finally { + var b = a; + } + for (var a in "foo"); + console.log(b); + })(); + } + expect: { + (function() { + try { + console; + } finally { + var b = a; + } + for (var a in "foo"); + console.log(b); + })(); + } + expect_stdout: "undefined" +} |