11import { JSXElement } from "revolution/jsx-runtime" ;
22import { type Operation } from "effection" ;
33import type {
4- DocNode ,
54 ParamDef ,
65 TsTypeDef ,
76 TsTypeParamDef ,
87 TsTypeRefDef ,
98 VariableDef ,
109} from "@deno/doc" ;
10+ import type { DocNode } from "../../hooks/use-deno-doc.tsx" ;
1111import {
1212 Builtin ,
1313 ClassName ,
@@ -25,44 +25,44 @@ export function* Type(props: TypeProps): Operation<JSXElement> {
2525 let { node } = props ;
2626
2727 switch ( node . kind ) {
28- case "function" :
28+ case "function" : {
29+ let typeParams = node . def . typeParams ?? [ ] ;
2930 return (
3031 < span class = "language-ts code-highlight inline-block" >
31- { node . functionDef . isAsync
32- ? < Punctuation > { "async " } </ Punctuation >
33- : < > </ > }
32+ { node . def . isAsync ? < Punctuation > { "async " } </ Punctuation > : < > </ > }
3433 < Keyword > { node . kind } </ Keyword >
35- { node . functionDef . isGenerator ? < Punctuation > *</ Punctuation > : < > </ > }
36- { " " }
34+ { node . def . isGenerator ? < Punctuation > *</ Punctuation > : < > </ > } { " " }
3735 < span class = "token function" > { node . name } </ span >
38- { node . functionDef . typeParams . length > 0
39- ? < InterfaceTypeParams typeParams = { node . functionDef . typeParams } />
36+ { typeParams . length > 0
37+ ? < InterfaceTypeParams typeParams = { typeParams } />
4038 : < > </ > }
4139 < Punctuation > (</ Punctuation >
42- < FunctionParams params = { node . functionDef . params } />
43- < Punctuation > )</ Punctuation > : { node . functionDef . returnType
44- ? < TypeDef typeDef = { node . functionDef . returnType } />
40+ < FunctionParams params = { node . def . params } />
41+ < Punctuation > )</ Punctuation > : { node . def . returnType
42+ ? < TypeDef typeDef = { node . def . returnType } />
4543 : < > </ > }
4644 </ span >
4745 ) ;
48- case "class" :
46+ }
47+ case "class" : {
48+ let impl /* implements */ = node . def . implements ?? [ ] ;
4949 return (
5050 < span class = "language-ts code-highlight inline-block" >
5151 < Keyword > { node . kind } </ Keyword > < ClassName > { node . name } </ ClassName >
52- { node . classDef . extends
52+ { node . def . extends
5353 ? (
5454 < >
5555 < Keyword > { " extends " } </ Keyword >
56- < ClassName > { node . classDef . extends } </ ClassName >
56+ < ClassName > { node . def . extends } </ ClassName >
5757 </ >
5858 )
5959 : < > </ > }
60- { node . classDef . implements
60+ { impl . length > 0
6161 ? (
6262 < >
6363 < Keyword > { " implements " } </ Keyword >
6464 < >
65- { node . classDef . implements
65+ { impl
6666 . flatMap ( ( typeDef ) => [ < TypeDef typeDef = { typeDef } /> , ", " ] )
6767 . slice ( 0 , - 1 ) }
6868 </ >
@@ -71,19 +71,22 @@ export function* Type(props: TypeProps): Operation<JSXElement> {
7171 : < > </ > }
7272 </ span >
7373 ) ;
74- case "interface" :
74+ }
75+ case "interface" : {
76+ let typeParams = node . def . typeParams ?? [ ] ;
77+ let ext = node . def . extends ?? [ ] ;
7578 return (
7679 < span class = "language-ts code-highlight inline-block" >
7780 < Keyword > { node . kind } </ Keyword > < ClassName > { node . name } </ ClassName >
78- { node . interfaceDef . typeParams . length > 0
79- ? < InterfaceTypeParams typeParams = { node . interfaceDef . typeParams } />
81+ { typeParams . length > 0
82+ ? < InterfaceTypeParams typeParams = { typeParams } />
8083 : < > </ > }
81- { node . interfaceDef . extends . length > 0
84+ { ext . length > 0
8285 ? (
8386 < >
8487 < Keyword > { " extends " } </ Keyword >
8588 < >
86- { node . interfaceDef . extends
89+ { ext
8790 . flatMap ( ( typeDef ) => [ < TypeDef typeDef = { typeDef } /> , ", " ] )
8891 . slice ( 0 , - 1 ) }
8992 </ >
@@ -92,10 +95,11 @@ export function* Type(props: TypeProps): Operation<JSXElement> {
9295 : < > </ > }
9396 </ span >
9497 ) ;
98+ }
9599 case "variable" :
96100 return (
97101 < span class = "inline-block" >
98- < TSVariableDef variableDef = { node . variableDef } name = { node . name } />
102+ < TSVariableDef variableDef = { node . def } name = { node . name } />
99103 </ span >
100104 ) ;
101105 case "typeAlias" :
@@ -104,12 +108,10 @@ export function* Type(props: TypeProps): Operation<JSXElement> {
104108 < Keyword > { "type " } </ Keyword >
105109 { node . name }
106110 < Operator > { " = " } </ Operator >
107- < TypeDef typeDef = { node . typeAliasDef . tsType } />
111+ < TypeDef typeDef = { node . def . tsType } />
108112 </ span >
109113 ) ;
110114 case "enum" :
111- case "import" :
112- case "moduleDoc" :
113115 case "namespace" :
114116 default :
115117 console . log ( "<Type> unimplemented" , node . kind ) ;
@@ -187,51 +189,51 @@ function TSParam({ param }: { param: ParamDef }) {
187189export function TypeDef ( { typeDef } : { typeDef : TsTypeDef } ) {
188190 switch ( typeDef . kind ) {
189191 case "literal" :
190- switch ( typeDef . literal . kind ) {
192+ switch ( typeDef . value . kind ) {
191193 case "string" :
192- return < span class = "token string" > "{ typeDef . repr } "</ span > ;
194+ return < span class = "token string" > "{ typeDef . repr ?? "" } "</ span > ;
193195 case "number" :
194- return < span class = "token number" > { typeDef . repr } </ span > ;
196+ return < span class = "token number" > { typeDef . repr ?? "" } </ span > ;
195197 case "boolean" :
196- return < span class = "token boolean" > { typeDef . repr } </ span > ;
198+ return < span class = "token boolean" > { typeDef . repr ?? "" } </ span > ;
197199 case "bigInt" :
198- return < span class = "token number" > { typeDef . repr } </ span > ;
200+ return < span class = "token number" > { typeDef . repr ?? "" } </ span > ;
199201 default :
200202 // TODO(taras): implement template
201203 return < > </ > ;
202204 }
203205 case "keyword" :
204- if ( [ "number" , "string" , "boolean" , "bigint" ] . includes ( typeDef . keyword ) ) {
205- return < Builtin > { typeDef . keyword } </ Builtin > ;
206+ if ( [ "number" , "string" , "boolean" , "bigint" ] . includes ( typeDef . value ) ) {
207+ return < Builtin > { typeDef . value } </ Builtin > ;
206208 } else {
207- return < Keyword > { typeDef . keyword } </ Keyword > ;
209+ return < Keyword > { typeDef . value } </ Keyword > ;
208210 }
209211 case "typeRef" :
210- return < TypeRef typeRef = { typeDef . typeRef } /> ;
212+ return < TypeRef typeRef = { typeDef . value } /> ;
211213 case "union" :
212- return < TypeDefUnion union = { typeDef . union } /> ;
214+ return < TypeDefUnion union = { typeDef . value } /> ;
213215 case "fnOrConstructor" :
214- if ( typeDef . fnOrConstructor . constructor ) {
215- console . log ( `<TypeDef> unimplemeneted` , typeDef . fnOrConstructor ) ;
216+ if ( typeDef . value . constructor ) {
217+ console . log ( `<TypeDef> unimplemeneted` , typeDef . value ) ;
216218 // TODO(taras): implement
217219 return < > </ > ;
218220 } else {
219221 return (
220222 < >
221223 < Punctuation > (</ Punctuation >
222- < FunctionParams params = { typeDef . fnOrConstructor . params } />
224+ < FunctionParams params = { typeDef . value . params } />
223225 < Punctuation > )</ Punctuation >
224226 < Operator > { " => " } </ Operator >
225- < TypeDef typeDef = { typeDef . fnOrConstructor . tsType } />
227+ < TypeDef typeDef = { typeDef . value . tsType } />
226228 </ >
227229 ) ;
228230 }
229231 case "indexedAccess" :
230232 return (
231233 < >
232- < TypeDef typeDef = { typeDef . indexedAccess . objType } />
234+ < TypeDef typeDef = { typeDef . value . objType } />
233235 < Punctuation > [</ Punctuation >
234- < TypeDef typeDef = { typeDef . indexedAccess . indexType } />
236+ < TypeDef typeDef = { typeDef . value . indexType } />
235237 < Punctuation > ]</ Punctuation >
236238 </ >
237239 ) ;
@@ -240,7 +242,7 @@ export function TypeDef({ typeDef }: { typeDef: TsTypeDef }) {
240242 < >
241243 < Punctuation > [</ Punctuation >
242244 < >
243- { typeDef . tuple
245+ { typeDef . value
244246 . flatMap ( ( tp ) => [ < TypeDef typeDef = { tp } /> , ", " ] )
245247 . slice ( 0 , - 1 ) }
246248 </ >
@@ -250,30 +252,30 @@ export function TypeDef({ typeDef }: { typeDef: TsTypeDef }) {
250252 case "array" :
251253 return (
252254 < >
253- < TypeDef typeDef = { typeDef . array } />
255+ < TypeDef typeDef = { typeDef . value } />
254256 < Punctuation > []</ Punctuation >
255257 </ >
256258 ) ;
257259 case "typeOperator" :
258260 return (
259261 < >
260- < Keyword > { typeDef . typeOperator . operator } </ Keyword > { " " }
261- < TypeDef typeDef = { typeDef . typeOperator . tsType } />
262+ < Keyword > { typeDef . value . operator } </ Keyword > { " " }
263+ < TypeDef typeDef = { typeDef . value . tsType } />
262264 </ >
263265 ) ;
264266 case "parenthesized" : {
265267 return (
266268 < >
267269 < Punctuation > (</ Punctuation >
268- < TypeDef typeDef = { typeDef . parenthesized } />
270+ < TypeDef typeDef = { typeDef . value } />
269271 < Punctuation > )</ Punctuation >
270272 </ >
271273 ) ;
272274 }
273275 case "intersection" : {
274276 return (
275277 < >
276- { typeDef . intersection
278+ { typeDef . value
277279 . flatMap ( ( tp ) => [
278280 < TypeDef typeDef = { tp } /> ,
279281 < Operator > { " & " } </ Operator > ,
@@ -294,37 +296,37 @@ export function TypeDef({ typeDef }: { typeDef: TsTypeDef }) {
294296 case "conditional" : {
295297 return (
296298 < >
297- < TypeDef typeDef = { typeDef . conditionalType . checkType } />
299+ < TypeDef typeDef = { typeDef . value . checkType } />
298300 < Keyword > { " extends " } </ Keyword >
299- < TypeDef typeDef = { typeDef . conditionalType . extendsType } />
301+ < TypeDef typeDef = { typeDef . value . extendsType } />
300302 < Operator > { " ? " } </ Operator >
301- < TypeDef typeDef = { typeDef . conditionalType . trueType } />
303+ < TypeDef typeDef = { typeDef . value . trueType } />
302304 < Operator > { " : " } </ Operator >
303- < TypeDef typeDef = { typeDef . conditionalType . falseType } />
305+ < TypeDef typeDef = { typeDef . value . falseType } />
304306 </ >
305307 ) ;
306308 }
307309 case "infer" : {
308310 return (
309311 < >
310312 < Keyword > { "infer " } </ Keyword >
311- { typeDef . infer . typeParam . name }
313+ { typeDef . value . typeParam . name }
312314 </ >
313315 ) ;
314316 }
315317 case "mapped" :
316318 return (
317319 < >
318320 < Punctuation > [</ Punctuation >
319- { typeDef . mappedType . typeParam . name }
321+ { typeDef . value . typeParam . name }
320322 < Keyword > { ` in ` } </ Keyword >
321- { typeDef . mappedType . typeParam . constraint
322- ? < TypeDef typeDef = { typeDef . mappedType . typeParam . constraint } />
323+ { typeDef . value . typeParam . constraint
324+ ? < TypeDef typeDef = { typeDef . value . typeParam . constraint } />
323325 : < > </ > }
324326 < Punctuation > ]</ Punctuation >
325327 < Operator > { " : " } </ Operator >
326- { typeDef . mappedType . tsType
327- ? < TypeDef typeDef = { typeDef . mappedType . tsType } />
328+ { typeDef . value . tsType
329+ ? < TypeDef typeDef = { typeDef . value . tsType } />
328330 : < > </ > }
329331 </ >
330332 ) ;
0 commit comments