[Pkg-javascript-commits] [uglifyjs] 119/190: boolean_expression ? true : false --> boolean_expression
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Aug 7 23:17:19 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.
commit 11b0efdf84dcdae71ac66453f8bf644052a32cc8
Author: kzc <zaxxon2011 at gmail.com>
Date: Sun Feb 21 18:47:21 2016 -0500
boolean_expression ? true : false --> boolean_expression
---
lib/compress.js | 4 +++
test/compress/conditionals.js | 74 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+)
diff --git a/lib/compress.js b/lib/compress.js
index a2666fa..f49486a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2651,6 +2651,10 @@ merge(Compressor.prototype, {
// y?true:false --> !!y
if (is_true(consequent) && is_false(alternative)) {
+ if (self.condition.is_boolean()) {
+ // boolean_expression ? true : false --> boolean_expression
+ return self.condition;
+ }
self.condition = self.condition.negate(compressor);
return make_node(AST_UnaryPrefix, self.condition, {
operator: "!",
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js
index 65cfea6..db0d800 100644
--- a/test/compress/conditionals.js
+++ b/test/compress/conditionals.js
@@ -738,3 +738,77 @@ conditional_or: {
a = condition + 3 || null;
}
}
+
+trivial_boolean_ternary_expressions : {
+ options = {
+ conditionals: true,
+ evaluate : true,
+ booleans : true
+ };
+ input: {
+ f('foo' in m ? true : false);
+ f('foo' in m ? false : true);
+
+ f(g ? true : false);
+ f(foo() ? true : false);
+ f("bar" ? true : false);
+ f(5 ? true : false);
+ f(5.7 ? true : false);
+ f(x - y ? true : false);
+
+ f(x == y ? true : false);
+ f(x === y ? !0 : !1);
+ f(x < y ? !0 : false);
+ f(x <= y ? true : false);
+ f(x > y ? true : !1);
+ f(x >= y ? !0 : !1);
+
+ f(g ? false : true);
+ f(foo() ? false : true);
+ f("bar" ? false : true);
+ f(5 ? false : true);
+ f(5.7 ? false : true);
+ f(x - y ? false : true);
+
+ f(x == y ? !1 : !0);
+ f(x === y ? false : true);
+
+ f(x < y ? false : true);
+ f(x <= y ? false : !0);
+ f(x > y ? !1 : true);
+ f(x >= y ? !1 : !0);
+ }
+ expect: {
+ f('foo' in m);
+ f(!('foo' in m));
+
+ f(!!g);
+ f(!!foo());
+ f(!0);
+ f(!0);
+ f(!0);
+ f(!!(x - y));
+
+ f(x == y);
+ f(x === y);
+ f(x < y);
+ f(x <= y);
+ f(x > y);
+ f(x >= y);
+
+ f(!g);
+ f(!foo());
+ f(!1);
+ f(!1);
+ f(!1);
+ f(!(x - y));
+
+ f(x != y);
+ f(x !== y);
+
+ f(!(x < y));
+ f(!(x <= y));
+ f(!(x > y));
+ f(!(x >= y));
+ }
+}
--
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