Clarification of code

master
Lucas Duailibe 2017-09-08 00:25:54 -03:00 committed by Stephen Scott
parent 2c37697f82
commit 3cfee9c976
1 changed files with 13 additions and 8 deletions

View File

@ -338,8 +338,9 @@ function genericPrintNoParens(path, options, print, args) {
);
}
// Avoid indenting sub-expressions in assignment/return/etc statements.
const willBreakRegardless =
// Avoid indenting sub-expressions in some cases where the first sub-expression is already
// idented accordingly. We should ident sub-expressions where the first case isn't idented.
const shouldNotIdent =
parent.type === "ReturnStatement" ||
(parent.type === "JSXExpressionContainer" &&
parentParent.type === "JSXAttribute") ||
@ -347,14 +348,18 @@ function genericPrintNoParens(path, options, print, args) {
(n !== parent.body && parent.type === "ForStatement") ||
parent.type === "ConditionalExpression";
const shouldIdentIfInlining =
parent.type === "AssignmentExpression" ||
parent.type === "VariableDeclarator" ||
parent.type === "ObjectProperty" ||
parent.type === "Property";
const logicalSubExpressionExists = n.left.type === "LogicalExpression";
if (
willBreakRegardless ||
shouldNotIdent ||
(shouldInlineLogicalExpression(n) && n.left.type !== n.type) ||
(!shouldInlineLogicalExpression(n) &&
(parent.type === "AssignmentExpression" ||
parent.type === "VariableDeclarator" ||
parent.type === "ObjectProperty" ||
parent.type === "Property"))
(!shouldInlineLogicalExpression(n) && shouldIdentIfInlining)
) {
return group(concat(parts));
}