From 17bd75d61384b584af6ee31e20652b5e70ad2f36 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Mon, 28 Oct 2019 14:59:27 -0700 Subject: [PATCH] Cherry-pick PR #34779 into release-3.7 (#34782) Component commits: 2e435ae3b0 Fix incorrectly looking for position in call/new expression arguments when looking for indentation of type arguments Fixes #32487 0bb1b40b1b Update src/services/formatting/smartIndenter.ts Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> --- src/services/formatting/smartIndenter.ts | 5 +++-- .../fourslash/formatTypeArgumentOnNewLine.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/formatTypeArgumentOnNewLine.ts diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 6cc654453e4..5539a8e30cb 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -326,8 +326,9 @@ namespace ts.formatting { 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 currentNode = find(parent.arguments, arg => arg.pos === child.pos); + // If it's not one of the arguments, don't look past this + if (!currentNode) return false; const currentIndex = parent.arguments.indexOf(currentNode); if (currentIndex === 0) return false; // Can't look at previous node if first diff --git a/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts b/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts new file mode 100644 index 00000000000..8567a5ff06d --- /dev/null +++ b/tests/cases/fourslash/formatTypeArgumentOnNewLine.ts @@ -0,0 +1,18 @@ +/// + +////const genericObject = new GenericObject< +//// /*1*/{} +////>(); +////const genericObject2 = new GenericObject2< +//// /*2*/{}, +//// /*3*/{} +////>(); + +format.document(); + +goTo.marker("1"); +verify.currentLineContentIs(" {}"); +goTo.marker("2"); +verify.currentLineContentIs(" {},"); +goTo.marker("3"); +verify.currentLineContentIs(" {}"); \ No newline at end of file