Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(website): always link in TypeAlias #10105

Merged
merged 4 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useMemo } from 'react';
import { ExcerptText } from '~/components/ExcerptText';
import { DocumentationSection } from './DocumentationSection';

export type UnionMember = ExcerptToken[];
export type UnionMember = readonly ExcerptToken[];

export function UnionMembersSection({
item,
Expand Down
4 changes: 2 additions & 2 deletions apps/website/src/components/documentation/tsdoc/TSDoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export function TSDoc({ item, tsdoc }: { readonly item: ApiItem; readonly tsdoc:
case DocNodeKind.Section:
case DocNodeKind.Paragraph:
return (
<span className="break-words leading-relaxed" key={idx}>
<div className="break-words leading-relaxed" key={idx}>
{(tsdoc as DocNodeContainer).nodes.map((node, idx) => createNode(node, idx))}
</span>
</div>
);
case DocNodeKind.SoftBreak:
return <Fragment key={idx} />;
Expand Down
12 changes: 3 additions & 9 deletions apps/website/src/components/model/TypeAlias.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@ export function TypeAlias({ item }: { readonly item: ApiTypeAlias }) {
let depth = 0;
for (const token of item.typeExcerpt.spannedTokens) {
if (token.text.includes('?')) {
return [];
return [item.typeExcerpt.spannedTokens];
}

if (token.text.includes('<')) {
depth++;
}

if (token.text.includes('>')) {
depth--;
}
depth += token.text.split('<').length - token.text.split('>').length;

if (token.text.trim() === '|' && depth === 0) {
if (currentUnionMember.length) {
Expand All @@ -47,7 +41,7 @@ export function TypeAlias({ item }: { readonly item: ApiTypeAlias }) {
}
}

if (currentUnionMember.length && union.length) {
if (currentUnionMember.length) {
union.push(currentUnionMember);
}

Expand Down
28 changes: 15 additions & 13 deletions packages/api-extractor/src/generators/ApiModelGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1690,20 +1690,22 @@ export class ApiModelGenerator {
}

private _fixLinkTags(input?: string): string | undefined {
return input?.replaceAll(linkRegEx, (_match, _p1, _p2, _p3, _p4, _p5, _offset, _string, groups) => {
let target = groups.class ?? groups.url;
const external = this._jsDocJson?.externals.find((external) => groups.class && external.name === groups.class);
const match = /discord-api-types-(?<type>[^#]*?)(?:#|\/(?<kind>[^#/]*)\/)(?<name>[^/}]*)}$/.exec(
external?.see?.[0] ?? '',
);
if (match) {
target = `discord-api-types#(${match.groups!.name}:${
/^v\d+$/.test(match.groups!.type!) ? match.groups!.kind : 'type'
})`;
}
return input
?.replaceAll(linkRegEx, (_match, _p1, _p2, _p3, _p4, _p5, _offset, _string, groups) => {
let target = groups.class ?? groups.url;
const external = this._jsDocJson?.externals.find((external) => groups.class && external.name === groups.class);
const match = /discord-api-types-(?<type>[^#]*?)(?:#|\/(?<kind>[^#/]*)\/)(?<name>[^/}]*)}$/.exec(
external?.see?.[0] ?? '',
);
if (match) {
target = `discord-api-types#(${match.groups!.name}:${
/^v\d+$/.test(match.groups!.type!) ? match.groups!.kind : 'type'
})`;
}

return `{@link ${target}${groups.prop ? `.${groups.prop}` : ''}${groups.name ? ` |${groups.name}` : ''}}`;
});
return `{@link ${target}${groups.prop ? `.${groups.prop}` : ''}${groups.name ? ` |${groups.name}` : ''}}`;
})
.replaceAll('* ', '\n * * ');
}

private _mapVarType(typey: DocgenVarTypeJson): IExcerptToken[] {
Expand Down
Loading