diff options
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/compress.js b/lib/compress.js index 9201d890..f4aa62d4 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -610,6 +610,11 @@ merge(Compressor.prototype, { function is_immutable(value) { if (!value) return false; + if (value instanceof AST_Assign) { + var op = value.operator; + return op == "=" ? is_immutable(value.right) : !lazy_op[op.slice(0, -1)]; + } + if (value instanceof AST_Sequence) return is_immutable(value.tail_node()); return value.is_constant() || is_lambda(value) || value instanceof AST_ObjectIdentity; } @@ -901,6 +906,7 @@ merge(Compressor.prototype, { function walk_assign() { right.walk(tw); + var modified = is_modified(compressor, tw, node, right, 0, is_immutable(right), recursive_ref(tw, d)); scan_declaration(tw, compressor, left, function() { return node.right; }, function(sym, fixed, walk) { @@ -911,10 +917,7 @@ merge(Compressor.prototype, { } var d = sym.definition(); d.assignments++; - if (fixed - && !is_modified(compressor, tw, node, right, 0, is_immutable(right), recursive_ref(tw, d)) - && !sym.in_arg - && safe_to_assign(tw, d)) { + if (fixed && !modified && !sym.in_arg && safe_to_assign(tw, d)) { push_ref(d, sym); mark(tw, d); if (d.single_use && left instanceof AST_Destructured) d.single_use = false; @@ -6299,18 +6302,13 @@ merge(Compressor.prototype, { var drop_sym = is_var ? can_drop_symbol(def.name) : is_safe_lexical(sym); if (!drop_sym || !drop_vars || sym.id in in_use_ids) { if (value && indexOf_assign(sym, def) < 0) { - var write_only = value.write_only; value = value.drop_side_effect_free(compressor); - if (def.value !== value) { - if (value) { - AST_Node.warn("Side effects in last use of variable {name} [{file}:{line},{col}]", template(def.name)); - side_effects.push(value); - } - value = null; - trim_defns.push(def); - } else if (value.write_only !== write_only) { - value.write_only = write_only; + if (value) { + AST_Node.warn("Side effects in last use of variable {name} [{file}:{line},{col}]", template(def.name)); + side_effects.push(value); } + value = null; + trim_defns.push(def); } var old_def; if (!value && !(node instanceof AST_Let)) { |