fix corner case in if_return (#4851)

fixes #4848
This commit is contained in:
Alex Lam S.L
2021-04-08 01:57:59 +01:00
committed by GitHub
parent ebe4e1ad28
commit 8a82822654
5 changed files with 153 additions and 7 deletions

View File

@@ -3054,7 +3054,7 @@ merge(Compressor.prototype, {
});
}
function can_merge_flow(ab) {
function can_drop_abort(ab) {
if (ab instanceof AST_Return) return in_lambda && is_return_void(ab.value);
if (!(ab instanceof AST_LoopControl)) return false;
var lct = compressor.loopcontrol_target(ab);
@@ -3063,16 +3063,35 @@ merge(Compressor.prototype, {
return match_target(lct);
}
function can_merge_flow(ab) {
if (!can_drop_abort(ab)) return false;
for (var j = statements.length; --j > i;) {
var stat = statements[j];
if (stat instanceof AST_DefClass) {
if (stat.name.definition().preinit) return false;
} else if (stat instanceof AST_Const || stat instanceof AST_Let) {
if (!all(stat.definitions, function(defn) {
return !defn.name.match_symbol(function(node) {
return node instanceof AST_SymbolDeclaration && node.definition().preinit;
});
})) return false;
}
}
return true;
}
function extract_functions() {
var defuns = [];
var lexical = false;
var tail = statements.splice(i + 1).filter(function(stat) {
if (stat instanceof AST_LambdaDefinition) {
defuns.push(stat);
return false;
}
if (is_lexical_definition(stat)) lexical = true;
return true;
});
[].push.apply(all(tail, safe_to_trim) ? statements : tail, defuns);
[].push.apply(lexical ? tail : statements, defuns);
return tail;
}