mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
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:
committed by
GitHub
parent
854cec7387
commit
c4fd0028f5
@@ -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}}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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("}"));
|
||||
|
||||
Reference in New Issue
Block a user