@@ -82,14 +82,8 @@ pub(crate) fn render_type_def(
8282 ctx : & RenderContext ,
8383 def : & crate :: ts_type:: TsTypeDef ,
8484) -> String {
85- let Some ( kind) = & def. kind else {
86- return html_escape:: encode_text ( & def. repr ) . to_string ( ) ;
87- } ;
88-
89- match kind {
90- TsTypeDefKind :: Keyword => {
91- let keyword = def. keyword . as_ref ( ) . unwrap ( ) ;
92-
85+ match & def. kind {
86+ TsTypeDefKind :: Keyword ( keyword) => {
9387 if !ctx. disable_links
9488 && let Some ( href) = ctx
9589 . ctx
@@ -104,53 +98,46 @@ pub(crate) fn render_type_def(
10498 format ! ( r#"<span class="td-kw">{keyword}</span>"# )
10599 }
106100 }
107- TsTypeDefKind :: Literal => {
108- let lit = def. literal . as_ref ( ) . unwrap ( ) ;
101+ TsTypeDefKind :: Literal ( lit) => match lit. kind {
102+ LiteralDefKind :: Number
103+ | LiteralDefKind :: BigInt
104+ | LiteralDefKind :: Boolean => {
105+ format ! (
106+ r#"<span class="td-lit">{}</span>"# ,
107+ html_escape:: encode_text( & def. repr)
108+ )
109+ }
110+ LiteralDefKind :: String => {
111+ format ! (
112+ r#"<span class="td-str">{:?}</span>"# ,
113+ html_escape:: encode_text( & def. repr)
114+ )
115+ }
116+ LiteralDefKind :: Template => {
117+ if let Some ( types) = & lit. ts_types {
118+ let mut out = String :: new ( ) ;
119+
120+ for ts_type in types {
121+ out. push_str ( & if matches ! (
122+ & ts_type. kind,
123+ TsTypeDefKind :: Literal ( l) if l. string. is_some( )
124+ ) {
125+ html_escape:: encode_text ( & ts_type. repr ) . into_owned ( )
126+ } else {
127+ format ! ( "${{{}}}" , render_type_def( ctx, ts_type) )
128+ } ) ;
129+ }
109130
110- match lit. kind {
111- LiteralDefKind :: Number
112- | LiteralDefKind :: BigInt
113- | LiteralDefKind :: Boolean => {
114- format ! (
115- r#"<span class="td-lit">{}</span>"# ,
116- html_escape:: encode_text( & def. repr)
117- )
118- }
119- LiteralDefKind :: String => {
131+ format ! ( r#"<span class="td-str">`{out}`</span>"# )
132+ } else {
120133 format ! (
121- r#"<span class="td-str">{:?} </span>"# ,
134+ r#"<span class="td-str">`{}` </span>"# ,
122135 html_escape:: encode_text( & def. repr)
123136 )
124137 }
125- LiteralDefKind :: Template => {
126- if let Some ( types) = & lit. ts_types {
127- let mut out = String :: new ( ) ;
128-
129- for ts_type in types {
130- out. push_str ( & if ts_type
131- . literal
132- . as_ref ( )
133- . is_some_and ( |literal| literal. string . is_some ( ) )
134- {
135- html_escape:: encode_text ( & ts_type. repr ) . into_owned ( )
136- } else {
137- format ! ( "${{{}}}" , render_type_def( ctx, ts_type) )
138- } ) ;
139- }
140-
141- format ! ( r#"<span class="td-str">`{out}`</span>"# )
142- } else {
143- format ! (
144- r#"<span class="td-str">`{}`</span>"# ,
145- html_escape:: encode_text( & def. repr)
146- )
147- }
148- }
149138 }
150- }
151- TsTypeDefKind :: TypeRef => {
152- let type_ref = def. type_ref . as_ref ( ) . unwrap ( ) ;
153-
139+ } ,
140+ TsTypeDefKind :: TypeRef ( type_ref) => {
154141 let href = if ctx. disable_links {
155142 None
156143 } else if ctx. contains_type_param ( & type_ref. type_name ) {
@@ -188,39 +175,29 @@ pub(crate) fn render_type_def(
188175 . unwrap_or_default( )
189176 )
190177 }
191- TsTypeDefKind :: Union => {
192- type_def_join ( ctx, def. union . as_ref ( ) . unwrap ( ) , '|' )
178+ TsTypeDefKind :: Union ( union) => type_def_join ( ctx, union, '|' ) ,
179+ TsTypeDefKind :: Intersection ( intersection) => {
180+ type_def_join ( ctx, intersection, '&' )
193181 }
194- TsTypeDefKind :: Intersection => {
195- type_def_join ( ctx , def . intersection . as_ref ( ) . unwrap ( ) , '&' )
182+ TsTypeDefKind :: Array ( array ) => {
183+ format ! ( "{}[]" , render_type_def ( ctx , array ) )
196184 }
197- TsTypeDefKind :: Array => {
198- format ! ( "{}[]" , render_type_def( ctx, def. array. as_ref( ) . unwrap( ) ) )
199- }
200- TsTypeDefKind :: Tuple => type_def_tuple ( ctx, def. tuple . as_ref ( ) . unwrap ( ) ) ,
201- TsTypeDefKind :: TypeOperator => {
202- let operator = def. type_operator . as_ref ( ) . unwrap ( ) ;
185+ TsTypeDefKind :: Tuple ( tuple) => type_def_tuple ( ctx, tuple) ,
186+ TsTypeDefKind :: TypeOperator ( operator) => {
203187 format ! (
204188 r#"<span class="td-kw">{}</span> {}"# ,
205189 operator. operator,
206190 render_type_def( ctx, & operator. ts_type)
207191 )
208192 }
209- TsTypeDefKind :: Parenthesized => {
210- format ! (
211- "({})" ,
212- render_type_def( ctx, def. parenthesized. as_ref( ) . unwrap( ) )
213- )
214- }
215- TsTypeDefKind :: Rest => {
216- format ! ( "...{}" , render_type_def( ctx, def. rest. as_ref( ) . unwrap( ) ) )
193+ TsTypeDefKind :: Parenthesized ( inner) => {
194+ format ! ( "({})" , render_type_def( ctx, inner) )
217195 }
218- TsTypeDefKind :: Optional => {
219- render_type_def ( ctx , def . optional . as_ref ( ) . unwrap ( ) )
196+ TsTypeDefKind :: Rest ( inner ) => {
197+ format ! ( "...{}" , render_type_def ( ctx , inner ) )
220198 }
221- TsTypeDefKind :: TypeQuery => {
222- let query = def. type_query . as_ref ( ) . unwrap ( ) ;
223-
199+ TsTypeDefKind :: Optional ( inner) => render_type_def ( ctx, inner) ,
200+ TsTypeDefKind :: TypeQuery ( query) => {
224201 if !ctx. disable_links
225202 && let Some ( href) = ctx. lookup_symbol_href ( query)
226203 {
@@ -237,9 +214,7 @@ pub(crate) fn render_type_def(
237214 }
238215 }
239216 TsTypeDefKind :: This => r#"<span class="td-kw">this</span>"# . to_string ( ) ,
240- TsTypeDefKind :: FnOrConstructor => {
241- let fn_or_constructor = def. fn_or_constructor . as_ref ( ) . unwrap ( ) ;
242-
217+ TsTypeDefKind :: FnOrConstructor ( fn_or_constructor) => {
243218 let new = if fn_or_constructor. constructor {
244219 r#"<span class="td-kw">new </span>"#
245220 } else {
@@ -253,9 +228,7 @@ pub(crate) fn render_type_def(
253228 render_type_def( ctx, & fn_or_constructor. ts_type) ,
254229 )
255230 }
256- TsTypeDefKind :: Conditional => {
257- let conditional = def. conditional_type . as_ref ( ) . unwrap ( ) ;
258-
231+ TsTypeDefKind :: Conditional ( conditional) => {
259232 format ! (
260233 r#"{} <span class="td-kw">extends</span> {} <span class="td-op">?</span> {} <span class="td-op">:</span> {}"# ,
261234 render_type_def( ctx, & conditional. check_type) ,
@@ -264,26 +237,18 @@ pub(crate) fn render_type_def(
264237 render_type_def( ctx, & conditional. false_type) ,
265238 )
266239 }
267- TsTypeDefKind :: Infer => format ! (
240+ TsTypeDefKind :: Infer ( infer ) => format ! (
268241 r#"<span class="td-kw">infer </span>{}"# ,
269- type_param_summary(
270- ctx,
271- & def. infer. as_ref( ) . unwrap( ) . type_param,
272- "extends" ,
273- )
242+ type_param_summary( ctx, & infer. type_param, "extends" , )
274243 ) ,
275- TsTypeDefKind :: IndexedAccess => {
276- let indexed_access = def. indexed_access . as_ref ( ) . unwrap ( ) ;
277-
244+ TsTypeDefKind :: IndexedAccess ( indexed_access) => {
278245 format ! (
279246 "{}[{}]" ,
280247 render_type_def( ctx, & indexed_access. obj_type) ,
281248 render_type_def( ctx, & indexed_access. index_type)
282249 )
283250 }
284- TsTypeDefKind :: Mapped => {
285- let mapped = def. mapped_type . as_ref ( ) . unwrap ( ) ;
286-
251+ TsTypeDefKind :: Mapped ( mapped) => {
287252 let readonly = if let Some ( readonly) = mapped. readonly {
288253 let char = match readonly {
289254 TruePlusMinus :: True => "" ,
@@ -329,9 +294,7 @@ pub(crate) fn render_type_def(
329294 type_param_summary( ctx, & mapped. type_param, "in" )
330295 )
331296 }
332- TsTypeDefKind :: TypeLiteral => {
333- let type_literal = def. type_literal . as_ref ( ) . unwrap ( ) ;
334-
297+ TsTypeDefKind :: TypeLiteral ( type_literal) => {
335298 let mut index_signatures =
336299 Vec :: with_capacity ( type_literal. index_signatures . len ( ) ) ;
337300
@@ -449,9 +412,7 @@ pub(crate) fn render_type_def(
449412
450413 format ! ( "{{ {index_signatures}{call_signatures}{properties}{methods} }}" )
451414 }
452- TsTypeDefKind :: TypePredicate => {
453- let type_predicate = def. type_predicate . as_ref ( ) . unwrap ( ) ;
454-
415+ TsTypeDefKind :: TypePredicate ( type_predicate) => {
455416 let asserts = if type_predicate. asserts {
456417 r#"<span class="td-kw">asserts </span>"#
457418 } else {
@@ -460,7 +421,7 @@ pub(crate) fn render_type_def(
460421 let param_type = if let crate :: ts_type:: ThisOrIdent :: Identifier { name } =
461422 & type_predicate. param
462423 {
463- html_escape:: encode_text ( name) . to_string ( )
424+ html_escape:: encode_text ( & name) . to_string ( )
464425 } else {
465426 r#"<span class="td-kw">this</span>"# . to_string ( )
466427 } ;
@@ -478,9 +439,7 @@ pub(crate) fn render_type_def(
478439
479440 format ! ( "{asserts}{param_type}{}" , r#type)
480441 }
481- TsTypeDefKind :: ImportType => {
482- let import_type = def. import_type . as_ref ( ) . unwrap ( ) ;
483-
442+ TsTypeDefKind :: ImportType ( import_type) => {
484443 let qualifier = import_type
485444 . qualifier
486445 . as_ref ( )
0 commit comments