fix cascade & collapse on property access of constants (#2158)
This commit is contained in:
@@ -547,8 +547,25 @@ merge(Compressor.prototype, {
|
||||
return fixed();
|
||||
});
|
||||
|
||||
AST_SymbolRef.DEFMETHOD("is_immutable", function() {
|
||||
var orig = this.definition().orig;
|
||||
return orig.length == 1 && orig[0] instanceof AST_SymbolLambda;
|
||||
});
|
||||
|
||||
function is_lhs_read_only(lhs) {
|
||||
return lhs instanceof AST_SymbolRef && lhs.definition().orig[0] instanceof AST_SymbolLambda;
|
||||
if (lhs instanceof AST_SymbolRef) return lhs.definition().orig[0] instanceof AST_SymbolLambda;
|
||||
if (lhs instanceof AST_PropAccess) {
|
||||
lhs = lhs.expression;
|
||||
if (lhs instanceof AST_SymbolRef) {
|
||||
if (lhs.is_immutable()) return false;
|
||||
lhs = lhs.fixed_value();
|
||||
}
|
||||
if (!lhs) return true;
|
||||
if (lhs instanceof AST_RegExp) return false;
|
||||
if (lhs instanceof AST_Constant) return true;
|
||||
return is_lhs_read_only(lhs);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function find_variable(compressor, name) {
|
||||
@@ -1287,6 +1304,7 @@ merge(Compressor.prototype, {
|
||||
def(AST_SymbolRef, function(pure_getters) {
|
||||
if (this.is_undefined) return true;
|
||||
if (!is_strict(pure_getters)) return false;
|
||||
if (this.is_immutable()) return false;
|
||||
var fixed = this.fixed_value();
|
||||
return !fixed || fixed._throw_on_access(pure_getters);
|
||||
});
|
||||
@@ -3359,6 +3377,8 @@ merge(Compressor.prototype, {
|
||||
|| cdr instanceof AST_PropAccess
|
||||
|| cdr instanceof AST_Unary && !unary_side_effects(cdr.operator)) {
|
||||
field = "expression";
|
||||
} else if (cdr instanceof AST_Conditional) {
|
||||
field = "condition";
|
||||
} else {
|
||||
expressions[++i] = expressions[j];
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user