@@ -4,15 +4,12 @@ import type {
4
4
CompilerOptions ,
5
5
Declaration ,
6
6
EnumDeclaration ,
7
- FunctionDeclaration ,
8
7
Node ,
9
- PropertyName ,
10
8
Signature ,
11
9
SourceFile ,
12
10
TypeChecker ,
13
11
Symbol as TypeScriptSymbol ,
14
- VariableDeclaration ,
15
- VariableStatement
12
+ VariableDeclaration
16
13
} from 'typescript' ;
17
14
import {
18
15
ModifierFlags ,
@@ -49,15 +46,13 @@ const serializeSymbol = ({
49
46
checker : TypeChecker ;
50
47
symbol : TypeScriptSymbol ;
51
48
doc_type ?: DocEntryType ;
52
- } ) : DocEntry => {
53
- return {
54
- name : symbol . getName ( ) ,
55
- documentation : displayPartsToString ( symbol . getDocumentationComment ( checker ) ) ,
56
- type : checker . typeToString ( checker . getTypeOfSymbolAtLocation ( symbol , symbol . valueDeclaration ! ) ) ,
57
- jsDocs : symbol . getJsDocTags ( ) ,
58
- ...( doc_type && { doc_type} )
59
- } ;
60
- } ;
49
+ } ) : DocEntry => ( {
50
+ name : symbol . getName ( ) ,
51
+ documentation : displayPartsToString ( symbol . getDocumentationComment ( checker ) ) ,
52
+ type : checker . typeToString ( checker . getTypeOfSymbolAtLocation ( symbol , symbol . valueDeclaration ! ) ) ,
53
+ jsDocs : symbol . getJsDocTags ( ) ,
54
+ ...( doc_type !== undefined && { doc_type} )
55
+ } ) ;
61
56
62
57
const serializeEnum = ( {
63
58
checker,
@@ -80,7 +75,7 @@ const serializeEnum = ({
80
75
return {
81
76
name : member . name . getText ( ) ,
82
77
...( type !== undefined && { type} ) ,
83
- ...( documentation !== undefined && documentation !== '' && { documentation} )
78
+ ...( documentation !== '' && { documentation} )
84
79
} ;
85
80
} ) ;
86
81
@@ -149,7 +144,7 @@ const serializeSignature = ({
149
144
documentation : displayPartsToString ( signature . getDocumentationComment ( checker ) )
150
145
} ;
151
146
152
- if ( ! ! signature . declaration && 'modifiers' in signature . declaration ) {
147
+ if ( ! ( signature . declaration == null ) && 'modifiers' in signature . declaration ) {
153
148
return {
154
149
...result ,
155
150
visibility :
@@ -219,7 +214,7 @@ const getRootParentName = (node: Node): string | undefined => {
219
214
} ;
220
215
221
216
const isRootOrClassLevelArrowFunction = ( node : Node ) : boolean => {
222
- const parent = node . parent ;
217
+ const { parent} = node ;
223
218
224
219
if ( ! parent ) {
225
220
return false ;
@@ -266,7 +261,7 @@ const visit = ({
266
261
267
262
const entries : DocEntry [ ] = [ ] ;
268
263
269
- const pushEntry = ( { details, node} : { details : DocEntry ; node : Node } ) => {
264
+ const pushEntry = ( { details, node} : { details : DocEntry ; node : Node } ) : void => {
270
265
entries . push ( {
271
266
...details ,
272
267
...buildSource ( {
@@ -284,7 +279,7 @@ const visit = ({
284
279
symbol : TypeScriptSymbol | undefined ;
285
280
doc_type : DocEntryType ;
286
281
node : Node ;
287
- } ) => {
282
+ } ) : void => {
288
283
if ( ! symbol ) {
289
284
return ;
290
285
}
@@ -308,11 +303,11 @@ const visit = ({
308
303
} )
309
304
} ;
310
305
311
- const visitChild = ( node : Node ) => {
306
+ const visitChild = ( node : Node ) : void => {
312
307
const docEntries : DocEntry [ ] = visit ( { node, checker, types, ...rest } ) ;
313
308
314
309
// We do not need to repeat the file name for class members
315
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
310
+
316
311
const omitFilename = ( { fileName : _ , ...rest } : DocEntry ) : Omit < DocEntry , 'fileName' > => rest ;
317
312
318
313
classEntry . methods ?. push (
@@ -331,7 +326,7 @@ const visit = ({
331
326
entries . push ( classEntry ) ;
332
327
}
333
328
} else if ( isModuleDeclaration ( node ) ) {
334
- const visitChild = ( node : Node ) => {
329
+ const visitChild = ( node : Node ) : void => {
335
330
const docEntries : DocEntry [ ] = visit ( { node, checker, types, ...rest } ) ;
336
331
entries . push ( ...docEntries ) ;
337
332
} ;
@@ -342,7 +337,7 @@ const visit = ({
342
337
const symbol = checker . getSymbolAtLocation ( node . name ) ;
343
338
addDocEntry ( { symbol, doc_type : 'method' , node} ) ;
344
339
} else if ( isFunctionDeclaration ( node ) ) {
345
- const symbol = checker . getSymbolAtLocation ( ( node as FunctionDeclaration ) . name ?? node ) ;
340
+ const symbol = checker . getSymbolAtLocation ( node . name ?? node ) ;
346
341
addDocEntry ( { symbol, doc_type : 'function' , node} ) ;
347
342
} else {
348
343
const arrowFunc : Node | undefined = findDescendantArrowFunction ( node ) ;
@@ -374,14 +369,14 @@ const visit = ({
374
369
} else if ( isVariableStatement ( node ) ) {
375
370
const {
376
371
declarationList : { declarations, flags}
377
- } = node as VariableStatement ;
372
+ } = node ;
378
373
379
374
// https://stackoverflow.com/a/69801125/5404186
380
375
const isConst = ( flags & NodeFlags . Const ) !== 0 ;
381
376
382
377
if ( isConst ) {
383
378
// TODO: not sure what's the proper casting, VariableDeclaration does not contain Symbol but the test entity effectively does
384
- const symbol = ( declarations [ 0 ] as unknown as { symbol : TypeScriptSymbol } ) . symbol ;
379
+ const { symbol} = declarations [ 0 ] as unknown as { symbol : TypeScriptSymbol } ;
385
380
addDocEntry ( { symbol, doc_type : 'const' , node} ) ;
386
381
}
387
382
} else if ( types && isInterfaceDeclaration ( node ) ) {
@@ -393,9 +388,9 @@ const visit = ({
393
388
( member ) =>
394
389
isPropertySignature ( member ) && member . name !== undefined && isIdentifier ( member . name )
395
390
)
396
- . map ( ( member ) => checker . getSymbolAtLocation ( member . name as PropertyName ) )
391
+ . map ( ( member ) => checker . getSymbolAtLocation ( member . name ! ) )
397
392
. filter ( ( symbol ) => symbol !== undefined )
398
- . map ( ( symbol ) => serializeSymbol ( { checker, symbol : symbol as TypeScriptSymbol } ) ) ;
393
+ . map ( ( symbol ) => serializeSymbol ( { checker, symbol : symbol ! } ) ) ;
399
394
400
395
const interfaceEntry : DocEntry = {
401
396
...serializeSymbol ( { checker, doc_type : 'interface' , symbol} ) ,
@@ -426,7 +421,7 @@ const visit = ({
426
421
entries . push ( typeEntry ) ;
427
422
}
428
423
} else if ( isEnumDeclaration ( node ) ) {
429
- const symbol = checker . getSymbolAtLocation ( ( node as EnumDeclaration ) . name ) ! ;
424
+ const symbol = checker . getSymbolAtLocation ( node . name ) ! ;
430
425
const details = serializeEnum ( { checker, symbol} ) ;
431
426
pushEntry ( { node, details} ) ;
432
427
}
@@ -448,7 +443,7 @@ const buildSource = ({
448
443
node,
449
444
sourceFile
450
445
} : Source & { node : Node } ) : Pick < DocEntry , 'url' | 'fileName' > => {
451
- const fileName = sourceFile . fileName ;
446
+ const { fileName} = sourceFile ;
452
447
453
448
if ( repo === undefined ) {
454
449
return { fileName} ;
0 commit comments