Inline chained conditionals inside of jsx attribute (#1519)

Fixes #1515
master
Christopher Chedeau 2017-05-05 21:44:50 -07:00 committed by GitHub
parent c63e21b52b
commit bb232d48a3
4 changed files with 49 additions and 2 deletions

View File

@ -196,6 +196,7 @@ function genericPrintNoParens(path, options, print, args) {
case "BinaryExpression":
case "LogicalExpression": {
const parent = path.getParentNode();
const parentParent = path.getParentNode(1);
const isInsideParenthesis =
n !== parent.body &&
(parent.type === "IfStatement" ||
@ -230,6 +231,8 @@ function genericPrintNoParens(path, options, print, args) {
parent.type === "VariableDeclarator" ||
shouldInlineLogicalExpression(n) ||
parent.type === "ReturnStatement" ||
(parent.type === "JSXExpressionContainer" &&
parentParent.type === "JSXAttribute") ||
(n === parent.body && parent.type === "ArrowFunctionExpression") ||
(n !== parent.body && parent.type === "ForStatement")
) {

View File

@ -120,6 +120,37 @@ this.steps = steps || [
`;
exports[`jsx_parent.js 1`] = `
<div
src={
!isJellyfishEnabled &&
diffUpdateMessageInput != null &&
this.state.isUpdateMessageEmpty
}
/>;
<div>
{!isJellyfishEnabled &&
diffUpdateMessageInput != null &&
this.state.isUpdateMessageEmpty}
</div>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<div
src={
!isJellyfishEnabled &&
diffUpdateMessageInput != null &&
this.state.isUpdateMessageEmpty
}
/>;
<div>
{!isJellyfishEnabled &&
diffUpdateMessageInput != null &&
this.state.isUpdateMessageEmpty}
</div>;
`;
exports[`short-right.js 1`] = `
this._cumulativeHeights &&
Math.abs(

View File

@ -0,0 +1,13 @@
<div
src={
!isJellyfishEnabled &&
diffUpdateMessageInput != null &&
this.state.isUpdateMessageEmpty
}
/>;
<div>
{!isJellyfishEnabled &&
diffUpdateMessageInput != null &&
this.state.isUpdateMessageEmpty}
</div>;

View File

@ -118,12 +118,12 @@ exports[`expression.js 1`] = `
key={option}
imageSource={
this.props.veryBigItemImageSourceFunc &&
this.props.veryBigItemImageSourceFunc(option)
this.props.veryBigItemImageSourceFunc(option)
}
imageSize={this.props.veryBigItemImageSize}
imageView={
this.props.veryBigItemImageViewFunc &&
this.props.veryBigItemImageViewFunc(option)
this.props.veryBigItemImageViewFunc(option)
}
heading={this.props.displayTextFunc(option)}
value={option}