Fix chained logical expressions with objects/array/etc inlined
parent
f964be5f8a
commit
2c37697f82
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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`] = `
|
||||
|
|
|
@ -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
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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>;
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue