aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorRichard van Velzen <rvanvelzen1@gmail.com>2015-02-11 21:05:49 +0100
committerRichard van Velzen <rvanvelzen1@gmail.com>2015-02-11 21:08:41 +0100
commit992b6b9fcce47ca67ecb14675f10b172ce7a99b5 (patch)
tree1a9dd765655e5af97392fae25dcb285462cf8aa7 /lib/compress.js
parent7b7134405118e944f87772edc41c3ddec856cdff (diff)
downloadtracifyjs-992b6b9fcce47ca67ecb14675f10b172ce7a99b5.tar.gz
tracifyjs-992b6b9fcce47ca67ecb14675f10b172ce7a99b5.zip
Fix invalid removal of left side in && and || compression
See #637. This does not produce the optimal result, but it does prevent the removal of non-side-effect-free code.
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 27285984..b77b5ff3 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2110,6 +2110,12 @@ merge(Compressor.prototype, {
var rr = self.right.evaluate(compressor);
if ((ll.length > 1 && !ll[1]) || (rr.length > 1 && !rr[1])) {
compressor.warn("Boolean && always false [{file}:{line},{col}]", self.start);
+ if (self.left.has_side_effects(compressor)) {
+ return make_node(AST_Seq, self, {
+ car: self.left,
+ cdr: make_node(AST_False)
+ }).optimize(compressor);
+ }
return make_node(AST_False, self);
}
if (ll.length > 1 && ll[1]) {
@@ -2124,6 +2130,12 @@ merge(Compressor.prototype, {
var rr = self.right.evaluate(compressor);
if ((ll.length > 1 && ll[1]) || (rr.length > 1 && rr[1])) {
compressor.warn("Boolean || always true [{file}:{line},{col}]", self.start);
+ if (self.left.has_side_effects(compressor)) {
+ return make_node(AST_Seq, self, {
+ car: self.left,
+ cdr: make_node(AST_True)
+ }).optimize(compressor);
+ }
return make_node(AST_True, self);
}
if (ll.length > 1 && !ll[1]) {