[Pkg-javascript-commits] [uglifyjs] 461/491: account for side-effects in `comparisons` of `null` & `undefined` (#2863)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:52:04 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.
commit c3a002ff9739b60ec1836719c1e240df22a67830
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Thu Feb 1 19:15:17 2018 +0800
account for side-effects in `comparisons` of `null` & `undefined` (#2863)
---
lib/compress.js | 1 +
test/compress/comparing.js | 233 +++++++++++++++++++++++++++++----------------
2 files changed, 154 insertions(+), 80 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index a88ea2c..1b0aa15 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4800,6 +4800,7 @@ merge(Compressor.prototype, {
&& lhs.operator == self.right.operator
&& (is_undefined(lhs.left, compressor) && self.right.left instanceof AST_Null
|| lhs.left instanceof AST_Null && is_undefined(self.right.left, compressor))
+ && !lhs.right.has_side_effects(compressor)
&& lhs.right.equivalent_to(self.right.right)) {
var combined = make_node(AST_Binary, self, {
operator: lhs.operator.slice(0, -1),
diff --git a/test/compress/comparing.js b/test/compress/comparing.js
index d581d08..d56445e 100644
--- a/test/compress/comparing.js
+++ b/test/compress/comparing.js
@@ -118,24 +118,48 @@ issue_2857_1: {
comparisons: true,
}
input: {
- a === undefined || a === null;
- a === undefined || a !== null;
- a !== undefined || a === null;
- a !== undefined || a !== null;
- a === undefined && a === null;
- a === undefined && a !== null;
- a !== undefined && a === null;
- a !== undefined && a !== null;
+ function f1(a) {
+ a === undefined || a === null;
+ a === undefined || a !== null;
+ a !== undefined || a === null;
+ a !== undefined || a !== null;
+ a === undefined && a === null;
+ a === undefined && a !== null;
+ a !== undefined && a === null;
+ a !== undefined && a !== null;
+ }
+ function f2(a) {
+ a === null || a === undefined;
+ a === null || a !== undefined;
+ a !== null || a === undefined;
+ a !== null || a !== undefined;
+ a === null && a === undefined;
+ a === null && a !== undefined;
+ a !== null && a === undefined;
+ a !== null && a !== undefined;
+ }
}
expect: {
- null == a;
- void 0 === a || null !== a;
- void 0 !== a || null === a;
- void 0 !== a || null !== a;
- void 0 === a && null === a;
- void 0 === a && null !== a;
- void 0 !== a && null === a;
- null != a;
+ function f1(a) {
+ null == a;
+ void 0 === a || null !== a;
+ void 0 !== a || null === a;
+ void 0 !== a || null !== a;
+ void 0 === a && null === a;
+ void 0 === a && null !== a;
+ void 0 !== a && null === a;
+ null != a;
+ }
+ function f2(a) {
+ null == a;
+ null === a || void 0 !== a;
+ null !== a || void 0 === a;
+ null !== a || void 0 !== a;
+ null === a && void 0 === a;
+ null === a && void 0 !== a;
+ null !== a && void 0 === a;
+ null != a;
+ }
}
}
@@ -144,24 +168,28 @@ issue_2857_2: {
comparisons: true,
}
input: {
- a === undefined || a === null || p;
- a === undefined || a !== null || p;
- a !== undefined || a === null || p;
- a !== undefined || a !== null || p;
- a === undefined && a === null || p;
- a === undefined && a !== null || p;
- a !== undefined && a === null || p;
- a !== undefined && a !== null || p;
+ function f(a, p) {
+ a === undefined || a === null || p;
+ a === undefined || a !== null || p;
+ a !== undefined || a === null || p;
+ a !== undefined || a !== null || p;
+ a === undefined && a === null || p;
+ a === undefined && a !== null || p;
+ a !== undefined && a === null || p;
+ a !== undefined && a !== null || p;
+ }
}
expect: {
- null == a || p;
- void 0 === a || null !== a || p;
- void 0 !== a || null === a || p;
- void 0 !== a || null !== a || p;
- void 0 === a && null === a || p;
- void 0 === a && null !== a || p;
- void 0 !== a && null === a || p;
- null != a || p;
+ function f(a, p) {
+ null == a || p;
+ void 0 === a || null !== a || p;
+ void 0 !== a || null === a || p;
+ void 0 !== a || null !== a || p;
+ void 0 === a && null === a || p;
+ void 0 === a && null !== a || p;
+ void 0 !== a && null === a || p;
+ null != a || p;
+ }
}
}
@@ -170,24 +198,28 @@ issue_2857_3: {
comparisons: true,
}
input: {
- a === undefined || a === null && p;
- a === undefined || a !== null && p;
- a !== undefined || a === null && p;
- a !== undefined || a !== null && p;
- a === undefined && a === null && p;
- a === undefined && a !== null && p;
- a !== undefined && a === null && p;
- a !== undefined && a !== null && p;
+ function f(a, p) {
+ a === undefined || a === null && p;
+ a === undefined || a !== null && p;
+ a !== undefined || a === null && p;
+ a !== undefined || a !== null && p;
+ a === undefined && a === null && p;
+ a === undefined && a !== null && p;
+ a !== undefined && a === null && p;
+ a !== undefined && a !== null && p;
+ }
}
expect: {
- void 0 === a || null === a && p;
- void 0 === a || null !== a && p;
- void 0 !== a || null === a && p;
- void 0 !== a || null !== a && p;
- void 0 === a && null === a && p;
- void 0 === a && null !== a && p;
- void 0 !== a && null === a && p;
- null != a && p;
+ function f(a, p) {
+ void 0 === a || null === a && p;
+ void 0 === a || null !== a && p;
+ void 0 !== a || null === a && p;
+ void 0 !== a || null !== a && p;
+ void 0 === a && null === a && p;
+ void 0 === a && null !== a && p;
+ void 0 !== a && null === a && p;
+ null != a && p;
+ }
}
}
@@ -196,24 +228,28 @@ issue_2857_4: {
comparisons: true,
}
input: {
- p || a === undefined || a === null;
- p || a === undefined || a !== null;
- p || a !== undefined || a === null;
- p || a !== undefined || a !== null;
- p || a === undefined && a === null;
- p || a === undefined && a !== null;
- p || a !== undefined && a === null;
- p || a !== undefined && a !== null;
+ function f(a, p) {
+ p || a === undefined || a === null;
+ p || a === undefined || a !== null;
+ p || a !== undefined || a === null;
+ p || a !== undefined || a !== null;
+ p || a === undefined && a === null;
+ p || a === undefined && a !== null;
+ p || a !== undefined && a === null;
+ p || a !== undefined && a !== null;
+ }
}
expect: {
- p || null == a;
- p || void 0 === a || null !== a;
- p || void 0 !== a || null === a;
- p || void 0 !== a || null !== a;
- p || void 0 === a && null === a;
- p || void 0 === a && null !== a;
- p || void 0 !== a && null === a;
- p || null != a;
+ function f(a, p) {
+ p || null == a;
+ p || void 0 === a || null !== a;
+ p || void 0 !== a || null === a;
+ p || void 0 !== a || null !== a;
+ p || void 0 === a && null === a;
+ p || void 0 === a && null !== a;
+ p || void 0 !== a && null === a;
+ p || null != a;
+ }
}
}
@@ -222,23 +258,60 @@ issue_2857_5: {
comparisons: true,
}
input: {
- p && a === undefined || a === null;
- p && a === undefined || a !== null;
- p && a !== undefined || a === null;
- p && a !== undefined || a !== null;
- p && a === undefined && a === null;
- p && a === undefined && a !== null;
- p && a !== undefined && a === null;
- p && a !== undefined && a !== null;
+ function f(a, p) {
+ p && a === undefined || a === null;
+ p && a === undefined || a !== null;
+ p && a !== undefined || a === null;
+ p && a !== undefined || a !== null;
+ p && a === undefined && a === null;
+ p && a === undefined && a !== null;
+ p && a !== undefined && a === null;
+ p && a !== undefined && a !== null;
+ }
+ }
+ expect: {
+ function f(a, p) {
+ p && void 0 === a || null === a;
+ p && void 0 === a || null !== a;
+ p && void 0 !== a || null === a;
+ p && void 0 !== a || null !== a;
+ p && void 0 === a && null === a;
+ p && void 0 === a && null !== a;
+ p && void 0 !== a && null === a;
+ p && null != a;
+ }
+ }
+}
+
+issue_2857_6: {
+ options = {
+ comparisons: true,
+ pure_getters: "strict",
+ reduce_vars: true,
+ }
+ input: {
+ function f(a) {
+ if (({}).b === undefined || {}.b === null)
+ return a.b !== undefined && a.b !== null;
+ }
+ console.log(f({
+ a: [ null ],
+ get b() {
+ return this.a.shift();
+ }
+ }));
}
expect: {
- p && void 0 === a || null === a;
- p && void 0 === a || null !== a;
- p && void 0 !== a || null === a;
- p && void 0 !== a || null !== a;
- p && void 0 === a && null === a;
- p && void 0 === a && null !== a;
- p && void 0 !== a && null === a;
- p && null != a;
+ function f(a) {
+ if (null == {}.b)
+ return void 0 !== a.b && null !== a.b;
+ }
+ console.log(f({
+ a: [ null ],
+ get b() {
+ return this.a.shift();
+ }
+ }));
}
+ expect_stdout: "true"
}
--
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