diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-12-14 04:38:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-14 04:38:21 +0800 |
commit | 8266993c6e0a78c4872cbcb81072094a4a7dba2d (patch) | |
tree | 4bd8d1e6fc25a50256c4d66810e5dbfd164262ac /lib/compress.js | |
parent | 9a137e8613e49066a54f2a1b734a559c05338f11 (diff) | |
download | tracifyjs-8266993c6e0a78c4872cbcb81072094a4a7dba2d.tar.gz tracifyjs-8266993c6e0a78c4872cbcb81072094a4a7dba2d.zip |
fix `dead_code` on `return`/`throw` within `try` (#2588)
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index 559fb51a..e394e8b2 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4674,6 +4674,11 @@ merge(Compressor.prototype, { node = parent; parent = compressor.parent(level++); if (parent instanceof AST_Exit) { + var try_node = find_try(level); + if (try_node) { + if (try_node.bfinally) break; + if (parent instanceof AST_Throw && try_node.bcatch) break; + } if (self.operator == "=") return self.right; return make_node(AST_Binary, self, { operator: self.operator.slice(0, -1), @@ -4704,6 +4709,14 @@ merge(Compressor.prototype, { } } return self; + + function find_try(level) { + var scope = self.left.definition().scope; + var parent; + while ((parent = compressor.parent(level++)) !== scope) { + if (parent instanceof AST_Try) return parent; + } + } }); OPT(AST_Conditional, function(self, compressor){ |