@@ -4222,16 +4222,25 @@ Compressor.prototype.compress = function(node) {
|
||||
if (value.left instanceof AST_SymbolRef) names.set(value.left.name, true);
|
||||
value = value.right;
|
||||
}
|
||||
if (!(value instanceof AST_Object)) return;
|
||||
var trimmed = false;
|
||||
do {
|
||||
if (!try_join(exprs[0])) break;
|
||||
exprs.shift();
|
||||
trimmed = true;
|
||||
} while (exprs.length);
|
||||
return trimmed;
|
||||
if (value instanceof AST_Array) {
|
||||
var trimmed = false;
|
||||
do {
|
||||
if (!try_join_array(exprs[0])) break;
|
||||
exprs.shift();
|
||||
trimmed = true;
|
||||
} while (exprs.length);
|
||||
return trimmed;
|
||||
} else if (value instanceof AST_Object) {
|
||||
var trimmed = false;
|
||||
do {
|
||||
if (!try_join_object(exprs[0])) break;
|
||||
exprs.shift();
|
||||
trimmed = true;
|
||||
} while (exprs.length);
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
function try_join(node) {
|
||||
function try_join_array(node) {
|
||||
if (!(node instanceof AST_Assign)) return;
|
||||
if (node.operator != "=") return;
|
||||
if (!(node.left instanceof AST_PropAccess)) return;
|
||||
@@ -4241,7 +4250,30 @@ Compressor.prototype.compress = function(node) {
|
||||
if (!node.right.is_constant_expression(scope)) return;
|
||||
var prop = node.left.property;
|
||||
if (prop instanceof AST_Node) {
|
||||
if (try_join(prop)) prop = node.left.property = prop.right.clone();
|
||||
if (try_join_array(prop)) prop = node.left.property = prop.right.clone();
|
||||
prop = prop.evaluate(compressor);
|
||||
}
|
||||
if (prop instanceof AST_Node) return;
|
||||
if (!RE_POSITIVE_INTEGER.test("" + prop)) return;
|
||||
prop = +prop;
|
||||
var len = value.elements.length;
|
||||
if (prop > len + 4) return;
|
||||
while (len < prop) value.elements[len++] = make_node(AST_Hole, value);
|
||||
value.elements[prop] = node.right;
|
||||
return true;
|
||||
}
|
||||
|
||||
function try_join_object(node) {
|
||||
if (!(node instanceof AST_Assign)) return;
|
||||
if (node.operator != "=") return;
|
||||
if (!(node.left instanceof AST_PropAccess)) return;
|
||||
var sym = node.left.expression;
|
||||
if (!(sym instanceof AST_SymbolRef)) return;
|
||||
if (!names.has(sym.name)) return;
|
||||
if (!node.right.is_constant_expression(scope)) return;
|
||||
var prop = node.left.property;
|
||||
if (prop instanceof AST_Node) {
|
||||
if (try_join_object(prop)) prop = node.left.property = prop.right.clone();
|
||||
prop = prop.evaluate(compressor);
|
||||
}
|
||||
if (prop instanceof AST_Node) return;
|
||||
|
||||
Reference in New Issue
Block a user