aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-02-01 20:06:36 +0800
committerGitHub <noreply@github.com>2018-02-01 20:06:36 +0800
commit525a61fb559227d9ea76663f2d9b4573b4cf7475 (patch)
treeb9441f92ee98d2b67416a3b0a0473b27a1688e6a /lib/compress.js
parentc3a002ff9739b60ec1836719c1e240df22a67830 (diff)
downloadtracifyjs-525a61fb559227d9ea76663f2d9b4573b4cf7475.tar.gz
tracifyjs-525a61fb559227d9ea76663f2d9b4573b4cf7475.zip
better fix for #2858 (#2864)
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js24
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 1b0aa15a..312ce728 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -990,7 +990,6 @@ merge(Compressor.prototype, {
|| node instanceof AST_Debugger
|| node instanceof AST_IterationStatement && !(node instanceof AST_For)
|| node instanceof AST_Try
- || node instanceof AST_VarDef && node.value && side_effects && !references_in_scope(node.name.definition())
|| node instanceof AST_With
|| parent instanceof AST_For && node !== parent.init
|| (side_effects || !replace_all)
@@ -1048,9 +1047,11 @@ merge(Compressor.prototype, {
|| node instanceof AST_PropAccess
&& (side_effects || node.expression.may_throw_on_access(compressor))
|| node instanceof AST_SymbolRef
- && (lvalues[node.name]
- || side_effects && !references_in_scope(node.definition()))
- || (sym = lhs_or_def(node))
+ && !(parent instanceof AST_Assign && parent.operator == "=" && parent.left === node)
+ && (lvalues[node.name] || may_modify(node))
+ || node instanceof AST_VarDef && node.value
+ && (node.name.name in lvalues || may_modify(node.name))
+ || (sym = is_lhs(node.left, node))
&& (sym instanceof AST_PropAccess || sym.name in lvalues)
|| may_throw
&& (in_try ? node.has_side_effects(compressor) : side_effects_external(node))
@@ -1321,11 +1322,6 @@ merge(Compressor.prototype, {
return lvalues;
}
- function lhs_or_def(node) {
- if (node instanceof AST_VarDef) return node.value && node.name;
- return is_lhs(node.left, node);
- }
-
function remove_candidate(expr) {
if (expr.name instanceof AST_SymbolFunarg) {
var index = compressor.self().argnames.indexOf(expr.name);
@@ -1359,10 +1355,12 @@ merge(Compressor.prototype, {
return get_rvalue(expr).has_side_effects(compressor);
}
- function references_in_scope(def) {
- if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return true;
- if (def.scope !== scope) return false;
- return def.references.every(function(ref) {
+ function may_modify(sym) {
+ if (!side_effects) return false;
+ var def = sym.definition();
+ if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return false;
+ if (def.scope !== scope) return true;
+ return !all(def.references, function(ref) {
return ref.scope === scope;
});
}