mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
feat(website): show descriptions for @typeParam blocks (#8523)
This commit is contained in:
@@ -1,6 +1,32 @@
|
||||
import type { ApiItem, ApiModel, ApiTypeParameterListMixin } from '@microsoft/api-extractor-model';
|
||||
import type { ApiItem, ApiModel, ApiTypeParameterListMixin, TypeParameter } from '@microsoft/api-extractor-model';
|
||||
import type { DocItemConstructor } from './DocItem';
|
||||
import { generateTypeParamData, TypeParameterData } from '~/util/parse.server';
|
||||
import { block, DocBlockJSON } from './comment/CommentBlock';
|
||||
import { genToken, TokenDocumentation } from '~/util/parse.server';
|
||||
|
||||
export interface TypeParameterData {
|
||||
name: string;
|
||||
constraintTokens: TokenDocumentation[];
|
||||
defaultTokens: TokenDocumentation[];
|
||||
optional: boolean;
|
||||
commentBlock: DocBlockJSON | null;
|
||||
}
|
||||
|
||||
export function generateTypeParamData(
|
||||
model: ApiModel,
|
||||
typeParam: TypeParameter,
|
||||
parentItem?: ApiItem,
|
||||
): TypeParameterData {
|
||||
const constraintTokens = typeParam.constraintExcerpt.spannedTokens.map((token) => genToken(model, token));
|
||||
const defaultTokens = typeParam.defaultTypeExcerpt.spannedTokens.map((token) => genToken(model, token));
|
||||
|
||||
return {
|
||||
name: typeParam.name,
|
||||
constraintTokens,
|
||||
defaultTokens,
|
||||
optional: typeParam.isOptional,
|
||||
commentBlock: typeParam.tsdocTypeParamBlock ? block(typeParam.tsdocTypeParamBlock, model, parentItem) : null,
|
||||
};
|
||||
}
|
||||
|
||||
export function TypeParameterMixin<TBase extends DocItemConstructor>(Base: TBase) {
|
||||
return class Mixed extends Base {
|
||||
@@ -10,7 +36,7 @@ export function TypeParameterMixin<TBase extends DocItemConstructor>(Base: TBase
|
||||
public constructor(model: ApiModel, item: ApiItem) {
|
||||
super(model, item);
|
||||
this.typeParameters = (item as ApiTypeParameterListMixin).typeParameters.map((typeParam) =>
|
||||
generateTypeParamData(this.model, typeParam),
|
||||
generateTypeParamData(this.model, typeParam, item.parent),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,7 @@ export function genToken(
|
||||
ref: DocDeclarationReference,
|
||||
context: ApiItem | null,
|
||||
): LinkTagCodeLink | null {
|
||||
if (!context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const item = model.resolveDeclarationReference(ref, context).resolvedApiItem ?? null;
|
||||
const item = model.resolveDeclarationReference(ref, context ?? undefined).resolvedApiItem ?? null;
|
||||
|
||||
if (!item) {
|
||||
return null;
|
||||
@@ -38,8 +34,14 @@ export interface LinkTagCodeLink {
|
||||
}
|
||||
|
||||
export function linkTagNode(linkNode: DocLinkTag, model: ApiModel, parentItem?: ApiItem): DocLinkTagJSON {
|
||||
const codeDestination =
|
||||
linkNode.codeDestination && parentItem ? genToken(model, linkNode.codeDestination, parentItem) : null;
|
||||
// If we weren't provided a parent object, fallback to the package entrypoint.
|
||||
const packageEntryPoint = linkNode.codeDestination?.importPath
|
||||
? model.getAssociatedPackage()?.findEntryPointsByPath(linkNode.codeDestination.importPath)[0]
|
||||
: null;
|
||||
|
||||
const codeDestination = linkNode.codeDestination
|
||||
? genToken(model, linkNode.codeDestination, parentItem ?? packageEntryPoint ?? null)
|
||||
: null;
|
||||
const text = linkNode.linkText ?? null;
|
||||
const urlDestination = linkNode.urlDestination ?? null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user