aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorkzc <zaxxon2011@gmail.com>2015-06-11 23:22:38 -0400
committerkzc <zaxxon2011@gmail.com>2015-06-11 23:22:38 -0400
commitfedb6191a11c2d868c23362e10f23795aae3ca3e (patch)
tree39b53e597d10975367e051bdf5bbfccd620c800c /lib/compress.js
parent5bf617ebde8edd0720477944f84f69c9adec078e (diff)
downloadtracifyjs-fedb6191a11c2d868c23362e10f23795aae3ca3e.tar.gz
tracifyjs-fedb6191a11c2d868c23362e10f23795aae3ca3e.zip
optimizations for && and || where left side is constant expression
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 530e7c2f..34233143 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2104,6 +2104,34 @@ merge(Compressor.prototype, {
}
break;
}
+ if (compressor.option("conditionals")) {
+ if (self.operator == "&&") {
+ var ll = self.left.evaluate(compressor);
+ var rr = self.right.evaluate(compressor);
+ if (ll.length > 1) {
+ if (ll[1]) {
+ compressor.warn("Condition left of && always true [{file}:{line},{col}]", self.start);
+ return rr[0];
+ } else {
+ compressor.warn("Condition left of && always false [{file}:{line},{col}]", self.start);
+ return ll[0];
+ }
+ }
+ }
+ if (self.operator == "||") {
+ var ll = self.left.evaluate(compressor);
+ var rr = self.right.evaluate(compressor);
+ if (ll.length > 1) {
+ if (ll[1]) {
+ compressor.warn("Condition left of || always true [{file}:{line},{col}]", self.start);
+ return ll[0];
+ } else {
+ compressor.warn("Condition left of || always false [{file}:{line},{col}]", self.start);
+ return rr[0];
+ }
+ }
+ }
+ }
if (compressor.option("booleans") && compressor.in_boolean_context()) switch (self.operator) {
case "&&":
var ll = self.left.evaluate(compressor);