boolean and if/exit optimizations
This commit is contained in:
@@ -62,6 +62,7 @@ function Compressor(options, false_by_default) {
|
|||||||
conditionals : !false_by_default,
|
conditionals : !false_by_default,
|
||||||
comparations : !false_by_default,
|
comparations : !false_by_default,
|
||||||
evaluate : !false_by_default,
|
evaluate : !false_by_default,
|
||||||
|
booleans : !false_by_default,
|
||||||
|
|
||||||
warnings : true
|
warnings : true
|
||||||
});
|
});
|
||||||
@@ -560,6 +561,17 @@ function Compressor(options, false_by_default) {
|
|||||||
}).optimize(compressor)
|
}).optimize(compressor)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (self.body instanceof AST_Exit
|
||||||
|
&& self.alternative instanceof AST_Exit
|
||||||
|
&& self.body.TYPE == self.alternative.TYPE) {
|
||||||
|
return make_node(self.body.CTOR, self, {
|
||||||
|
value: make_node(AST_Conditional, self, {
|
||||||
|
condition : self.condition,
|
||||||
|
consequent : self.body.value,
|
||||||
|
alternative : self.alternative.value
|
||||||
|
}).optimize(compressor)
|
||||||
|
});
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -709,4 +721,22 @@ function Compressor(options, false_by_default) {
|
|||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
SQUEEZE(AST_True, function(self, compressor){
|
||||||
|
if (compressor.option("booleans")) return make_node(AST_UnaryPrefix, self, {
|
||||||
|
operator: "!",
|
||||||
|
expression: make_node(AST_Number, self, {
|
||||||
|
value: 0
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
SQUEEZE(AST_False, function(self, compressor){
|
||||||
|
if (compressor.option("booleans")) return make_node(AST_UnaryPrefix, self, {
|
||||||
|
operator: "!",
|
||||||
|
expression: make_node(AST_Number, self, {
|
||||||
|
value: 1
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user