diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-11-01 02:08:31 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-01 02:08:31 +0800 |
commit | 815eff1f7c5c2fca63814f11fbf6e769bc599e38 (patch) | |
tree | 274816aa217047b35ef08163330e77ed8e410a54 /lib/compress.js | |
parent | 1e9b576ee9938d6acb9dff277474e9a32f866690 (diff) | |
download | tracifyjs-815eff1f7c5c2fca63814f11fbf6e769bc599e38.tar.gz tracifyjs-815eff1f7c5c2fca63814f11fbf6e769bc599e38.zip |
enhance `if_return` (#3560)
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/compress.js b/lib/compress.js index 65768c02..0321a532 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1749,9 +1749,7 @@ merge(Compressor.prototype, { if (stat instanceof AST_If) { var ab = aborts(stat.body); if (can_merge_flow(ab)) { - if (ab.label) { - remove(ab.label.thedef.references, ab); - } + if (ab.label) remove(ab.label.thedef.references, ab); CHANGED = true; stat = stat.clone(); stat.condition = stat.condition.negate(compressor); @@ -1779,23 +1777,34 @@ merge(Compressor.prototype, { } } - var ab = aborts(stat.alternative); - if (can_merge_flow(ab)) { - if (ab.label) { - remove(ab.label.thedef.references, ab); - } + var alt = aborts(stat.alternative); + if (can_merge_flow(alt)) { + if (alt.label) remove(alt.label.thedef.references, alt); CHANGED = true; stat = stat.clone(); stat.body = make_node(AST_BlockStatement, stat.body, { body: as_statement_array(stat.body).concat(extract_functions()) }); - var body = as_statement_array_with_return(stat.alternative, ab); + var body = as_statement_array_with_return(stat.alternative, alt); stat.alternative = make_node(AST_BlockStatement, stat.alternative, { body: body }); statements[i] = stat.transform(compressor); continue; } + + if (compressor.option("typeofs")) { + if (ab && !alt) { + mark_locally_defined(stat.condition, null, make_node(AST_BlockStatement, self, { + body: statements.slice(i + 1) + })); + } + if (!ab && alt) { + mark_locally_defined(stat.condition, make_node(AST_BlockStatement, self, { + body: statements.slice(i + 1) + })); + } + } } if (stat instanceof AST_If && stat.body instanceof AST_Return) { @@ -1940,9 +1949,7 @@ merge(Compressor.prototype, { && loop_body(lct) === self || stat instanceof AST_Continue && loop_body(lct) === self) { - if (stat.label) { - remove(stat.label.thedef.references, stat); - } + if (stat.label) remove(stat.label.thedef.references, stat); } else { statements[n++] = stat; } |