aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorkzc <zaxxon2011@gmail.com>2016-10-02 10:46:09 -0400
committerRichard van Velzen <rvanvelzen@experty.com>2016-10-06 13:50:11 +0200
commitfc9804b90955d3b38ac6e6c903a8c0e3f7945913 (patch)
treed9863712ef4643b9796baabb25cd4fcf4aaf40bb /lib
parent4761d07e0bc3d4c53e0c9c72fc9c322c95cb090e (diff)
downloadtracifyjs-fc9804b90955d3b38ac6e6c903a8c0e3f7945913.tar.gz
tracifyjs-fc9804b90955d3b38ac6e6c903a8c0e3f7945913.zip
Fix (typeof side_effect()) in boolean context
Fixes #1289 with suggestion by @rvanvelzen
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 14fb8f1e..1845717c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2314,6 +2314,12 @@ merge(Compressor.prototype, {
// typeof always returns a non-empty string, thus it's
// always true in booleans
compressor.warn("Boolean expression always true [{file}:{line},{col}]", self.start);
+ if (self.expression.has_side_effects(compressor)) {
+ return make_node(AST_Seq, self, {
+ car: self.expression,
+ cdr: make_node(AST_True, self)
+ });
+ }
return make_node(AST_True, self);
}
if (e instanceof AST_Binary && self.operator == "!") {