aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress/collapse_vars.js4
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 872e2bbf..9504241b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1264,6 +1264,7 @@ merge(Compressor.prototype, {
if (stat_index == 0 && compressor.option("unused")) extract_args();
// Find collapsible assignments
var hit_stack = [];
+ var declare_only = Object.create(null);
extract_candidates(statements[stat_index]);
while (candidates.length > 0) {
hit_stack = candidates.pop();
@@ -1574,6 +1575,8 @@ merge(Compressor.prototype, {
candidates.push(hit_stack.slice());
}
extract_candidates(expr.value);
+ } else {
+ declare_only[expr.name.name] = (declare_only[expr.name.name] || 0) + 1;
}
}
hit_stack.pop();
@@ -1739,6 +1742,7 @@ merge(Compressor.prototype, {
if (!member(expr.name, def.orig)) return;
var referenced = def.references.length - def.replaced;
var declared = def.orig.length - def.eliminated;
+ declared -= declare_only[def.name] || 0;
if (declared > 1 && !(expr.name instanceof AST_SymbolFunarg)) {
mangleable_var(expr.value);
return make_node(AST_SymbolRef, expr.name, expr.name);
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 17d9c981..ac87d788 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -2205,8 +2205,8 @@ var_defs: {
}
expect: {
var f1 = function(x, y) {
- var r = x + y, z = r * r - r, b = 7;
- console.log(z + b);
+ var r = x + y, a = r * r - r, b = 7;
+ console.log(a + b);
};
f1("1", 0);
}