@@ -254,6 +254,33 @@ async function renderJsDocTags(tags: JsDocTag[], symbolLookup: SymbolLookup): Pr
254254// Member Rendering
255255// =============================================================================
256256
257+ type DefinitionListItem = {
258+ signature : string
259+ description ?: string
260+ }
261+
262+ function renderMemberList ( title : string , items : DefinitionListItem [ ] ) : string {
263+ const lines : string [ ] = [ ]
264+
265+ if ( items . length === 0 ) {
266+ return ''
267+ }
268+
269+ lines . push ( `<div class="docs-members">` )
270+ lines . push ( `<h4>${ title } </h4>` )
271+ lines . push ( `<dl>` )
272+ for ( const item of items ) {
273+ lines . push ( `<dt><code>${ escapeHtml ( item . signature ) } </code></dt>` )
274+ if ( item . description ) {
275+ lines . push ( `<dd>${ escapeHtml ( item . description . split ( '\n' ) [ 0 ] ?? '' ) } </dd>` )
276+ }
277+ }
278+ lines . push ( `</dl>` )
279+ lines . push ( `</div>` )
280+
281+ return lines . join ( '\n' )
282+ }
283+
257284/**
258285 * Render class members (constructor, properties, methods).
259286 */
@@ -272,44 +299,54 @@ function renderClassMembers(def: NonNullable<DenoDocNode['classDef']>): string {
272299 }
273300
274301 if ( properties && properties . length > 0 ) {
275- lines . push ( `<div class="docs-members">` )
276- lines . push ( `<h4>Properties</h4>` )
277- lines . push ( `<dl>` )
278- for ( const prop of properties ) {
302+ const propertyItems : DefinitionListItem [ ] = properties . map ( prop => {
279303 const modifiers : string [ ] = [ ]
280304 if ( prop . isStatic ) modifiers . push ( 'static' )
281305 if ( prop . readonly ) modifiers . push ( 'readonly' )
282306 const modStr = modifiers . length > 0 ? `${ modifiers . join ( ' ' ) } ` : ''
283307 const type = formatType ( prop . tsType )
284308 const opt = prop . optional ? '?' : ''
285- lines . push (
286- `<dt><code> ${ escapeHtml ( modStr ) } ${ escapeHtml ( prop . name ) } ${ opt } : ${ escapeHtml ( type ) } </code></dt>` ,
287- )
288- if ( prop . jsDoc ?. doc ) {
289- lines . push ( `<dd> ${ escapeHtml ( prop . jsDoc . doc . split ( '\n' ) [ 0 ] ?? '' ) } </dd>` )
309+ const typeStr = type ? `: ${ type } ` : ''
310+
311+ return {
312+ signature : ` ${ modStr } ${ prop . name } ${ opt } ${ typeStr } ` ,
313+ description : prop . jsDoc ? .doc ,
290314 }
291- }
292- lines . push ( `</dl>` )
293- lines . push ( `</div>` )
315+ } )
316+
317+ lines . push ( renderMemberList ( 'Properties' , propertyItems ) )
294318 }
295319
296- if ( methods && methods . length > 0 ) {
297- lines . push ( `<div class="docs-members">` )
298- lines . push ( `<h4>Methods</h4>` )
299- lines . push ( `<dl>` )
300- for ( const method of methods ) {
320+ const getters = methods ?. filter ( m => m . kind === 'getter' ) || [ ]
321+ const regularMethods = methods ?. filter ( m => m . kind !== 'getter' ) || [ ]
322+
323+ if ( getters . length > 0 ) {
324+ const getterItems : DefinitionListItem [ ] = getters . map ( getter => {
325+ const ret = formatType ( getter . functionDef ?. returnType ) || 'unknown'
326+ const staticStr = getter . isStatic ? 'static ' : ''
327+
328+ return {
329+ signature : `${ staticStr } get ${ getter . name } : ${ ret } ` ,
330+ description : getter . jsDoc ?. doc ,
331+ }
332+ } )
333+
334+ lines . push ( renderMemberList ( 'Getters' , getterItems ) )
335+ }
336+
337+ if ( regularMethods . length > 0 ) {
338+ const methodItems : DefinitionListItem [ ] = regularMethods . map ( method => {
301339 const params = method . functionDef ?. params ?. map ( p => formatParam ( p ) ) . join ( ', ' ) || ''
302340 const ret = formatType ( method . functionDef ?. returnType ) || 'void'
303341 const staticStr = method . isStatic ? 'static ' : ''
304- lines . push (
305- `<dt><code>${ escapeHtml ( staticStr ) } ${ escapeHtml ( method . name ) } (${ escapeHtml ( params ) } ): ${ escapeHtml ( ret ) } </code></dt>` ,
306- )
307- if ( method . jsDoc ?. doc ) {
308- lines . push ( `<dd>${ escapeHtml ( method . jsDoc . doc . split ( '\n' ) [ 0 ] ?? '' ) } </dd>` )
342+
343+ return {
344+ signature : `${ staticStr } ${ method . name } (${ params } ): ${ ret } ` ,
345+ description : method . jsDoc ?. doc ,
309346 }
310- }
311- lines . push ( `</dl>` )
312- lines . push ( `</div>` )
347+ } )
348+
349+ lines . push ( renderMemberList ( 'Methods' , methodItems ) )
313350 }
314351
315352 return lines . join ( '\n' )
0 commit comments