Skip to content

Commit 5ea03d8

Browse files
authored
chore(repo): Render accessors to markdown in the same fashion as properties for typedoc (#6532)
1 parent d2b41d5 commit 5ea03d8

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

.changeset/old-dolls-smell.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.typedoc/custom-theme.mjs

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,69 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
218218
const customizedModel = model;
219219
customizedModel.typeParameters = undefined;
220220

221-
const output = superPartials.memberWithGroups(customizedModel, options);
221+
// Extract the Accessors group (if any) and prevent default rendering for it
222+
const originalGroups = customizedModel.groups;
223+
const accessorsGroup = originalGroups?.find(g => g.title === 'Accessors');
224+
const groupsWithoutAccessors = originalGroups?.filter(g => g.title !== 'Accessors');
225+
226+
customizedModel.groups = groupsWithoutAccessors;
227+
const nonAccessorOutput = superPartials.memberWithGroups(customizedModel, options);
228+
customizedModel.groups = originalGroups;
229+
230+
/** @type {string[]} */
231+
const md = [nonAccessorOutput];
232+
233+
if (accessorsGroup && accessorsGroup.children && accessorsGroup.children.length > 0) {
234+
md.push('\n\n## Accessors\n');
235+
// Table header
236+
// This needs to be 'Property' instead of 'Accessor' so that clerk.com renders it correctly
237+
md.push('| Property | Type | Description |');
238+
md.push('| --- | --- | --- |');
239+
240+
for (const child of accessorsGroup.children) {
241+
/** @type {import('typedoc').DeclarationReflection} */
242+
// @ts-ignore - child is a DeclarationReflection for accessor members
243+
const decl = child;
244+
// Name and anchor id
245+
const name = decl.name;
246+
const id = name.toLowerCase().replace(/[^a-z0-9]/g, '');
247+
248+
// Resolve the accessor type from the getter signature
249+
/** @type {any} */
250+
const getterSig = /** @type {any} */ (decl).getSignature;
251+
/** @type {any} */
252+
const setterSig = /** @type {any} */ (decl).setSignature;
253+
let typeStr = '';
254+
if (getterSig?.type) {
255+
typeStr = this.partials.someType(getterSig.type);
256+
} else if (setterSig?.parameters?.[0]?.type) {
257+
typeStr = this.partials.someType(setterSig.parameters[0].type);
258+
} else if (decl.type) {
259+
typeStr = this.partials.someType(decl.type);
260+
}
222261

223-
return output;
262+
// Prefer comment on the getter signature; fallback to declaration comment
263+
const summary = getterSig?.comment?.summary ?? decl.comment?.summary ?? setterSig?.comment?.summary;
264+
const description = Array.isArray(summary)
265+
? summary.reduce((acc, curr) => acc + (curr.text || ''), '')
266+
: '';
267+
268+
md.push(`| <a id="${id}"></a> \`${escapeChars(name)}\` | ${typeStr} | ${description} |`);
269+
}
270+
}
271+
272+
return md.join('\n');
273+
},
274+
/**
275+
* Suppress default per-accessor member rendering; table is rendered in memberWithGroups instead.
276+
* @param {import('typedoc').DeclarationReflection} model
277+
* @param {{ headingLevel: number, nested?: boolean }} options
278+
*/
279+
member: (model, options) => {
280+
if (model.kind === ReflectionKind.Accessor) {
281+
return '';
282+
}
283+
return superPartials.member(model, options);
224284
},
225285
/**
226286
* This hides the "Type parameters" section and the declaration title from the output
@@ -412,6 +472,17 @@ ${tabs}
412472
* Hide "Extends" and "Extended by" sections
413473
*/
414474
hierarchy: () => '',
475+
/**
476+
* @param {import('typedoc').DeclarationReflection} model
477+
*/
478+
accessor: model => {
479+
// Fallback single-row rendering if used directly elsewhere
480+
const name = model.name;
481+
const typeStr = model.getSignature?.type ? this.partials.someType(model.getSignature.type) : '';
482+
const summary = model.getSignature?.comment?.summary ?? model.comment?.summary;
483+
const description = Array.isArray(summary) ? summary.reduce((acc, curr) => acc + (curr.text || ''), '') : '';
484+
return '| ' + '`' + escapeChars(name) + '`' + ' | ' + typeStr + ' | ' + description + ' |';
485+
},
415486
};
416487
}
417488
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"test:integration:vue": "E2E_APP_ID=vue.vite pnpm test:integration:base --grep @vue",
5454
"test:typedoc": "pnpm typedoc:generate && cd ./.typedoc && vitest run",
5555
"turbo:clean": "turbo daemon clean",
56-
"typedoc:generate": "pnpm build:declarations && typedoc --tsconfig tsconfig.typedoc.json && rm -rf .typedoc/docs && mv .typedoc/temp-docs .typedoc/docs",
56+
"typedoc:generate": "pnpm build:declarations && pnpm typedoc:generate:skip-build",
57+
"typedoc:generate:skip-build": "typedoc --tsconfig tsconfig.typedoc.json && rm -rf .typedoc/docs && mv .typedoc/temp-docs .typedoc/docs",
5758
"version-packages": "changeset version && pnpm install --lockfile-only --engine-strict=false",
5859
"version-packages:canary": "./scripts/canary.mjs",
5960
"version-packages:snapshot": "./scripts/snapshot.mjs",

0 commit comments

Comments
 (0)