patch variable declaractions extracted within catch (#2753)

fixes #2749
This commit is contained in:
Alex Lam S.L
2018-01-09 13:54:35 +08:00
committed by GitHub
parent 2e22d38a02
commit 2972d58dbb
3 changed files with 43 additions and 2 deletions

View File

@@ -3774,9 +3774,20 @@ merge(Compressor.prototype, {
OPT(AST_Try, function(self, compressor){
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)) {
if (compressor.option("dead_code") && all(self.body, is_empty)) {
var body = [];
if (self.bcatch) extract_declarations_from_unreachable_code(compressor, self.bcatch, body);
if (self.bcatch) {
extract_declarations_from_unreachable_code(compressor, self.bcatch, body);
body.forEach(function(stat) {
if (!(stat instanceof AST_Definitions)) return;
stat.definitions.forEach(function(var_def) {
var def = var_def.name.definition().redefined();
if (!def) return;
var_def.name = var_def.name.clone();
var_def.name.thedef = def;
});
});
}
if (self.bfinally) body = body.concat(self.bfinally.body);
return make_node(AST_BlockStatement, self, {
body: body