enhance conditionals (#2758)

`x ? y || z : z` --> `x && y || z`
This commit is contained in:
Alex Lam S.L
2018-01-10 16:59:57 +08:00
committed by GitHub
parent bf832cde16
commit 09269be974
2 changed files with 57 additions and 0 deletions

View File

@@ -1224,3 +1224,46 @@ hoist_decl: {
x() ? y() : z();
}
}
to_and_or: {
options = {
conditionals: true,
}
input: {
var values = [
0,
null,
true,
"foo",
false,
-1 / 0,
void 0,
];
values.forEach(function(x) {
values.forEach(function(y) {
values.forEach(function(z) {
console.log(x ? y || z : z);
});
});
});
}
expect: {
var values = [
0,
null,
true,
"foo",
false,
-1 / 0,
void 0,
];
values.forEach(function(x) {
values.forEach(function(y) {
values.forEach(function(z) {
console.log(x && y || z);
});
});
});
}
expect_stdout: true
}