Skip to content

Commit 150720b

Browse files
committed
when formatting lists check if end list token still belongs to the parent node
1 parent cbecae3 commit 150720b

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/services/formatting/formatting.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,11 @@ module ts.formatting {
597597
if (listEndToken !== SyntaxKind.Unknown) {
598598
if (formattingScanner.isOnToken()) {
599599
var tokenInfo = formattingScanner.readTokenInfo(parent);
600-
if (tokenInfo.token.kind === listEndToken) {
600+
// consume the list end token only if it is still belong to the parent
601+
// there might be the case when current token matches end token but does not considered as one
602+
// function (x: function) <--
603+
// without this check close paren will be interpreted as list end token for function expression which is wrong
604+
if (tokenInfo.token.kind === listEndToken && rangeContainsRange(parent, tokenInfo.token)) {
601605
// consume list end token
602606
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation);
603607
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference path='fourslash.ts' />
2+
////function f( f: function){/*1*/
3+
goTo.marker("1");
4+
edit.insert("}");
5+
verify.currentLineContentIs("function f(f: function){ }")

0 commit comments

Comments
 (0)