[Pkg-javascript-commits] [uglifyjs] 30/49: Fix (typeof side_effect()) in boolean context
Jonas Smedegaard
dr at jones.dk
Fri Dec 9 11:43:27 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository uglifyjs.
commit fc9804b90955d3b38ac6e6c903a8c0e3f7945913
Author: kzc <zaxxon2011 at gmail.com>
Date: Sun Oct 2 10:46:09 2016 -0400
Fix (typeof side_effect()) in boolean context
Fixes #1289 with suggestion by @rvanvelzen
---
lib/compress.js | 6 ++++++
test/compress/typeof.js | 22 ++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/lib/compress.js b/lib/compress.js
index 14fb8f1..1845717 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 == "!") {
diff --git a/test/compress/typeof.js b/test/compress/typeof.js
index cefdd43..fb39157 100644
--- a/test/compress/typeof.js
+++ b/test/compress/typeof.js
@@ -23,3 +23,25 @@ typeof_evaluation: {
h='undefined';
}
}
+
+typeof_in_boolean_context: {
+ options = {
+ booleans : true,
+ evaluate : true,
+ conditionals : true,
+ };
+ input: {
+ function f1(x) { return typeof x ? "yes" : "no"; }
+ function f2() { return typeof g()? "Yes" : "No"; }
+ typeof 0 ? foo() : bar();
+ !typeof console.log(1);
+ var a = !typeof console.log(2);
+ }
+ expect: {
+ function f1(x) { return "yes"; }
+ function f2() { return g(), "Yes"; }
+ foo();
+ !(console.log(1), !0);
+ var a = !(console.log(2), !0);
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list