mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #32359 from orta/fix_14589
Don't add extra indentation for objects inside function parameters
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user