Skip to content

Commit 1d78218

Browse files
committed
Handle feedback from #32359
1 parent 59d5585 commit 1d78218

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/services/formatting/formatting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ namespace ts.formatting {
490490
else if (SmartIndenter.childStartsOnTheSameLineWithElseInIfStatement(parent, node, startLine, sourceFile)) {
491491
return { indentation: parentDynamicIndentation.getIndentation(), delta };
492492
}
493-
else if (SmartIndenter.childStartsInlineWithPreviousObject(parent, node, startLine, sourceFile)) {
493+
else if (SmartIndenter.argumentStartsOnSameLineAsPreviousArgument(parent, node, startLine, sourceFile)) {
494494
return { indentation: parentDynamicIndentation.getIndentation(), delta };
495495
}
496496
else {

src/services/formatting/smartIndenter.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,15 @@ namespace ts.formatting {
322322
return false;
323323
}
324324

325-
export function childStartsInlineWithPreviousObject(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean {
326-
if (parent.kind === SyntaxKind.CallExpression) {
327-
const parentCallExpression = <CallExpression>parent;
328-
const currentNode = find(parentCallExpression.arguments, arg => arg.pos === child.pos);
329-
if (!currentNode) return false; // Shouldn't happen
325+
export function argumentStartsOnSameLineAsPreviousArgument(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean {
326+
if (isCallOrNewExpression(parent)) {
327+
if (!parent.arguments) return false;
330328

331-
const currentIndex = parentCallExpression.arguments.indexOf(currentNode);
329+
const currentNode = Debug.assertDefined(find(parent.arguments, arg => arg.pos === child.pos));
330+
const currentIndex = parent.arguments.indexOf(currentNode);
332331
if (currentIndex === 0) return false; // Can't look at previous node if first
333332

334-
const previousNode = parentCallExpression.arguments[currentIndex - 1];
333+
const previousNode = parent.arguments[currentIndex - 1];
335334
const lineOfPreviousNode = getLineAndCharacterOfPosition(sourceFile, previousNode.getEnd()).line;
336335

337336
if (childStartLine === lineOfPreviousNode) {

0 commit comments

Comments
 (0)