aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-30 12:16:58 +0800
committerGitHub <noreply@github.com>2017-03-30 12:16:58 +0800
commit7bea38a05dbe357434001fe59dbe06bb659a585f (patch)
tree7cc5cd33df52b95b44c31ecbfa49a48af4d0b121 /lib
parent0f910ee25c3e644baf043f217b2fe91df8dc67ac (diff)
downloadtracifyjs-7bea38a05dbe357434001fe59dbe06bb659a585f.tar.gz
tracifyjs-7bea38a05dbe357434001fe59dbe06bb659a585f.zip
optimize try-catch-finally (#1731)
- eliminate empty blocks - flatten out if try-block does not throw
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index e36ff893..be760152 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2606,6 +2606,15 @@ merge(Compressor.prototype, {
OPT(AST_Try, function(self, compressor){
self.body = tighten_body(self.body, compressor);
+ if (self.bcatch && self.bfinally && all(self.bfinally.body, is_empty)) self.bfinally = null;
+ if (all(self.body, is_empty)) {
+ var body = [];
+ if (self.bcatch) extract_declarations_from_unreachable_code(compressor, self.bcatch, body);
+ if (self.bfinally) body = body.concat(self.bfinally.body);
+ return body.length > 0 ? make_node(AST_BlockStatement, self, {
+ body: body
+ }).optimize(compressor) : make_node(AST_EmptyStatement, self);
+ }
return self;
});