enhance join_vars (#3783)
This commit is contained in:
@@ -2338,10 +2338,7 @@ merge(Compressor.prototype, {
|
||||
exprs = body.expressions.slice();
|
||||
}
|
||||
if (!exprs) return;
|
||||
if (defn instanceof AST_Definitions) {
|
||||
var def = defn.definitions[defn.definitions.length - 1];
|
||||
if (trim_assigns(def.name, def.value, exprs)) return exprs;
|
||||
}
|
||||
var trimmed = false;
|
||||
for (var i = exprs.length - 1; --i >= 0;) {
|
||||
var expr = exprs[i];
|
||||
if (!(expr instanceof AST_Assign)) continue;
|
||||
@@ -2349,8 +2346,38 @@ merge(Compressor.prototype, {
|
||||
if (!(expr.left instanceof AST_SymbolRef)) continue;
|
||||
var tail = exprs.slice(i + 1);
|
||||
if (!trim_assigns(expr.left, expr.right, tail)) continue;
|
||||
return exprs.slice(0, i + 1).concat(tail);
|
||||
trimmed = true;
|
||||
exprs = exprs.slice(0, i + 1).concat(tail);
|
||||
}
|
||||
if (defn instanceof AST_Definitions) {
|
||||
var def = defn.definitions[defn.definitions.length - 1];
|
||||
if (trim_assigns(def.name, def.value, exprs)) trimmed = true;
|
||||
if (join_var_assign(defn.definitions, exprs)) trimmed = true;
|
||||
}
|
||||
return trimmed && exprs;
|
||||
}
|
||||
|
||||
function join_var_assign(definitions, exprs) {
|
||||
var trimmed = false;
|
||||
while (exprs.length) {
|
||||
var expr = exprs[0];
|
||||
if (!(expr instanceof AST_Assign)) break;
|
||||
if (expr.operator != "=") break;
|
||||
var lhs = expr.left;
|
||||
if (!(lhs instanceof AST_SymbolRef)) break;
|
||||
var def = lhs.definition();
|
||||
if (def.scope !== scope) break;
|
||||
var name = make_node(AST_SymbolVar, lhs, lhs);
|
||||
definitions.push(make_node(AST_VarDef, expr, {
|
||||
name: name,
|
||||
value: expr.right
|
||||
}));
|
||||
def.orig.push(name);
|
||||
def.replaced++;
|
||||
exprs.shift();
|
||||
trimmed = true;
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
function trim_assigns(name, value, exprs) {
|
||||
|
||||
Reference in New Issue
Block a user