1
- import type { DeclarationReflection , SignatureReflection } from "../../../../models/index.js" ;
2
- import type { SomeType , TypeVisitor } from "../../../../models/types.js" ;
1
+ import {
2
+ type Reflection ,
3
+ ReflectionKind ,
4
+ type DeclarationReflection ,
5
+ type SignatureReflection ,
6
+ } from "../../../../models/index.js" ;
7
+ import type { ReferenceType , SomeType , TypeVisitor } from "../../../../models/types.js" ;
3
8
import { JSX , Raw } from "../../../../utils/index.js" ;
4
9
import { classNames , getKindClass } from "../../lib.js" ;
5
10
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext.js" ;
@@ -17,6 +22,9 @@ const isUsefulVisitor: Partial<TypeVisitor<boolean>> = {
17
22
reflection ( type ) {
18
23
return renderingChildIsUseful ( type . declaration ) ;
19
24
} ,
25
+ reference ( type ) {
26
+ return shouldExpandReference ( type ) ;
27
+ } ,
20
28
} ;
21
29
22
30
function renderingTypeDetailsIsUseful ( type : SomeType ) {
@@ -35,6 +43,15 @@ export function typeDeclaration(context: DefaultThemeRenderContext, type: SomeTy
35
43
return null ;
36
44
}
37
45
46
+ const expanded = new Set < Reflection > ( ) ;
47
+ function shouldExpandReference ( reference : ReferenceType ) {
48
+ const target = reference . reflection ;
49
+ if ( ! target ?. kindOf ( ReflectionKind . TypeAlias | ReflectionKind . Interface ) ) return false ;
50
+ if ( ! target . comment ?. hasModifier ( "@expand" ) ) return false ;
51
+
52
+ return expanded . has ( target ) === false ;
53
+ }
54
+
38
55
export function typeDetails ( context : DefaultThemeRenderContext , type : SomeType ) : JSX . Children {
39
56
return type . visit < JSX . Children > ( {
40
57
array ( type ) {
@@ -58,42 +75,18 @@ export function typeDetails(context: DefaultThemeRenderContext, type: SomeType):
58
75
} ,
59
76
reflection ( type ) {
60
77
const declaration = type . declaration ;
61
-
62
- return (
63
- < ul class = "tsd-parameters" >
64
- { declaration . signatures && (
65
- < li class = "tsd-parameter-signature" >
66
- < ul
67
- class = { classNames (
68
- { "tsd-signatures" : true } ,
69
- context . getReflectionClasses ( declaration ) ,
70
- ) }
71
- >
72
- { declaration . signatures . map ( ( item ) => (
73
- < >
74
- < li class = "tsd-signature" id = { item . anchor } >
75
- { context . memberSignatureTitle ( item , {
76
- hideName : true ,
77
- } ) }
78
- </ li >
79
- < li class = "tsd-description" >
80
- { context . memberSignatureBody ( item , {
81
- hideSources : true ,
82
- } ) }
83
- </ li >
84
- </ >
85
- ) ) }
86
- </ ul >
87
- </ li >
88
- ) }
89
- { declaration . indexSignatures ?. map ( ( index ) => renderIndexSignature ( context , index ) ) }
90
- { declaration . children ?. map ( ( child ) => renderChild ( context , child ) ) }
91
- </ ul >
92
- ) ;
78
+ return declarationDetails ( context , declaration ) ;
93
79
} ,
94
- reference ( ) {
95
- // TODO: Check for @expand
96
- return null ;
80
+ reference ( reference ) {
81
+ if ( shouldExpandReference ( reference ) ) {
82
+ const target = reference . reflection as DeclarationReflection ;
83
+
84
+ // Ensure we don't go into an infinite loop here
85
+ expanded . add ( target ) ;
86
+ const details = target . type ? typeDetails ( context , target . type ) : declarationDetails ( context , target ) ;
87
+ expanded . delete ( target ) ;
88
+ return details ;
89
+ }
97
90
} ,
98
91
// tuple??
99
92
} ) ;
@@ -105,6 +98,38 @@ export function typeDetailsIfUseful(context: DefaultThemeRenderContext, type: So
105
98
}
106
99
}
107
100
101
+ function declarationDetails ( context : DefaultThemeRenderContext , declaration : DeclarationReflection ) : JSX . Children {
102
+ return (
103
+ < >
104
+ { context . commentSummary ( declaration ) }
105
+ < ul class = "tsd-parameters" >
106
+ { declaration . signatures && (
107
+ < li class = "tsd-parameter-signature" >
108
+ < ul class = { classNames ( { "tsd-signatures" : true } , context . getReflectionClasses ( declaration ) ) } >
109
+ { declaration . signatures . map ( ( item ) => (
110
+ < >
111
+ < li class = "tsd-signature" id = { item . anchor } >
112
+ { context . memberSignatureTitle ( item , {
113
+ hideName : true ,
114
+ } ) }
115
+ </ li >
116
+ < li class = "tsd-description" >
117
+ { context . memberSignatureBody ( item , {
118
+ hideSources : true ,
119
+ } ) }
120
+ </ li >
121
+ </ >
122
+ ) ) }
123
+ </ ul >
124
+ </ li >
125
+ ) }
126
+ { declaration . indexSignatures ?. map ( ( index ) => renderIndexSignature ( context , index ) ) }
127
+ { declaration . children ?. map ( ( child ) => renderChild ( context , child ) ) }
128
+ </ ul >
129
+ </ >
130
+ ) ;
131
+ }
132
+
108
133
function renderChild ( context : DefaultThemeRenderContext , child : DeclarationReflection ) {
109
134
if ( child . signatures ) {
110
135
return (
0 commit comments