optimize try-catch-finally (#1731)

- eliminate empty blocks
- flatten out if try-block does not throw
This commit is contained in:
Alex Lam S.L
2017-03-30 12:16:58 +08:00
committed by GitHub
parent 0f910ee25c
commit 7bea38a05d
5 changed files with 81 additions and 12 deletions

View File

@@ -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;
});