when unsafe, compress undefined as [][0]
This commit is contained in:
Mihai Bazon
2012-09-14 19:04:18 +03:00
parent 5e83e7ec17
commit 50d1670e42

View File

@@ -224,8 +224,8 @@ function Compressor(options, false_by_default) {
&& !statements[last - 1].alternative) {
CHANGED = true;
return MAP.splice([ stat, make_node(AST_Return, stat, {
value: make_node(AST_Undefined, stat)
})]);
value: make_node(AST_Undefined, stat).optimize(compressor)
}).optimize(compressor)]);
}
}
if (stat instanceof AST_If
@@ -439,7 +439,7 @@ function Compressor(options, false_by_default) {
ast = make_node(val ? AST_True : AST_False, this);
break;
case "undefined":
ast = make_node(AST_Undefined, this);
ast = make_node(AST_Undefined, this).optimize(compressor);
break;
default:
if (val === null) {
@@ -1353,7 +1353,25 @@ function Compressor(options, false_by_default) {
AST_SymbolRef.DEFMETHOD("optimize", function(compressor){
if (this.name == "undefined" && this.undeclared()) {
return make_node(AST_Undefined, this);
return make_node(AST_Undefined, this).optimize(compressor);
}
return this;
});
SQUEEZE(AST_Undefined, function(self, compressor){
return self.optimize(compressor);
});
AST_Undefined.DEFMETHOD("optimize", function(compressor){
if (compressor.option("unsafe") && !(compressor.parent() instanceof AST_Array)) {
return make_node(AST_Sub, this, {
expression: make_node(AST_Array, this, {
elements: []
}),
property: make_node(AST_Number, this, {
value: 0
})
});
}
return this;
});