minor
when unsafe, compress undefined as [][0]
This commit is contained in:
@@ -224,8 +224,8 @@ function Compressor(options, false_by_default) {
|
|||||||
&& !statements[last - 1].alternative) {
|
&& !statements[last - 1].alternative) {
|
||||||
CHANGED = true;
|
CHANGED = true;
|
||||||
return MAP.splice([ stat, make_node(AST_Return, stat, {
|
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
|
if (stat instanceof AST_If
|
||||||
@@ -439,7 +439,7 @@ function Compressor(options, false_by_default) {
|
|||||||
ast = make_node(val ? AST_True : AST_False, this);
|
ast = make_node(val ? AST_True : AST_False, this);
|
||||||
break;
|
break;
|
||||||
case "undefined":
|
case "undefined":
|
||||||
ast = make_node(AST_Undefined, this);
|
ast = make_node(AST_Undefined, this).optimize(compressor);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (val === null) {
|
if (val === null) {
|
||||||
@@ -1353,7 +1353,25 @@ function Compressor(options, false_by_default) {
|
|||||||
|
|
||||||
AST_SymbolRef.DEFMETHOD("optimize", function(compressor){
|
AST_SymbolRef.DEFMETHOD("optimize", function(compressor){
|
||||||
if (this.name == "undefined" && this.undeclared()) {
|
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;
|
return this;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user