extend fuzzy RHS folding (#3006)

- `a = []; if (1) x();` => `if (a = []) x();`
This commit is contained in:
Alex Lam S.L
2018-03-17 03:10:21 +08:00
committed by GitHub
parent 20ca0f5906
commit ccf0e2ef4f
3 changed files with 138 additions and 58 deletions

View File

@@ -4976,7 +4976,7 @@ collapse_rhs_array: {
expect_stdout: "false false false"
}
collapse_rhs_boolean: {
collapse_rhs_boolean_1: {
options = {
collapse_vars: true,
}
@@ -5001,6 +5001,66 @@ collapse_rhs_boolean: {
expect_stdout: "true true true"
}
collapse_rhs_boolean_2: {
options = {
collapse_vars: true,
}
input: {
var a;
(function f1() {
a = function() {};
if (/foo/)
console.log(typeof a);
})();
console.log(function f2() {
a = [];
return !1;
}());
}
expect: {
var a;
(function f1() {
if (a = function() {})
console.log(typeof a);
})();
console.log(function f2() {
return !(a = []);
}());
}
expect_stdout: [
"function",
"false",
]
}
collapse_rhs_boolean_3: {
options = {
booleans: true,
collapse_vars: true,
conditionals: true,
}
input: {
var a, f, g, h, i, n, s, t, x, y;
if (x()) {
n = a;
} else if (y()) {
n = f();
} else if (s) {
i = false;
n = g(true);
} else if (t) {
i = false;
n = h(true);
} else {
n = [];
}
}
expect: {
var a, f, g, h, i, n, s, t, x, y;
n = x() ? a : y() ? f() : s ? g(!(i = !1)) : t ? h(!(i = !1)) : [];
}
}
collapse_rhs_function: {
options = {
collapse_vars: true,