aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js44
1 files changed, 14 insertions, 30 deletions
diff --git a/lib/compress.js b/lib/compress.js
index b51fdfc7..f49f0b24 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -800,14 +800,6 @@ merge(Compressor.prototype, {
|| compressor.option("unsafe") && global_names(this.name);
});
- function drop_decl(def) {
- def.eliminated++;
- if (def.orig.length == def.eliminated) {
- def.scope.functions.del(def.name);
- def.scope.variables.del(def.name);
- }
- }
-
function is_identifier_atom(node) {
return node instanceof AST_Infinity
|| node instanceof AST_NaN
@@ -1138,7 +1130,6 @@ merge(Compressor.prototype, {
if (node === expr || node.body === expr) {
found = true;
if (node instanceof AST_VarDef) {
- drop_decl(node.name.definition());
node.value = null;
return node;
}
@@ -2484,7 +2475,7 @@ merge(Compressor.prototype, {
var def = node.name.definition();
if (!(def.id in in_use_ids)) {
compressor[node.name.unreferenced() ? "warn" : "info"]("Dropping unused function {name} [{file}:{line},{col}]", template(node.name));
- drop_decl(def);
+ def.eliminated++;
return make_node(AST_EmptyStatement, node);
}
return node;
@@ -2503,10 +2494,17 @@ merge(Compressor.prototype, {
if (!drop_vars || sym.id in in_use_ids) {
if (def.name instanceof AST_SymbolVar) {
var var_defs = var_defs_by_id.get(sym.id);
- if (var_defs.length > 1 && !def.value) {
+ if (var_defs.length > 1 && (!def.value || sym.orig.indexOf(def.name) > sym.eliminated)) {
compressor.warn("Dropping duplicated definition of variable {name} [{file}:{line},{col}]", template(def.name));
+ if (def.value) {
+ merge_sequence(side_effects, make_node(AST_Assign, def, {
+ operator: "=",
+ left: make_node(AST_SymbolRef, def.name, def.name),
+ right: def.value
+ }));
+ }
remove(var_defs, def);
- drop_decl(sym);
+ sym.eliminated++;
return;
}
}
@@ -2539,25 +2537,9 @@ merge(Compressor.prototype, {
} else {
compressor[def.name.unreferenced() ? "warn" : "info"]("Dropping unused variable {name} [{file}:{line},{col}]", template(def.name));
}
- drop_decl(sym);
+ sym.eliminated++;
}
});
- if (head.length == 0 && tail.length == 1 && tail[0].name instanceof AST_SymbolVar) {
- var var_defs = var_defs_by_id.get(tail[0].name.definition().id);
- if (var_defs.length > 1) {
- var def = tail.pop();
- compressor.warn("Converting duplicated definition of variable {name} to assignment [{file}:{line},{col}]", template(def.name));
- remove(var_defs, def);
- side_effects.unshift(make_node(AST_Assign, def, {
- operator: "=",
- left: make_node(AST_SymbolRef, def.name, def.name),
- right: def.value
- }));
- def = def.name.definition();
- drop_decl(def);
- def.replaced--;
- }
- }
if (head.length > 0 || tail.length > 0) {
node.definitions = head.concat(tail);
body.push(node);
@@ -3385,7 +3367,9 @@ merge(Compressor.prototype, {
}));
if (reduce_vars) name.definition().fixed = false;
}
- drop_decl(def.name.definition());
+ def = def.name.definition();
+ def.eliminated++;
+ def.replaced--;
return a;
}, []);
if (assignments.length == 0) return null;