mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-16 06:28:12 -05:00
Fixed closing JSDoc when adding multiple blocks (#49888)
* Fixed closing JSDoc when adding multiple blocks * Fixed linting errors * Refactored to use `some` Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> * Removed empty lines Co-authored-by: Armando Aguirre <araguir@microsoft.com> Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
@@ -357,8 +357,12 @@ namespace ts.JsDoc {
|
||||
}
|
||||
|
||||
const { commentOwner, parameters, hasReturn } = commentOwnerInfo;
|
||||
const commentOwnerJSDoc = hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? lastOrUndefined(commentOwner.jsDoc) : undefined;
|
||||
if (commentOwner.getStart(sourceFile) < position || commentOwnerJSDoc && commentOwnerJSDoc !== existingDocComment) {
|
||||
const commentOwnerJsDoc = hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? commentOwner.jsDoc : undefined;
|
||||
const lastJsDoc = lastOrUndefined(commentOwnerJsDoc);
|
||||
if (commentOwner.getStart(sourceFile) < position
|
||||
|| lastJsDoc
|
||||
&& existingDocComment
|
||||
&& lastJsDoc !== existingDocComment) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -378,7 +382,11 @@ namespace ts.JsDoc {
|
||||
// * if the caret was directly in front of the object, then we add an extra line and indentation.
|
||||
const openComment = "/**";
|
||||
const closeComment = " */";
|
||||
if (tags) {
|
||||
|
||||
// If any of the existing jsDoc has tags, ignore adding new ones.
|
||||
const hasTag = (commentOwnerJsDoc || []).some(jsDoc => !!jsDoc.tags);
|
||||
|
||||
if (tags && !hasTag) {
|
||||
const preamble = openComment + newLine + indentationStr + " * ";
|
||||
const endLine = tokenStart === position ? newLine + indentationStr : "";
|
||||
const result = preamble + newLine + tags + indentationStr + closeComment + endLine;
|
||||
|
||||
Reference in New Issue
Block a user