diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-10-26 05:41:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-26 05:41:02 +0800 |
commit | 85237b08d46c62a97c9b338c4e62d71cdba76e24 (patch) | |
tree | f49863e73bab96aa00bd8ab780929a38be6bf9cf /lib | |
parent | 27b159e711b1f0fc0a3c75672d9db33dfe023d67 (diff) | |
download | tracifyjs-85237b08d46c62a97c9b338c4e62d71cdba76e24.tar.gz tracifyjs-85237b08d46c62a97c9b338c4e62d71cdba76e24.zip |
fix corner case in `collapse_vars` (#3527)
fixes #3526
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index c8eb3487..03c1f590 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1228,6 +1228,7 @@ merge(Compressor.prototype, { var scan_lhs = lhs && !side_effects && !is_lhs_read_only(lhs, compressor); var scan_rhs = foldable(get_rhs(candidate)); if (!scan_lhs && !scan_rhs) continue; + var modify_toplevel = false; // Locate symbols which may execute code outside of scanning range var lvalues = get_lvalues(candidate); var lhs_local = is_lhs_local(lhs); @@ -1580,7 +1581,16 @@ merge(Compressor.prototype, { if (candidate instanceof AST_VarDef) { lvalues[candidate.name.name] = lhs; } + var scan_iife = scope instanceof AST_Toplevel; var tw = new TreeWalker(function(node) { + if (scan_iife && node.TYPE == "Call") { + var exp = node.expression; + if (exp instanceof AST_PropAccess) return; + if (exp instanceof AST_Function && !exp.contains_this()) return; + modify_toplevel = true; + scan_iife = false; + return; + } var value; if (node instanceof AST_SymbolRef) { value = node.fixed_value() || node; @@ -1667,6 +1677,7 @@ merge(Compressor.prototype, { var def = sym.definition(); if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return false; if (def.scope !== scope) return true; + if (modify_toplevel && compressor.exposed(def)) return true; return !all(def.references, function(ref) { return ref.scope.resolve() === scope; }); |