diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-02-01 19:15:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-01 19:15:17 +0800 |
commit | c3a002ff9739b60ec1836719c1e240df22a67830 (patch) | |
tree | 181897bab1377b136aef85dca74f7439d18f06e4 /test/compress | |
parent | fad6766a905350574b698af707958294e22184f3 (diff) | |
download | tracifyjs-c3a002ff9739b60ec1836719c1e240df22a67830.tar.gz tracifyjs-c3a002ff9739b60ec1836719c1e240df22a67830.zip |
account for side-effects in `comparisons` of `null` & `undefined` (#2863)
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/comparing.js | 233 |
1 files changed, 153 insertions, 80 deletions
diff --git a/test/compress/comparing.js b/test/compress/comparing.js index d581d086..d56445e0 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" } |