feat(api-extractor): replace type parameters with their actual values on inherited members (#9939)

* refactor: use tokenRange for typeParams in heritage

* fix: correct type param replacement
This commit is contained in:
Qjuh
2023-11-11 15:18:08 +01:00
committed by GitHub
parent 5b0aa92c81
commit 5a4c9755c3
8 changed files with 116 additions and 89 deletions

View File

@@ -24,14 +24,12 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
return (
<span>
{excerpt.spannedTokens.map((token, idx) => {
// TODO: Real fix in api-extractor needed
const text = token.text.replaceAll('\n', '').replaceAll(/\s{2}$/g, '');
if (token.kind === ExcerptTokenKind.Reference) {
if (text in BuiltinDocumentationLinks) {
const href = BuiltinDocumentationLinks[text as keyof typeof BuiltinDocumentationLinks];
if (token.text in BuiltinDocumentationLinks) {
const href = BuiltinDocumentationLinks[token.text as keyof typeof BuiltinDocumentationLinks];
return (
<DocumentationLink key={`${text}-${idx}`} href={href}>
{text}
<DocumentationLink key={`${token.text}-${idx}`} href={href}>
{token.text}
</DocumentationLink>
);
}
@@ -45,20 +43,22 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
// dapi-types doesn't have routes for class members
// so we can assume this member is for an enum
if (meaning === 'member' && path && 'parent' in path) href += `/enum/${path.parent}#${path.component}`;
else if (meaning === 'type') href += `#${text}`;
else href += `/${meaning}/${text}`;
else if (meaning === 'type' || meaning === 'var') href += `#${token.text}`;
else href += `/${meaning}/${token.text}`;
return (
<DocumentationLink key={`${text}-${idx}`} href={href}>
{text}
<DocumentationLink key={`${token.text}-${idx}`} href={href}>
{token.text}
</DocumentationLink>
);
}
const item = model.resolveDeclarationReference(token.canonicalReference!, model).resolvedApiItem;
const item = token.canonicalReference
? model.resolveDeclarationReference(token.canonicalReference!, model).resolvedApiItem
: null;
if (!item) {
return text;
return token.text;
}
return (
@@ -68,12 +68,12 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
key={`${item.displayName}-${item.containerKey}-${idx}`}
packageName={item.getAssociatedPackage()?.displayName.replace('@discordjs/', '')}
>
{text}
{token.text}
</ItemLink>
);
}
return text.replace(/import\("discord-api-types(?:\/v\d+)?"\)\./, '');
return token.text.replace(/import\("discord-api-types(?:\/v\d+)?"\)\./, '');
})}
</span>
);

View File

@@ -127,7 +127,7 @@ export function TableOfContentItems({ serializedMembers }: TableOfContentsItemPr
<div className="flex flex-row place-items-center gap-4">
<VscSymbolEvent size={20} />
<div className="p-3 pl-0">
<span className="font-semibold">Properties</span>
<span className="font-semibold">Events</span>
</div>
</div>
{eventItems}