more smallish optimizations
This commit is contained in:
@@ -1321,9 +1321,10 @@ function Compressor(options, false_by_default) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
AST_UnaryPrefix.DEFMETHOD("optimize", function(compressor){
|
AST_UnaryPrefix.DEFMETHOD("optimize", function(compressor){
|
||||||
|
var self = this;
|
||||||
|
var e = self.expression;
|
||||||
if (compressor.option("booleans") && compressor.in_boolean_context()) {
|
if (compressor.option("booleans") && compressor.in_boolean_context()) {
|
||||||
var e = this.expression;
|
switch (self.operator) {
|
||||||
switch (this.operator) {
|
|
||||||
case "!":
|
case "!":
|
||||||
if (e instanceof AST_UnaryPrefix && e.operator == "!") {
|
if (e instanceof AST_UnaryPrefix && e.operator == "!") {
|
||||||
// !!foo ==> foo, if we're in boolean context
|
// !!foo ==> foo, if we're in boolean context
|
||||||
@@ -1333,11 +1334,14 @@ function Compressor(options, false_by_default) {
|
|||||||
case "typeof":
|
case "typeof":
|
||||||
// typeof always returns a non-empty string, thus it's
|
// typeof always returns a non-empty string, thus it's
|
||||||
// always true in booleans
|
// always true in booleans
|
||||||
compressor.warn("Boolean expression always true [{line},{col}]", this.start);
|
compressor.warn("Boolean expression always true [{line},{col}]", self.start);
|
||||||
return make_node(AST_True, this).optimize(compressor);
|
return make_node(AST_True, self).optimize(compressor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.evaluate(compressor)[0];
|
if (e instanceof AST_Binary) {
|
||||||
|
self = best_of(self, e.negate(compressor));
|
||||||
|
}
|
||||||
|
return self.evaluate(compressor)[0];
|
||||||
});
|
});
|
||||||
|
|
||||||
SQUEEZE(AST_Binary, function(self, compressor){
|
SQUEEZE(AST_Binary, function(self, compressor){
|
||||||
@@ -1531,6 +1535,11 @@ function Compressor(options, false_by_default) {
|
|||||||
AST_Conditional.DEFMETHOD("optimize", function(compressor){
|
AST_Conditional.DEFMETHOD("optimize", function(compressor){
|
||||||
var self = this;
|
var self = this;
|
||||||
if (!compressor.option("conditionals")) return self;
|
if (!compressor.option("conditionals")) return self;
|
||||||
|
if (self.condition instanceof AST_Seq) {
|
||||||
|
var car = self.condition.car;
|
||||||
|
self.condition = self.condition.cdr;
|
||||||
|
return AST_Seq.cons(car, self.optimize(compressor)).optimize(compressor);
|
||||||
|
}
|
||||||
var cond = self.condition.evaluate(compressor);
|
var cond = self.condition.evaluate(compressor);
|
||||||
if (cond.length == 2) {
|
if (cond.length == 2) {
|
||||||
if (cond[1]) {
|
if (cond[1]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user