diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-01-29 08:52:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-29 08:52:20 +0800 |
commit | 2ba5f391e008b5d842571094d1140f9ae888ea4d (patch) | |
tree | ffd937e18a4efbda9b771463a3de0d58d2e30ddf /lib | |
parent | 87119e44a08118bf302a4da6ae71e74f8bea4f89 (diff) | |
download | tracifyjs-2ba5f391e008b5d842571094d1140f9ae888ea4d.tar.gz tracifyjs-2ba5f391e008b5d842571094d1140f9ae888ea4d.zip |
enhance `collapse_vars` (#3697)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 9b054ca3..85ad449e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1382,7 +1382,34 @@ merge(Compressor.prototype, { } function is_last_node(node, parent) { - if (node instanceof AST_Call) return true; + if (node instanceof AST_Call) { + var fn = node.expression; + if (fn instanceof AST_SymbolRef) fn = fn.fixed_value(); + if (!(fn instanceof AST_Lambda)) return true; + if (fn.collapse_scanning) return false; + fn.collapse_scanning = true; + var replace = can_replace; + can_replace = false; + var after = stop_after; + var if_hit = stop_if_hit; + var rhs_fn = scan_rhs; + for (var i = 0; !abort && i < fn.body.length; i++) { + var stat = fn.body[i]; + if (stat instanceof AST_Exit) { + if (stat.value) stat.value.transform(scanner); + break; + } + stat.transform(scanner); + } + scan_rhs = rhs_fn; + stop_if_hit = if_hit; + stop_after = after; + can_replace = replace; + delete fn.collapse_scanning; + if (!abort) return false; + abort = false; + return true; + } if (node instanceof AST_Exit) { if (in_try) { if (in_try.bfinally) return true; |