Skip to content

Commit 22eb519

Browse files
Return empty doc comment instead of undefined
1 parent b5f292d commit 22eb519

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/services/jsDoc.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,24 +188,26 @@ namespace ts.JsDoc {
188188
* be performed.
189189
*/
190190
export function getDocCommentTemplateAtPosition(newLine: string, sourceFile: SourceFile, position: number): TextInsertion {
191+
const emptyDocComment = { newText: "", caretOffset: 0 };
192+
191193
// Check if in a context where we don't want to perform any insertion
192194
if (isInString(sourceFile, position) || isInComment(sourceFile, position) || hasDocComment(sourceFile, position)) {
193-
return undefined;
195+
return emptyDocComment;
194196
}
195197

196198
const tokenAtPos = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false);
197199
const tokenStart = tokenAtPos.getStart();
198200
if (!tokenAtPos || tokenStart < position) {
199-
return undefined;
201+
return emptyDocComment;
200202
}
201203

202204
const commentOwnerInfo = getCommentOwnerInfo(tokenAtPos);
203205
if (!commentOwnerInfo) {
204-
return undefined;
206+
return emptyDocComment;
205207
}
206208
const { commentOwner, parameters } = commentOwnerInfo;
207209
if (commentOwner.getStart() < position) {
208-
return undefined;
210+
return emptyDocComment;
209211
}
210212

211213
const posLineAndChar = sourceFile.getLineAndCharacterOfPosition(position);

0 commit comments

Comments
 (0)