@@ -1146,48 +1146,35 @@ namespace ts.formatting {
1146
1146
export function getRangeOfEnclosingComment (
1147
1147
sourceFile : SourceFile ,
1148
1148
position : number ,
1149
- onlyMultiLine : boolean ,
1150
1149
precedingToken ?: Node | null , // tslint:disable-line:no-null-keyword
1151
- tokenAtPosition = getTokenAtPosition ( sourceFile , position , /*includeJsDocComment*/ false ) ,
1152
- predicate ?: ( c : CommentRange ) => boolean ) : CommentRange | undefined {
1150
+ tokenAtPosition = getTokenAtPosition ( sourceFile , position , /*includeJsDocComment*/ false ) ) : CommentRange | undefined {
1153
1151
const tokenStart = tokenAtPosition . getStart ( sourceFile ) ;
1154
1152
if ( tokenStart <= position && position < tokenAtPosition . getEnd ( ) ) {
1155
1153
return undefined ;
1156
1154
}
1157
1155
1158
- if ( precedingToken === undefined ) {
1159
- precedingToken = findPrecedingToken ( position , sourceFile ) ;
1160
- }
1156
+ precedingToken = precedingToken === null ? undefined : precedingToken === undefined ? findPrecedingToken ( position , sourceFile ) : precedingToken ; //neater
1161
1157
1162
1158
// Between two consecutive tokens, all comments are either trailing on the former
1163
1159
// or leading on the latter (and none are in both lists).
1164
1160
const trailingRangesOfPreviousToken = precedingToken && getTrailingCommentRanges ( sourceFile . text , precedingToken . end ) ;
1165
1161
const leadingCommentRangesOfNextToken = getLeadingCommentRangesOfNode ( tokenAtPosition , sourceFile ) ;
1166
- const commentRanges = trailingRangesOfPreviousToken && leadingCommentRangesOfNextToken ?
1167
- trailingRangesOfPreviousToken . concat ( leadingCommentRangesOfNextToken ) :
1168
- trailingRangesOfPreviousToken || leadingCommentRangesOfNextToken ;
1169
- if ( commentRanges ) {
1170
- for ( const range of commentRanges ) {
1171
- // The end marker of a single-line comment does not include the newline character.
1172
- // With caret at `^`, in the following case, we are inside a comment (^ denotes the cursor position):
1173
- //
1174
- // // asdf ^\n
1175
- //
1176
- // But for closed multi-line comments, we don't want to be inside the comment in the following case:
1177
- //
1178
- // /* asdf */^
1179
- //
1180
- // However, unterminated multi-line comments *do* contain their end.
1181
- //
1182
- // Internally, we represent the end of the comment at the newline and closing '/', respectively.
1183
- //
1184
- if ( ( range . pos < position && position < range . end ||
1185
- position === range . end && ( range . kind === SyntaxKind . SingleLineCommentTrivia || position === sourceFile . getFullWidth ( ) ) ) ) {
1186
- return ( range . kind === SyntaxKind . MultiLineCommentTrivia || ! onlyMultiLine ) && ( ! predicate || predicate ( range ) ) ? range : undefined ;
1187
- }
1188
- }
1189
- }
1190
- return undefined ;
1162
+ const commentRanges = concatenate ( trailingRangesOfPreviousToken , leadingCommentRangesOfNextToken ) ;
1163
+ return commentRanges && find ( commentRanges , range => rangeContainsPositionExclusive ( range , position ) ||
1164
+ // The end marker of a single-line comment does not include the newline character.
1165
+ // With caret at `^`, in the following case, we are inside a comment (^ denotes the cursor position):
1166
+ //
1167
+ // // asdf ^\n
1168
+ //
1169
+ // But for closed multi-line comments, we don't want to be inside the comment in the following case:
1170
+ //
1171
+ // /* asdf */^
1172
+ //
1173
+ // However, unterminated multi-line comments *do* contain their end.
1174
+ //
1175
+ // Internally, we represent the end of the comment at the newline and closing '/', respectively.
1176
+ //
1177
+ position === range . end && ( range . kind === SyntaxKind . SingleLineCommentTrivia || position === sourceFile . getFullWidth ( ) ) ) ;
1191
1178
}
1192
1179
1193
1180
function getOpenTokenForList ( node : Node , list : ReadonlyArray < Node > ) {
0 commit comments