mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
feat(docgen): update typedoc
This commit is contained in:
@@ -121,7 +121,7 @@ export class Documentation {
|
||||
item = new DocumentedMember(member, this.config);
|
||||
break;
|
||||
}
|
||||
case 'event': {
|
||||
case 'Event': {
|
||||
item = new DocumentedEvent(member, this.config);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ export class DocumentedClass extends DocumentedItem<Class | DeclarationReflectio
|
||||
public override serializer() {
|
||||
if (this.config.typescript) {
|
||||
const data = this.data as DeclarationReflection;
|
||||
const signature = (data.signatures ?? [])[0] ?? data;
|
||||
let meta;
|
||||
|
||||
const sources = data.sources?.[0];
|
||||
@@ -87,25 +88,37 @@ export class DocumentedClass extends DocumentedItem<Class | DeclarationReflectio
|
||||
meta = new DocumentedItemMeta(sources, this.config).serialize();
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
// @ts-expect-error
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
name: data.name === 'default' ? parse(meta?.file ?? 'default').name : data.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
description: data.comment?.shortText?.trim(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
see: data.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
|
||||
name: signature.name === 'default' ? parse(meta?.file ?? 'default').name : signature.name,
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
description: signature.comment?.summary.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
extends: this.extends?.serialize(),
|
||||
implements: this.implements?.serialize(),
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
data.flags.isPrivate || data.comment?.tags?.some((t) => t.tagName === 'private' || t.tagName === 'internal')
|
||||
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/no-unnecessary-condition
|
||||
abstract: signature.comment?.blockTags?.some((t) => t.tag === '@abstract') || undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
abstract: data.comment?.tags?.some((t) => t.tagName === 'abstract'),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: data.comment?.tags?.some((t) => t.tagName === 'deprecated'),
|
||||
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
? signature.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
construct: this.construct?.serialize(),
|
||||
props: this.props.size ? this.props.map((p) => p.serialize()) : undefined,
|
||||
methods: this.methods.size ? this.methods.map((m) => m.serialize()) : undefined,
|
||||
|
||||
@@ -9,16 +9,22 @@ export class DocumentedConstructor extends DocumentedItem<Constructor | Declarat
|
||||
const data = this.data as DeclarationReflection;
|
||||
const signature = (data.signatures ?? [])[0] ?? data;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
name: data.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
description: signature.comment?.shortText?.trim(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
see: signature.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
|
||||
name: signature.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
signature.comment?.tags?.some((t) => t.tagName === 'private' || t.tagName === 'internal')
|
||||
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
// @ts-expect-error
|
||||
|
||||
@@ -16,14 +16,25 @@ export class DocumentedEvent extends DocumentedItem<Event | DeclarationReflectio
|
||||
meta = new DocumentedItemMeta(sources, this.config).serialize();
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
name: data.name,
|
||||
name: signature.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
description: signature.comment?.shortText?.trim(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
see: signature.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: signature.comment?.tags?.some((t) => t.tagName === 'deprecated'),
|
||||
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
? signature.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
// @ts-expect-error
|
||||
params: signature.parameters
|
||||
? (signature as SignatureReflection).parameters?.map((p) => new DocumentedParam(p, this.config).serialize())
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { basename, dirname, relative } from 'node:path';
|
||||
import { basename, relative } from 'node:path';
|
||||
import type { SourceReference } from 'typedoc';
|
||||
import { DocumentedItem } from './item.js';
|
||||
import type { Meta } from '../interfaces/index.js';
|
||||
@@ -11,7 +11,8 @@ export class DocumentedItemMeta extends DocumentedItem<Meta | SourceReference> {
|
||||
return {
|
||||
line: data.line,
|
||||
file: basename(data.fileName),
|
||||
path: dirname(data.fileName),
|
||||
path: undefined,
|
||||
url: data.url,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
|
||||
public override serializer() {
|
||||
if (this.config.typescript) {
|
||||
const data = this.data as DeclarationReflection;
|
||||
const signature = (data.signatures ?? [])[0] ?? data;
|
||||
let meta;
|
||||
|
||||
const sources = data.sources?.[0];
|
||||
@@ -17,28 +18,47 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
|
||||
meta = new DocumentedItemMeta(sources, this.config).serialize();
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
const base = {
|
||||
name: data.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
description: data.comment?.shortText?.trim(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
see: data.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
|
||||
name: signature.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
scope: data.flags.isStatic ? 'static' : undefined,
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
data.flags.isPrivate || data.comment?.tags?.some((t) => t.tagName === 'private' || t.tagName === 'internal')
|
||||
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
readonly: data.flags.isReadonly,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
abstract: signature.comment?.blockTags?.some((t) => t.tag === '@abstract') || undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
abstract: data.comment?.tags?.some((t) => t.tagName === 'abstract'),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: data.comment?.tags?.some((t) => t.tagName === 'deprecated'),
|
||||
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
? signature.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
data.comment?.tags?.find((t) => t.tagName === 'default')?.text.trim() ??
|
||||
(data.defaultValue === '...' ? undefined : data.defaultValue),
|
||||
type: data.type ? new DocumentedVarType({ names: [parseType(data.type)] }, this.config).serialize() : undefined,
|
||||
(data.defaultValue === '...' ? undefined : data.defaultValue) ??
|
||||
(signature.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@default')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
undefined),
|
||||
type: signature.type
|
||||
? new DocumentedVarType({ names: [parseType(signature.type)] }, this.config).serialize()
|
||||
: undefined,
|
||||
meta,
|
||||
};
|
||||
|
||||
@@ -50,28 +70,47 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
|
||||
throw new Error("Can't parse accessor without getter.");
|
||||
}
|
||||
|
||||
if (!hasSetter) base.readonly = true;
|
||||
if (!hasSetter) {
|
||||
base.readonly = true;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = getter.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
? getter.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
...base,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
description: getter.comment?.shortText?.trim(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
see: getter.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
description: getter.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
access:
|
||||
getter.flags.isPrivate ||
|
||||
getter.comment?.tags.some((t) => t.tagName === 'private' || t.tagName === 'internal')
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
getter.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
readonly: base.readonly || !hasSetter,
|
||||
abstract: getter.comment?.tags.some((t) => t.tagName === 'abstract'),
|
||||
deprecated: getter.comment?.tags.some((t) => t.tagName === 'deprecated'),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
abstract: getter.comment?.blockTags?.some((t) => t.tag === '@abstract') || undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: getter.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
? getter.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
default:
|
||||
base.default ??
|
||||
getter.comment?.tags.find((t) => t.tagName === 'default')?.text.trim() ??
|
||||
// @ts-expect-error
|
||||
getter.defaultValue,
|
||||
(getter.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@default')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
undefined),
|
||||
type: getter.type ? parseType(getter.type) : undefined,
|
||||
};
|
||||
}
|
||||
@@ -99,20 +138,3 @@ export class DocumentedMember extends DocumentedItem<Member | DeclarationReflect
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
{ id: 'Client#rest',
|
||||
longname: 'Client#rest',
|
||||
name: 'rest',
|
||||
scope: 'instance',
|
||||
kind: 'member',
|
||||
description: 'The REST manager of the client',
|
||||
memberof: 'Client',
|
||||
type: { names: [ 'RESTManager' ] },
|
||||
access: 'private',
|
||||
meta:
|
||||
{ lineno: 32,
|
||||
filename: 'Client.js',
|
||||
path: 'src/client' },
|
||||
order: 11 }
|
||||
*/
|
||||
|
||||
@@ -18,27 +18,44 @@ export class DocumentedMethod extends DocumentedItem<Method | DeclarationReflect
|
||||
meta = new DocumentedItemMeta(sources, this.config).serialize();
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const examples = signature.comment?.blockTags?.filter((t) => t.tag === '@example').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@example')
|
||||
.map((t) => t.content.reduce((prev, curr) => (prev += curr.text), '').trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
name: data.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
description: signature.comment?.shortText?.trim(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
see: signature.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
|
||||
name: signature.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
scope: data.flags.isStatic ? 'static' : undefined,
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
signature.comment?.tags?.some((t) => t.tagName === 'private' || t.tagName === 'internal')
|
||||
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
examples,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
abstract: signature.comment?.blockTags?.some((t) => t.tag === '@abstract') || undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
examples: signature.comment?.tags?.filter((t) => t.tagName === 'example').map((t) => t.text.trim()),
|
||||
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
? signature.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
abstract: signature.comment?.tags?.some((t) => t.tagName === 'abstract'),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: signature.comment?.tags?.some((t) => t.tagName === 'deprecated'),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
emits: signature.comment?.tags?.filter((t) => t.tagName === 'emits').map((t) => t.text.trim()),
|
||||
// emits: signature.comment?.blockTags?.filter((t) => t.tag === '@emits').map((t) => t.content),
|
||||
// @ts-expect-error
|
||||
params: signature.parameters
|
||||
? (signature as SignatureReflection).parameters?.map((p) => new DocumentedParam(p, this.config).serialize())
|
||||
@@ -46,12 +63,27 @@ export class DocumentedMethod extends DocumentedItem<Method | DeclarationReflect
|
||||
returns: signature.type
|
||||
? [
|
||||
new DocumentedVarType(
|
||||
{ names: [parseType(signature.type)], description: signature.comment?.returns?.trim() },
|
||||
{
|
||||
names: [parseType(signature.type)],
|
||||
description:
|
||||
signature.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
},
|
||||
this.config,
|
||||
).serialize(),
|
||||
]
|
||||
: undefined,
|
||||
returnsDescription: signature.comment?.returns?.trim(),
|
||||
returnsDescription:
|
||||
signature.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
meta,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,13 +11,18 @@ export class DocumentedParam extends DocumentedItem<Param | ParameterReflection>
|
||||
|
||||
return {
|
||||
name: data.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
description: data.comment?.shortText?.trim() ?? data.comment?.text.trim(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
description: data.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
optional: data.flags.isOptional || typeof data.defaultValue != 'undefined',
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
data.comment?.tags?.find((t) => t.tagName === 'default')?.text.trim() ??
|
||||
(data.defaultValue === '...' ? undefined : data.defaultValue),
|
||||
(data.defaultValue === '...' ? undefined : data.defaultValue) ??
|
||||
(data.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@default')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
undefined),
|
||||
variable: data.flags.isRest,
|
||||
type: data.type ? new DocumentedVarType({ names: [parseType(data.type)] }, this.config).serialize() : undefined,
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { DeclarationReflection } from 'typedoc';
|
||||
import type { DeclarationReflection, LiteralType } from 'typedoc';
|
||||
import { DocumentedItemMeta } from './item-meta.js';
|
||||
import { DocumentedItem } from './item.js';
|
||||
import { DocumentedParam } from './param.js';
|
||||
@@ -11,6 +11,7 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
public override serializer() {
|
||||
if (this.config.typescript) {
|
||||
const data = this.data as DeclarationReflection;
|
||||
const signature = (data.signatures ?? [])[0] ?? data;
|
||||
let meta;
|
||||
|
||||
const sources = data.sources?.[0];
|
||||
@@ -18,20 +19,34 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
meta = new DocumentedItemMeta(sources, this.config).serialize();
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = signature.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
? signature.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
const baseReturn = {
|
||||
name: data.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
description: data.comment?.shortText?.trim(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
see: data.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
|
||||
name: signature.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
description: signature.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
access:
|
||||
data.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
data.flags.isPrivate || data.comment?.tags?.some((t) => t.tagName === 'private' || t.tagName === 'internal')
|
||||
signature.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: data.comment?.tags?.some((t) => t.tagName === 'deprecated'),
|
||||
type: data.type ? new DocumentedVarType({ names: [parseType(data.type)] }, this.config).serialize() : undefined,
|
||||
deprecated: signature.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
? signature.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
type: signature.type
|
||||
? new DocumentedVarType({ names: [parseType(signature.type)] }, this.config).serialize()
|
||||
: undefined,
|
||||
meta,
|
||||
};
|
||||
|
||||
@@ -46,8 +61,13 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
props: data.children?.length
|
||||
? data.children.map((child) => ({
|
||||
name: child.name,
|
||||
description: child.comment?.shortText.trim(),
|
||||
type: typeof child.defaultValue == 'undefined' ? undefined : [[[child.defaultValue]]],
|
||||
description:
|
||||
child.comment?.summary
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
type: [[[(child.type as LiteralType | undefined)?.value]]],
|
||||
}))
|
||||
: undefined,
|
||||
};
|
||||
@@ -59,13 +79,25 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
if (children && children.length > 0) {
|
||||
const props = children.map((child) => ({
|
||||
name: child.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
description: child.comment?.shortText?.trim() ?? child.signatures?.[0]?.comment?.shortText?.trim(),
|
||||
description:
|
||||
child.comment?.summary
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
child.signatures?.[0]?.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() ||
|
||||
undefined,
|
||||
optional: child.flags.isOptional || typeof child.defaultValue != 'undefined',
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
child.comment?.tags?.find((t) => t.tagName === 'default')?.text.trim() ??
|
||||
(child.defaultValue === '...' ? undefined : child.defaultValue),
|
||||
(child.defaultValue === '...' ? undefined : child.defaultValue) ??
|
||||
(child.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@default')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
undefined),
|
||||
type: child.type
|
||||
? new DocumentedVarType({ names: [parseType(child.type)] }, this.config).serialize()
|
||||
: child.kindString === 'Method'
|
||||
@@ -77,6 +109,11 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
declaration: child,
|
||||
}),
|
||||
],
|
||||
description: child.signatures?.[0]?.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim(),
|
||||
},
|
||||
this.config,
|
||||
).serialize()
|
||||
@@ -94,42 +131,74 @@ export class DocumentedTypeDef extends DocumentedItem<Typedef | DeclarationRefle
|
||||
|
||||
const params = sig?.parameters?.map((param) => ({
|
||||
name: param.name,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
description: param.comment?.shortText?.trim(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
description: param.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
optional: param.flags.isOptional || typeof param.defaultValue != 'undefined',
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
param.comment?.tags?.find((t) => t.tagName === 'default')?.text.trim() ??
|
||||
(param.defaultValue === '...' ? undefined : param.defaultValue),
|
||||
(param.defaultValue === '...' ? undefined : param.defaultValue) ??
|
||||
(param.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@default')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() ||
|
||||
undefined),
|
||||
type: param.type
|
||||
? new DocumentedVarType({ names: [parseType(param.type)] }, this.config).serialize()
|
||||
: undefined,
|
||||
}));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
const see = sig?.comment?.blockTags?.filter((t) => t.tag === '@see').length
|
||||
? sig.comment.blockTags
|
||||
.filter((t) => t.tag === '@see')
|
||||
.map((t) => t.content.find((c) => c.kind === 'text')?.text.trim())
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
...baseReturn,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
description: sig?.comment?.shortText?.trim(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
see: sig?.comment?.tags?.filter((t) => t.tagName === 'see').map((t) => t.text.trim()),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing
|
||||
description: sig?.comment?.summary?.reduce((prev, curr) => (prev += curr.text), '').trim() || undefined,
|
||||
see,
|
||||
access:
|
||||
sig?.flags.isPrivate ||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
sig?.comment?.tags?.some((t) => t.tagName === 'private' || t.tagName === 'internal')
|
||||
sig?.comment?.blockTags?.some((t) => t.tag === '@private' || t.tag === '@internal')
|
||||
? 'private'
|
||||
: undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
deprecated: sig?.comment?.tags?.some((t) => t.tagName === 'deprecated'),
|
||||
deprecated: sig?.comment?.blockTags?.some((t) => t.tag === '@deprecated')
|
||||
? sig.comment.blockTags
|
||||
.find((t) => t.tag === '@deprecated')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
.trim() ?? true
|
||||
: undefined,
|
||||
params,
|
||||
returns: sig?.type
|
||||
? [
|
||||
new DocumentedVarType(
|
||||
{ names: [parseType(sig.type)], description: sig.comment?.returns?.trim() },
|
||||
{
|
||||
names: [parseType(sig.type)],
|
||||
description:
|
||||
sig.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
},
|
||||
this.config,
|
||||
).serialize(),
|
||||
]
|
||||
: undefined,
|
||||
returnsDescription: sig?.comment?.returns?.trim(),
|
||||
returnsDescription:
|
||||
sig?.comment?.blockTags
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
?.find((t) => t.tag === '@returns')
|
||||
?.content.reduce((prev, curr) => (prev += curr.text), '')
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
.trim() || undefined,
|
||||
meta,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user