diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-12-13 18:20:53 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-13 18:20:53 +0800 |
commit | 7f418978c9d39bd0827108176d817259a6e60f5c (patch) | |
tree | b88feba47b9b2303ac0f5ff751a2838e442b4ba6 /lib | |
parent | 04cc395c353ac622d8e737c9099387d69b851d64 (diff) | |
download | tracifyjs-7f418978c9d39bd0827108176d817259a6e60f5c.tar.gz tracifyjs-7f418978c9d39bd0827108176d817259a6e60f5c.zip |
recover lost opportunities from #2574 (#2584)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 6aee9497..004858ac 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -863,6 +863,7 @@ merge(Compressor.prototype, { if (scope.uses_eval || scope.uses_with) return statements; var args; var candidates = []; + var in_try = compressor.self() instanceof AST_Try; var stat_index = statements.length; var scanner = new TreeTransformer(function(node, descend) { if (abort) return node; @@ -956,7 +957,8 @@ merge(Compressor.prototype, { || side_effects && !references_in_scope(node.definition())) || (sym = lhs_or_def(node)) && (sym instanceof AST_PropAccess || sym.name in lvalues) - || may_throw && node.has_side_effects(compressor) + || may_throw + && (in_try ? node.has_side_effects(compressor) : side_effects_external(node)) || (side_effects || !replace_all) && (parent instanceof AST_Binary && lazy_op(parent.operator) || parent instanceof AST_Conditional @@ -1192,6 +1194,25 @@ merge(Compressor.prototype, { return ref.scope === scope; }); } + + function side_effects_external(node, lhs) { + if (node instanceof AST_Assign) { + return side_effects_external(node.left, true) + || side_effects_external(node.right); + } + if (node instanceof AST_Definitions) return false; + if (node instanceof AST_Unary) return side_effects_external(node.expression, true); + if (node instanceof AST_VarDef) return node.value && side_effects_external(node.value); + if (lhs) { + if (node instanceof AST_Dot) return side_effects_external(node.expression, true); + if (node instanceof AST_Sub) { + return side_effects_external(node.expression, true) + || side_effects_external(node.property); + } + if (node instanceof AST_SymbolRef) return node.definition().scope !== scope; + } + return node.has_side_effects(compressor); + } } function eliminate_spurious_blocks(statements) { |