enhance if_return (#3232)

This commit is contained in:
Alex Lam S.L
2018-08-21 18:34:16 +08:00
committed by GitHub
parent 18c1c9b38a
commit 57fb58b263
2 changed files with 161 additions and 0 deletions

View File

@@ -1699,6 +1699,19 @@ merge(Compressor.prototype, {
continue;
}
if (ab && !stat.alternative && stat.body instanceof AST_BlockStatement && next instanceof AST_Jump) {
var negated = stat.condition.negate(compressor);
if (negated.print_to_string().length <= stat.condition.print_to_string().length) {
CHANGED = true;
stat = stat.clone();
stat.condition = negated;
statements[j] = stat.body;
stat.body = next;
statements[i] = stat.transform(compressor);
continue;
}
}
var ab = aborts(stat.alternative);
if (can_merge_flow(ab)) {
if (ab.label) {