From 3cfee9c976bfe9dbf9ebae4a0afe7c6e677b91ab Mon Sep 17 00:00:00 2001 From: Lucas Duailibe Date: Fri, 8 Sep 2017 00:25:54 -0300 Subject: [PATCH] Clarification of code --- src/printer.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/printer.js b/src/printer.js index 878a48c7..f809cdb3 100644 --- a/src/printer.js +++ b/src/printer.js @@ -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)); }