@@ -25,6 +25,7 @@ export const TYPESPEC_NODE_ANONYMOUS = Symbol('anonymous')
2525export interface ModuleTypes {
2626 name : string
2727 methods : Map < string , MethodTypes >
28+ variables : Map < string , VariableTypes >
2829}
2930
3031/**
@@ -43,6 +44,16 @@ export interface MethodTypes {
4344 ]
4445}
4546
47+ /**
48+ * Type definitions for a variable or constant.
49+ */
50+ export interface VariableTypes {
51+ name : string | typeof TYPESPEC_NODE_ANONYMOUS
52+ comment ?: Comment
53+ type : TypeDetails | undefined
54+ isConst ?: boolean
55+ }
56+
4657interface Comment {
4758 shortText ?: string
4859 text ?: string
@@ -160,6 +171,7 @@ export interface CustomTypePropertyType {
160171// The meaning of kind flags from `typedoc`:
161172// https://github.com/TypeStrong/typedoc/blob/2953b0148253589448176881a7acb46090f941bd/src/lib/output/themes/default/assets/typedoc/Application.ts#L36
162173const KIND_MODULE = 2
174+ const KIND_VARIABLE = 32
163175const KIND_CLASS = 128
164176const KIND_INTERFACE = 256
165177const KIND_CONSTRUCTOR = 512
@@ -285,6 +297,7 @@ function parseMod(mod: (typeof typeSpec)['children'][number]) {
285297 const res : ModuleTypes = {
286298 name : mod . name ,
287299 methods : new Map ( ) ,
300+ variables : new Map ( ) ,
288301 }
289302
290303 // Build a map of nodes by their IDs for easy cross-referencing.
@@ -365,6 +378,8 @@ function parseModInternal(
365378 parseConstructor ( node , map , currentPath , res )
366379 } else if ( node . kind === KIND_METHOD ) {
367380 return parseMethod ( node , map , currentPath , res )
381+ } else if ( node . kind === KIND_VARIABLE ) {
382+ return parseVariable ( node , map , currentPath , res )
368383 } else if ( node . kind === KIND_PROPERTY ) {
369384 parsePropertyReference ( node , map , currentPath , res , processingRefs )
370385 }
@@ -490,6 +505,27 @@ function parseMethod(
490505 res . methods . set ( $ref , types )
491506}
492507
508+ function parseVariable (
509+ node : any ,
510+ map : Map < number , any > ,
511+ currentPath : Array < string > ,
512+ res : ModuleTypes
513+ ) {
514+ const $ref = buildRefPath ( [ ...currentPath , node . name ] )
515+
516+ const type = parseType ( node . type , map )
517+ const comment = node . comment ? normalizeComment ( node . comment ) : undefined
518+
519+ const types : VariableTypes = {
520+ name : $ref ,
521+ type,
522+ comment,
523+ isConst : node . flags ?. isConst ?? false ,
524+ }
525+
526+ res . variables . set ( $ref , types )
527+ }
528+
493529function parseSignature (
494530 signature : any ,
495531 map : Map < number , any >
0 commit comments