Fix chained logical expressions with objects/array/etc inlined

master
Lucas Duailibe 2017-09-07 15:28:12 -03:00 committed by Stephen Scott
parent f964be5f8a
commit 2c37697f82
7 changed files with 211 additions and 7 deletions

View File

@ -339,18 +339,22 @@ function genericPrintNoParens(path, options, print, args) {
}
// Avoid indenting sub-expressions in assignment/return/etc statements.
if (
parent.type === "AssignmentExpression" ||
parent.type === "VariableDeclarator" ||
shouldInlineLogicalExpression(n) ||
const willBreakRegardless =
parent.type === "ReturnStatement" ||
(parent.type === "JSXExpressionContainer" &&
parentParent.type === "JSXAttribute") ||
(n === parent.body && parent.type === "ArrowFunctionExpression") ||
(n !== parent.body && parent.type === "ForStatement") ||
parent.type === "ObjectProperty" ||
parent.type === "Property" ||
parent.type === "ConditionalExpression"
parent.type === "ConditionalExpression";
if (
willBreakRegardless ||
(shouldInlineLogicalExpression(n) && n.left.type !== n.type) ||
(!shouldInlineLogicalExpression(n) &&
(parent.type === "AssignmentExpression" ||
parent.type === "VariableDeclarator" ||
parent.type === "ObjectProperty" ||
parent.type === "Property"))
) {
return group(concat(parts));
}

View File

@ -6,6 +6,14 @@ function f() {
entity => entity && entity.isInstallAvailable() && !entity.isQueue() && entity.isDisabled()
)
}
function f() {
const appEntitys = getAppEntitys(loadObject).map(
entity => entity && entity.isInstallAvailable() && !entity.isQueue() && entity.isDisabled() && {
id: entity.id
}
)
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function f() {
const appEntitys = getAppEntitys(loadObject).filter(
@ -17,6 +25,18 @@ function f() {
);
}
function f() {
const appEntitys = getAppEntitys(loadObject).map(
entity =>
entity &&
entity.isInstallAvailable() &&
!entity.isQueue() &&
entity.isDisabled() && {
id: entity.id
}
);
}
`;
exports[`bitwise-flags.js 1`] = `
@ -134,12 +154,42 @@ prevState = prevState || {
selectedCatalog: null,
};
prevState = prevState ||
defaultState || {
catalogs: [],
loadState: LOADED,
opened: false,
searchQuery: '',
selectedCatalog: null,
};
this.steps = steps || [
{
name: 'mock-module',
path: '/nux/mock-module',
},
];
const create = () => {
const result = doSomething();
return (
shouldReturn &&
result.ok && {
status: "ok",
createdAt: result.createdAt,
updatedAt: result.updatedAt
}
);
}
const obj = {
state: shouldHaveState &&
stateIsOK && {
loadState: LOADED,
opened: false
},
loaded: true
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prevState = prevState || {
catalogs: [],
@ -149,6 +199,15 @@ prevState = prevState || {
selectedCatalog: null
};
prevState = prevState ||
defaultState || {
catalogs: [],
loadState: LOADED,
opened: false,
searchQuery: "",
selectedCatalog: null
};
this.steps = steps || [
{
name: "mock-module",
@ -156,6 +215,27 @@ this.steps = steps || [
}
];
const create = () => {
const result = doSomething();
return (
shouldReturn &&
result.ok && {
status: "ok",
createdAt: result.createdAt,
updatedAt: result.updatedAt
}
);
};
const obj = {
state: shouldHaveState &&
stateIsOK && {
loadState: LOADED,
opened: false
},
loaded: true
};
`;
exports[`jsx_parent.js 1`] = `
@ -172,6 +252,21 @@ exports[`jsx_parent.js 1`] = `
diffUpdateMessageInput != null &&
this.state.isUpdateMessageEmpty}
</div>;
<div
style={
!isJellyfishEnabled &&
diffUpdateMessageInput && {
fontSize: 14,
color: '#fff'
}
}
/>;
<div>
{!isJellyfishEnabled &&
diffUpdateMessageInput != null && <div><span>Text</span></div>}
</div>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div
src={
@ -187,6 +282,25 @@ exports[`jsx_parent.js 1`] = `
this.state.isUpdateMessageEmpty}
</div>;
<div
style={
!isJellyfishEnabled &&
diffUpdateMessageInput && {
fontSize: 14,
color: "#fff"
}
}
/>;
<div>
{!isJellyfishEnabled &&
diffUpdateMessageInput != null && (
<div>
<span>Text</span>
</div>
)}
</div>;
`;
exports[`math.js 1`] = `

View File

@ -3,3 +3,11 @@ function f() {
entity => entity && entity.isInstallAvailable() && !entity.isQueue() && entity.isDisabled()
)
}
function f() {
const appEntitys = getAppEntitys(loadObject).map(
entity => entity && entity.isInstallAvailable() && !entity.isQueue() && entity.isDisabled() && {
id: entity.id
}
)
}

View File

@ -6,9 +6,39 @@ prevState = prevState || {
selectedCatalog: null,
};
prevState = prevState ||
defaultState || {
catalogs: [],
loadState: LOADED,
opened: false,
searchQuery: '',
selectedCatalog: null,
};
this.steps = steps || [
{
name: 'mock-module',
path: '/nux/mock-module',
},
];
const create = () => {
const result = doSomething();
return (
shouldReturn &&
result.ok && {
status: "ok",
createdAt: result.createdAt,
updatedAt: result.updatedAt
}
);
}
const obj = {
state: shouldHaveState &&
stateIsOK && {
loadState: LOADED,
opened: false
},
loaded: true
}

View File

@ -11,3 +11,18 @@
diffUpdateMessageInput != null &&
this.state.isUpdateMessageEmpty}
</div>;
<div
style={
!isJellyfishEnabled &&
diffUpdateMessageInput && {
fontSize: 14,
color: '#fff'
}
}
/>;
<div>
{!isJellyfishEnabled &&
diffUpdateMessageInput != null && <div><span>Text</span></div>}
</div>;

View File

@ -528,6 +528,14 @@ exports[`logical-expression.js 1`] = `
{a && <span></span>}
</div>;
<div>
{a && <span>make this text just so long enough to break this to the next line</span>}
</div>;
<div>
{a && b && <span>make this text just so long enough to break this to the next line</span>}
</div>;
<div>
{a && <span>
<div>
@ -544,6 +552,23 @@ exports[`logical-expression.js 1`] = `
<div>{a && <span />}</div>;
<div>
{a && (
<span>
make this text just so long enough to break this to the next line
</span>
)}
</div>;
<div>
{a &&
b && (
<span>
make this text just so long enough to break this to the next line
</span>
)}
</div>;
<div>
{a && (
<span>

View File

@ -14,6 +14,14 @@
{a && <span></span>}
</div>;
<div>
{a && <span>make this text just so long enough to break this to the next line</span>}
</div>;
<div>
{a && b && <span>make this text just so long enough to break this to the next line</span>}
</div>;
<div>
{a && <span>
<div>