diff options
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) { |