avoid emitting try-block with no catch- & finally-blocks
This commit is contained in:
parent
2a2c6badd7
commit
ff0c1116b6
|
|
@ -2606,15 +2606,14 @@ merge(Compressor.prototype, {
|
|||
|
||||
OPT(AST_Try, function(self, compressor){
|
||||
self.body = tighten_body(self.body, compressor);
|
||||
if (self.bcatch && all(self.bcatch.body, is_empty)) self.bcatch = null;
|
||||
if (self.bfinally && all(self.bfinally.body, is_empty)) self.bfinally = null;
|
||||
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
|
||||
}) : make_node(AST_EmptyStatement, self);
|
||||
}).optimize(compressor) : make_node(AST_EmptyStatement, self);
|
||||
}
|
||||
return self;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -234,7 +234,10 @@ try_catch_finally: {
|
|||
console.log("PASS");
|
||||
}
|
||||
}();
|
||||
console.log(a);
|
||||
try {
|
||||
console.log(a);
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
var a = 1;
|
||||
|
|
@ -243,7 +246,10 @@ try_catch_finally: {
|
|||
a = 3;
|
||||
console.log("PASS");
|
||||
}();
|
||||
console.log(a);
|
||||
try {
|
||||
console.log(a);
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ side_effects_finally: {
|
|||
function f() {
|
||||
function g() {
|
||||
try {
|
||||
if (f);
|
||||
x();
|
||||
} catch (e) {
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
|
|
@ -84,7 +84,8 @@ side_effects_finally: {
|
|||
function f() {
|
||||
(function() {
|
||||
try {
|
||||
if (f);
|
||||
x();
|
||||
} catch (e) {
|
||||
} finally {
|
||||
console.log("PASS");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user