Fix @link https:// formatting (#47705)

* Fix @link https:// formatting

Also improve .d.ts formatting of `@link`,`@linkcode`,`@linkplain`.

Fixes #46734

1. Previously, `@link` incorrectly put a space between "https" and "://"
when formatting jsdoc for editors. Now it does not.
2. When fixing the same output for .d.ts, I discovered that all `@link` tags
were formatted as `@link`, even if they were `@linkcode` or
`@linkplain`. I fixed that too.

* semicolon lint
This commit is contained in:
Nathan Shively-Sanders
2022-02-02 14:00:08 -08:00
committed by GitHub
parent 854cec7387
commit c4fd0028f5
8 changed files with 181 additions and 4 deletions

View File

@@ -905,9 +905,16 @@ namespace ts {
/** Gets the text of a jsdoc comment, flattening links to their text. */
export function getTextOfJSDocComment(comment?: string | NodeArray<JSDocComment>) {
return typeof comment === "string" ? comment
: comment?.map(c =>
// TODO: Other kinds here
c.kind === SyntaxKind.JSDocText ? c.text : `{@link ${c.name ? entityNameToString(c.name) + " " : ""}${c.text}}`).join("");
: comment?.map(c => c.kind === SyntaxKind.JSDocText ? c.text : formatJSDocLink(c)).join("");
}
function formatJSDocLink(link: JSDocLink | JSDocLinkCode | JSDocLinkPlain) {
const kind = link.kind === SyntaxKind.JSDocLink ? "link"
: link.kind === SyntaxKind.JSDocLinkCode ? "linkcode"
: "linkplain";
const name = link.name ? entityNameToString(link.name) : "";
const space = link.name && link.text.startsWith("://") ? "" : " ";
return `{@${kind} ${name}${space}${link.text}}`;
}
/**

View File

@@ -2320,7 +2320,7 @@ namespace ts {
if (text) parts.push(linkTextPart(text));
}
else {
parts.push(linkTextPart(name + (suffix ? "" : " ") + text));
parts.push(linkTextPart(name + (suffix || text.indexOf("://") === 0 ? "" : " ") + text));
}
}
parts.push(linkPart("}"));