enhance assignments, booleans & conditionals (#5691)

This commit is contained in:
Alex Lam S.L
2022-10-03 01:01:23 +01:00
committed by GitHub
parent 6cdc035b2f
commit 80fc862547
6 changed files with 164 additions and 58 deletions

View File

@@ -290,6 +290,45 @@ increment_decrement_2: {
expect_stdout: "42"
}
lazily_chained_assignments: {
options = {
assignments: true,
collapse_vars: true,
conditionals: true,
unused: true,
}
input: {
function f(a) {
if (a = console.log("foo"))
a = console.log("bar");
return a;
}
function g(b) {
if (b = console.log("baz"))
;
else
b = console.log("moo");
return b;
}
console.log(f(), g());
}
expect: {
function f(a) {
return console.log("foo") && console.log("bar");
}
function g(b) {
return console.log("baz") || console.log("moo");
}
console.log(f(), g());
}
expect_stdout: [
"foo",
"baz",
"moo",
"undefined undefined",
]
}
issue_3375_1: {
options = {
assignments: true,

View File

@@ -80,6 +80,25 @@ de_morgan_1c: {
expect_stdout: "true"
}
de_morgan_1d: {
options = {
booleans: true,
}
input: {
function f(a) {
return (a = false) || a;
}
console.log(f(null), f(42));
}
expect: {
function f(a) {
return a = !1;
}
console.log(f(null), f(42));
}
expect_stdout: "false false"
}
de_morgan_2a: {
options = {
booleans: true,
@@ -181,6 +200,31 @@ de_morgan_2d: {
]
}
de_morgan_2e: {
options = {
booleans: true,
conditionals: true,
}
input: {
function f(a, b) {
return (a && b) && b;
}
console.log(f(null), f(null, {}));
console.log(f(42), f(42, {}));
}
expect: {
function f(a, b) {
return a && b;
}
console.log(f(null), f(null, {}));
console.log(f(42), f(42, {}));
}
expect_stdout: [
"null null",
"undefined {}",
]
}
de_morgan_3a: {
options = {
booleans: true,

View File

@@ -76,12 +76,14 @@ self_comparison_1: {
comparisons: true,
}
input: {
var a, b;
a === a;
a !== b;
b.c === a.c;
b.c !== b.c;
}
expect: {
var a, b;
a == a;
a !== b;
b.c === a.c;
@@ -275,6 +277,7 @@ issue_2857_3: {
issue_2857_4: {
options = {
comparisons: true,
conditionals: true,
}
input: {
function f(a, p) {
@@ -305,6 +308,7 @@ issue_2857_4: {
issue_2857_5: {
options = {
comparisons: true,
conditionals: true,
}
input: {
function f(a, p) {
@@ -528,6 +532,7 @@ nullish_assign: {
nullish_chain: {
options = {
comparisons: true,
conditionals: true,
}
input: {
var a;

View File

@@ -3028,7 +3028,7 @@ issue_5673_2: {
expect: {
var a = "PASS";
console.log(function(b) {
return ((b = a) || (b = a)) && b;
return a || (b = a) && b;
}());
}
expect_stdout: "PASS"

View File

@@ -976,33 +976,33 @@ nested_if_return: {
if_return: true,
}
input: {
function f() {
if (A) {
if (B)
return B;
if (C)
return D;
if (E)
return F;
if (G)
return H;
if (I) {
if (J)
return K;
function f(a, b, c, d, e, f, g, h, i, j, k, l, m, n) {
if (a) {
if (b)
return b;
if (c)
return d;
if (e)
return f;
if (g)
return h;
if (i) {
if (j)
return k;
return;
}
if (L) {
if (M)
if (l) {
if (m)
return;
return N;
return n;
}
}
}
}
expect: {
function f() {
if (A)
return B || (C ? D : E ? F : G ? H : I ? J ? K : void 0 : L && !M ? N : void 0);
function f(a, b, c, d, e, f, g, h, i, j, k, l, m, n) {
if (a)
return b || (c ? d : e ? f : g ? h : i ? j ? k : void 0 : l && !m ? n : void 0);
}
}
}