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

@@ -214,3 +214,45 @@ dead_code_const_annotation_complex_scope: {
}
expect_stdout: true
}
try_catch_finally: {
options = {
conditionals: true,
dead_code: true,
evaluate: true,
}
input: {
var a = 1;
!function() {
try {
if (false) throw x;
} catch (a) {
var a = 2;
console.log("FAIL");
} finally {
a = 3;
console.log("PASS");
}
}();
try {
console.log(a);
} finally {
}
}
expect: {
var a = 1;
!function() {
var a;
a = 3;
console.log("PASS");
}();
try {
console.log(a);
} finally {
}
}
expect_stdout: [
"PASS",
"1",
]
}