Skip to content

Commit e4e969a

Browse files
committed
respond to comments
1 parent e7d2af0 commit e4e969a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/services/formatting/formatting.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,17 +1159,20 @@ namespace ts.formatting {
11591159
sourceFile: SourceFile,
11601160
position: number,
11611161
onlyMultiLine: boolean,
1162-
precedingToken: Node | null | undefined = findPrecedingToken(position, sourceFile), // tslint:disable-line:no-null-keyword
1162+
precedingToken?: Node | null, // tslint:disable-line:no-null-keyword
11631163
tokenAtPosition = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false),
11641164
predicate?: (c: CommentRange) => boolean): CommentRange | undefined {
1165-
// Considering a fixed position,
1166-
// - trailing comments are those following and on the same line as the position.
1167-
// - leading comments are those in the range [position, start of next non-trivia token)
1168-
// that are not trailing comments of that position.
1169-
//
1170-
// Note, `node.start` is the start-position of the first comment following the previous
1171-
// token that is not a trailing comment, so the leading and trailing comments of all
1172-
// tokens contain all comments in a sourcefile disjointly.
1165+
const tokenStart = tokenAtPosition.getStart(sourceFile);
1166+
if (tokenStart <= position && position < tokenAtPosition.getEnd()) {
1167+
return undefined;
1168+
}
1169+
1170+
if (precedingToken === undefined) {
1171+
precedingToken = findPrecedingToken(position, sourceFile);
1172+
}
1173+
1174+
// Between two consecutive tokens, all comments are either trailing on the former
1175+
// or leading on the latter (and none are in both lists).
11731176
const trailingRangesOfPreviousToken = precedingToken && getTrailingCommentRanges(sourceFile.text, precedingToken.end);
11741177
const leadingCommentRangesOfNextToken = getLeadingCommentRangesOfNode(tokenAtPosition, sourceFile);
11751178
const commentRanges = trailingRangesOfPreviousToken && leadingCommentRangesOfNextToken ?

0 commit comments

Comments
 (0)