forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeno-doc.ts
More file actions
160 lines (154 loc) · 3.47 KB
/
deno-doc.ts
File metadata and controls
160 lines (154 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* Types for deno doc JSON output.
*
* These types represent the structure of the JSON output from `deno doc --json`.
* In an ideal world, we'd generate these or implement our own AST / parser.
* That might be an endgame, but there's a lot of value in using deno's implementation, too.
* Well trodden ground and all that.
*
* @see: https://deno.land/x/deno_doc
*/
/** JSDoc tag from deno doc output */
export interface JsDocTag {
kind: string
name?: string
doc?: string
optional?: boolean
type?: string
}
/** TypeScript type representation from deno doc */
export interface TsType {
repr: string
kind: string
keyword?: string
typeRef?: {
typeName: string
typeParams?: TsType[] | null
}
array?: TsType
union?: TsType[]
literal?: {
kind: string
string?: string
number?: number
boolean?: boolean
}
fnOrConstructor?: {
constructor: boolean
tsType: TsType
params: FunctionParam[]
typeParams?: Array<{ name: string; constraint?: TsType }>
}
indexedAccess?: {
objType: TsType
indexType: TsType
}
typeOperator?: {
operator: string
tsType: TsType
}
this?: boolean
typeLiteral?: {
properties: Array<{ name: string; tsType?: TsType; readonly?: boolean; optional?: boolean }>
methods: Array<{ name: string; params?: FunctionParam[]; returnType?: TsType }>
callSignatures: Array<{ params?: FunctionParam[]; tsType?: TsType }>
indexSignatures: Array<{ params: FunctionParam[]; tsType?: TsType }>
}
}
/** Function parameter from deno doc */
export interface FunctionParam {
kind: string
name: string
optional?: boolean
tsType?: TsType
}
/** A documentation node from deno doc output */
export interface DenoDocNode {
name: string
kind: string
isDefault?: boolean
location?: {
filename: string
line: number
col: number
}
declarationKind?: string
jsDoc?: {
doc?: string
tags?: JsDocTag[]
}
functionDef?: {
params?: FunctionParam[]
returnType?: TsType
isAsync?: boolean
isGenerator?: boolean
typeParams?: Array<{ name: string }>
}
classDef?: {
isAbstract?: boolean
properties?: Array<{
name: string
tsType?: TsType
readonly?: boolean
optional?: boolean
isStatic?: boolean
jsDoc?: { doc?: string }
}>
methods?: Array<{
name: string
isStatic?: boolean
functionDef?: {
params?: FunctionParam[]
returnType?: TsType
}
jsDoc?: { doc?: string }
}>
constructors?: Array<{
params?: FunctionParam[]
}>
extends?: string
implements?: TsType[]
}
interfaceDef?: {
properties?: Array<{
name: string
tsType?: TsType
readonly?: boolean
optional?: boolean
jsDoc?: { doc?: string }
}>
methods?: Array<{
name: string
params?: FunctionParam[]
returnType?: TsType
jsDoc?: { doc?: string }
}>
extends?: TsType[]
typeParams?: Array<{ name: string }>
}
typeAliasDef?: {
tsType?: TsType
typeParams?: Array<{ name: string }>
}
variableDef?: {
tsType?: TsType
kind?: string
}
enumDef?: {
members?: Array<{ name: string; init?: TsType }>
}
namespaceDef?: {
elements?: DenoDocNode[]
}
}
/** Raw output from deno doc --json */
export interface DenoDocResult {
version: number
nodes: DenoDocNode[]
}
/** Result of documentation generation */
export interface DocsGenerationResult {
html: string
toc: string | null
nodes: DenoDocNode[]
}