mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06: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:
parent
5d2e62a810
commit
7b764164ed
@ -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;
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
/////** */
|
||||
/////*/**/
|
||||
////function foo() {}
|
||||
|
||||
verify.docCommentTemplateAt("", 3, "/** */");
|
||||
@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
/////** */
|
||||
/////**
|
||||
//// *
|
||||
//// * @param p
|
||||
//// */
|
||||
/////** */
|
||||
/////*/**/
|
||||
////function foo(p) {}
|
||||
|
||||
verify.docCommentTemplateAt("", 3, "/** */");
|
||||
Loading…
x
Reference in New Issue
Block a user