});
});
+ function safe_to_flatten(value, compressor) {
+ if (value instanceof AST_SymbolRef) {
+ value = value.fixed_value();
+ }
+ if (!value) return false;
+ return !(value instanceof AST_Lambda)
+ || compressor.parent() instanceof AST_New
+ || !value.contains_this();
+ }
+
OPT(AST_Sub, function(self, compressor) {
var expr = self.expression;
var prop = self.property;
&& prop instanceof AST_Number && expr instanceof AST_Array) {
var index = prop.getValue();
var elements = expr.elements;
- if (index in elements) {
+ var retValue = elements[index];
+ if (safe_to_flatten(retValue, compressor)) {
var flatten = true;
var values = [];
for (var i = elements.length; --i > index;) {
if (flatten && value.has_side_effects(compressor)) flatten = false;
}
}
- var retValue = elements[index];
retValue = retValue instanceof AST_Hole ? make_node(AST_Undefined, retValue) : retValue;
if (!flatten) values.unshift(retValue);
while (--i >= 0) {
if (!all(props, function(prop) {
return prop instanceof AST_ObjectKeyVal;
})) break;
- var value = prop.value;
- if (value instanceof AST_Function
- && !(compressor.parent() instanceof AST_New)
- && value.contains_this()) break;
+ if (!safe_to_flatten(prop.value, compressor)) break;
return make_node(AST_Sub, this, {
expression: make_node(AST_Array, expr, {
elements: props.map(function(prop) {