mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
docs(docs-infra): wrap getTextOfJSDocComment
This commits adds a wrapper around `ts.getTextOfJSDocComment` because of bugs that won't be fixed by the TS team (see microsoft/TypeScript#63027)
This commit is contained in:
committed by
Leon Senft
parent
6990f88d97
commit
72dfb4d92a
@@ -24,13 +24,42 @@ export function extractJsDocTags(node: ts.HasJSDoc): JsDocTagEntry[] {
|
||||
return ts.getJSDocTags(escapedNode).map((t) => {
|
||||
return {
|
||||
name: t.tagName.getText(),
|
||||
// In TS 5.9, ts.getTextOfJSDocComment still strips "http" from comments breaking any absolute links in @see blocks.
|
||||
// eg: @see https://angular.dev
|
||||
comment: unescapeAngularDecorators(ts.getTextOfJSDocComment(t.comment) ?? ''),
|
||||
comment: unescapeAngularDecorators(getJSDocTagComment(t) ?? ''),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the comment text from a JSDoc tag
|
||||
* This wrapper attemps to work around some TS bugs (microsoft/TypeScript#59679, microsoft/TypeScript#63027 etc).
|
||||
*/
|
||||
function getJSDocTagComment(tag: ts.JSDocTag): string | undefined {
|
||||
const comment = tag.comment;
|
||||
if (comment === undefined) return undefined;
|
||||
|
||||
// If the comment is a string, it might be the result of the TS 5.9 bug where "http" is stripped.
|
||||
if (typeof comment === 'string') {
|
||||
if (comment.startsWith('://')) {
|
||||
// Try to verify if we can recover "https" or "http" from the raw tag text.
|
||||
const rawText = tag.getText();
|
||||
if (rawText.includes('https' + comment)) {
|
||||
return 'https' + comment;
|
||||
}
|
||||
if (rawText.includes('http' + comment)) {
|
||||
return 'http' + comment;
|
||||
}
|
||||
}
|
||||
return comment;
|
||||
}
|
||||
|
||||
let text = ts.getTextOfJSDocComment(comment);
|
||||
// getTextOfJSDocComment introduces an extra space between the symbol and a trailing ()
|
||||
if (text) {
|
||||
text = text.replace(/ \(\)\}$/, '()}');
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the JsDoc description for a node. If the node does not have
|
||||
* a description, returns the empty string.
|
||||
|
||||
Reference in New Issue
Block a user