function join_object_assignments(defn, body) {
if (!(defn instanceof AST_Definitions)) return;
+ var def = defn.definitions[defn.definitions.length - 1];
+ if (!(def.value instanceof AST_Object)) return;
var exprs;
if (body instanceof AST_Assign) {
exprs = [ body ];
exprs = body.expressions.slice();
}
if (!exprs) return;
+ var trimmed = false;
do {
var node = exprs[0];
if (!(node instanceof AST_Assign)) break;
if (!(node.left instanceof AST_PropAccess)) break;
var sym = node.left.expression;
if (!(sym instanceof AST_SymbolRef)) break;
- var def = find_if(function(def) {
- return def.name.name == sym.name
- && def.value instanceof AST_Object;
- }, defn.definitions);
- if (!def) break;
+ if (def.name.name != sym.name) break;
if (!node.right.is_constant_expression(scope)) break;
var prop = node.left.property;
if (prop instanceof AST_Node) {
value: node.right
}));
exprs.shift();
+ trimmed = true;
} while (exprs.length);
- return exprs;
+ return trimmed && exprs;
}
function join_consecutive_vars(statements, compressor) {
} else if (stat instanceof AST_SimpleStatement) {
var exprs = join_object_assignments(prev, stat.body);
if (exprs) {
- if (exprs.length > 0) {
- stat.body = make_sequence(stat.body, exprs);
- statements[++j] = stat;
- }
CHANGED = true;
- } else {
- statements[++j] = stat;
+ if (!exprs.length) continue;
+ stat.body = make_sequence(stat.body, exprs);
}
+ statements[++j] = stat;
} else {
statements[++j] = stat;
}