Fix boolean for empty objects (#1590)
* Add test for empty object in logical expression * Add check for empty object and array in shouldInlineLogicalExpression * Review fixes, add additional case with function callmaster
parent
5ca2117d23
commit
1d9478a61f
|
@ -3694,11 +3694,19 @@ function isBinaryish(node) {
|
|||
}
|
||||
|
||||
function shouldInlineLogicalExpression(node) {
|
||||
return (
|
||||
node.type === "LogicalExpression" &&
|
||||
(node.right.type === "ObjectExpression" ||
|
||||
node.right.type === "ArrayExpression")
|
||||
);
|
||||
if (node.type !== "LogicalExpression") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (node.right.type === "ObjectExpression" && node.right.properties.length !== 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node.right.type === "ArrayExpression" && node.right.elements.length !== 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// For binary expressions to be consistent, we need to group
|
||||
|
|
|
@ -4,8 +4,10 @@ exports[`empty.js 1`] = `
|
|||
const a = someVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeLong.Expression || [];
|
||||
const a = someVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeLong.Expression || {};
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
const a = someVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeLong.Expression || [];
|
||||
const a = someVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeLong.Expression || {};
|
||||
const a =
|
||||
someVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeLong.Expression || [];
|
||||
const a =
|
||||
someVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeLong.Expression || {};
|
||||
|
||||
`;
|
||||
|
||||
|
|
|
@ -202,6 +202,9 @@ const x = longVariable + longVariable * longVariable * longVariable / longVariab
|
|||
|
||||
const x = longVariable && longVariable && longVariable && longVariable && longVariable && longVariable;
|
||||
const x = longVariable && longVariable || longVariable && longVariable || longVariable && longVariable;
|
||||
const x = firstItemWithAVeryLongNameThatKeepsGoing || firstItemWithAVeryLongNameThatKeepsGoing || {};
|
||||
const x = firstItemWithAVeryLongNameThatKeepsGoing || firstItemWithAVeryLongNameThatKeepsGoing || [];
|
||||
const x = call(firstItemWithAVeryLongNameThatKeepsGoing, firstItemWithAVeryLongNameThatKeepsGoing) || [];
|
||||
|
||||
const x = longVariable * longint && longVariable >> 0 && longVariable + longVariable;
|
||||
|
||||
|
@ -242,6 +245,19 @@ const x =
|
|||
(longVariable && longVariable) ||
|
||||
(longVariable && longVariable) ||
|
||||
(longVariable && longVariable);
|
||||
const x =
|
||||
firstItemWithAVeryLongNameThatKeepsGoing ||
|
||||
firstItemWithAVeryLongNameThatKeepsGoing ||
|
||||
{};
|
||||
const x =
|
||||
firstItemWithAVeryLongNameThatKeepsGoing ||
|
||||
firstItemWithAVeryLongNameThatKeepsGoing ||
|
||||
[];
|
||||
const x =
|
||||
call(
|
||||
firstItemWithAVeryLongNameThatKeepsGoing,
|
||||
firstItemWithAVeryLongNameThatKeepsGoing
|
||||
) || [];
|
||||
|
||||
const x =
|
||||
longVariable * longint && longVariable >> 0 && longVariable + longVariable;
|
||||
|
|
|
@ -8,6 +8,9 @@ const x = longVariable + longVariable * longVariable * longVariable / longVariab
|
|||
|
||||
const x = longVariable && longVariable && longVariable && longVariable && longVariable && longVariable;
|
||||
const x = longVariable && longVariable || longVariable && longVariable || longVariable && longVariable;
|
||||
const x = firstItemWithAVeryLongNameThatKeepsGoing || firstItemWithAVeryLongNameThatKeepsGoing || {};
|
||||
const x = firstItemWithAVeryLongNameThatKeepsGoing || firstItemWithAVeryLongNameThatKeepsGoing || [];
|
||||
const x = call(firstItemWithAVeryLongNameThatKeepsGoing, firstItemWithAVeryLongNameThatKeepsGoing) || [];
|
||||
|
||||
const x = longVariable * longint && longVariable >> 0 && longVariable + longVariable;
|
||||
|
||||
|
|
Loading…
Reference in New Issue