From 150720bd70cd7a0d1ebf1347f37d97d57c0be7ee Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 13 Jan 2015 14:22:53 -0800 Subject: [PATCH] when formatting lists check if end list token still belongs to the parent node --- src/services/formatting/formatting.ts | 6 +++++- tests/cases/fourslash/formatEmptyParamList.ts | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/formatEmptyParamList.ts diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index b5edf776d58..13c423e9813 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -597,7 +597,11 @@ module ts.formatting { if (listEndToken !== SyntaxKind.Unknown) { if (formattingScanner.isOnToken()) { var tokenInfo = formattingScanner.readTokenInfo(parent); - if (tokenInfo.token.kind === listEndToken) { + // consume the list end token only if it is still belong to the parent + // there might be the case when current token matches end token but does not considered as one + // function (x: function) <-- + // without this check close paren will be interpreted as list end token for function expression which is wrong + if (tokenInfo.token.kind === listEndToken && rangeContainsRange(parent, tokenInfo.token)) { // consume list end token consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation); } diff --git a/tests/cases/fourslash/formatEmptyParamList.ts b/tests/cases/fourslash/formatEmptyParamList.ts new file mode 100644 index 00000000000..5b207581d61 --- /dev/null +++ b/tests/cases/fourslash/formatEmptyParamList.ts @@ -0,0 +1,5 @@ +/// +////function f( f: function){/*1*/ +goTo.marker("1"); +edit.insert("}"); +verify.currentLineContentIs("function f(f: function){ }") \ No newline at end of file