aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js45
1 files changed, 27 insertions, 18 deletions
diff --git a/lib/compress.js b/lib/compress.js
index d6f6a710..3aa9f0bc 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4134,6 +4134,7 @@ merge(Compressor.prototype, {
// side effects, we can cascade the init. code
// into the next one, or next statement.
var side_effects = [];
+ var duplicated = 0;
node.definitions.forEach(function(def) {
if (def.value) def.value = def.value.transform(tt);
var sym = def.name.definition();
@@ -4142,24 +4143,17 @@ merge(Compressor.prototype, {
def.value = def.value.drop_side_effect_free(compressor);
}
var var_defs = var_defs_by_id.get(sym.id);
- if (var_defs.length > 1 && (!def.value || sym.orig.indexOf(def.name) > sym.eliminated)) {
- AST_Node.warn("Dropping duplicated definition of variable {name} [{file}:{line},{col}]", template(def.name));
- if (def.value) {
- var ref = make_node(AST_SymbolRef, def.name, def.name);
- sym.references.push(ref);
- var assign = make_node(AST_Assign, def, {
- operator: "=",
- left: ref,
- right: def.value
- });
- if (fixed_ids[sym.id] === def) {
- fixed_ids[sym.id] = assign;
- }
- side_effects.push(assign.transform(tt));
+ if (var_defs.length > 1) {
+ if (!def.value) {
+ AST_Node.warn("Dropping duplicated declaration of variable {name} [{file}:{line},{col}]", template(def.name));
+ remove(var_defs, def);
+ sym.eliminated++;
+ return;
+ }
+ if (sym.orig.indexOf(def.name) > sym.eliminated) {
+ remove(var_defs, def);
+ duplicated++;
}
- remove(var_defs, def);
- sym.eliminated++;
- return;
}
if (!def.value) {
head.push(def);
@@ -4220,7 +4214,22 @@ merge(Compressor.prototype, {
return !def || fn.name && def === fn.name.definition();
}
});
- if (head.length > 0 || tail.length > 0) {
+ if (head.length == 0 && tail.length == duplicated) {
+ [].unshift.apply(side_effects, tail.map(function(def) {
+ AST_Node.warn("Dropping duplicated definition of variable {name} [{file}:{line},{col}]", template(def.name));
+ var sym = def.name.definition();
+ var ref = make_node(AST_SymbolRef, def.name, def.name);
+ sym.references.push(ref);
+ var assign = make_node(AST_Assign, def, {
+ operator: "=",
+ left: ref,
+ right: def.value
+ });
+ if (fixed_ids[sym.id] === def) fixed_ids[sym.id] = assign;
+ sym.eliminated++;
+ return assign.transform(tt);
+ }));
+ } else if (head.length > 0 || tail.length > 0) {
node.definitions = head.concat(tail);
body.push(node);
}