Merge pull request #32359 from orta/fix_14589

Don't add extra indentation for objects inside function parameters
This commit is contained in:
Orta
2019-07-15 11:33:48 -04:00
committed by GitHub
4 changed files with 67 additions and 1 deletions
+3
View File
@@ -490,6 +490,9 @@ namespace ts.formatting {
else if (SmartIndenter.childStartsOnTheSameLineWithElseInIfStatement(parent, node, startLine, sourceFile)) {
return { indentation: parentDynamicIndentation.getIndentation(), delta };
}
else if (SmartIndenter.argumentStartsOnSameLineAsPreviousArgument(parent, node, startLine, sourceFile)) {
return { indentation: parentDynamicIndentation.getIndentation(), delta };
}
else {
return { indentation: parentDynamicIndentation.getIndentation() + parentDynamicIndentation.getDelta(node), delta };
}
+19
View File
@@ -322,6 +322,25 @@ namespace ts.formatting {
return false;
}
export function argumentStartsOnSameLineAsPreviousArgument(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean {
if (isCallOrNewExpression(parent)) {
if (!parent.arguments) return false;
const currentNode = Debug.assertDefined(find(parent.arguments, arg => arg.pos === child.pos));
const currentIndex = parent.arguments.indexOf(currentNode);
if (currentIndex === 0) return false; // Can't look at previous node if first
const previousNode = parent.arguments[currentIndex - 1];
const lineOfPreviousNode = getLineAndCharacterOfPosition(sourceFile, previousNode.getEnd()).line;
if (childStartLine === lineOfPreviousNode) {
return true;
}
}
return false;
}
export function getContainingList(node: Node, sourceFile: SourceFile): NodeArray<Node> | undefined {
return node.parent && getListByRange(node.getStart(sourceFile), node.getEnd(), node.parent, sourceFile);
}