diff options
author | Mihai Bazon <mihai.bazon@gmail.com> | 2015-07-20 09:58:01 +0300 |
---|---|---|
committer | Mihai Bazon <mihai.bazon@gmail.com> | 2015-07-20 09:58:01 +0300 |
commit | 63fb2d5a44db3d583b1927c8daa244bf9f4d8dd2 (patch) | |
tree | cebb024e71b8c41002ee6014eaee9f6fefd49831 /lib/compress.js | |
parent | 85a5fc0aeb1785982506c09a484e12608ba01624 (diff) | |
parent | 9d398d999c67f6d2e74a5b07d5ce8d265391a698 (diff) | |
download | tracifyjs-63fb2d5a44db3d583b1927c8daa244bf9f4d8dd2.tar.gz tracifyjs-63fb2d5a44db3d583b1927c8daa244bf9f4d8dd2.zip |
Merge pull request #735 from kzc/master
optimizations for && and || where left side is constant expression
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index 091ad9e5..54873f0d 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]; + } + } + } + else 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); |