@@ -1159,17 +1159,20 @@ namespace ts.formatting {
1159
1159
sourceFile : SourceFile ,
1160
1160
position : number ,
1161
1161
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
1163
1163
tokenAtPosition = getTokenAtPosition ( sourceFile , position , /*includeJsDocComment*/ false ) ,
1164
1164
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).
1173
1176
const trailingRangesOfPreviousToken = precedingToken && getTrailingCommentRanges ( sourceFile . text , precedingToken . end ) ;
1174
1177
const leadingCommentRangesOfNextToken = getLeadingCommentRangesOfNode ( tokenAtPosition , sourceFile ) ;
1175
1178
const commentRanges = trailingRangesOfPreviousToken && leadingCommentRangesOfNextToken ?
0 commit comments