1
1
'use strict' ;
2
2
3
3
const ts = require ( 'typescript' ) ;
4
- const fs = require ( 'fs' ) ;
5
4
const marked = require ( 'marked' ) ;
6
5
7
6
const renderer = new marked . Renderer ( ) ;
8
7
renderer . link = ( href , title , text ) => ( `<a href=\"${ href } \" target="_blank" title=\"${ title } \">${ text } </a>` ) ;
9
8
marked . setOptions ( { gfm : true } ) ;
10
9
11
- const getDescription = ( symbol ) => marked (
12
- ts . displayPartsToString ( symbol . getDocumentationComment ( ) ) ,
10
+ const getDescription = ( symbol , typeChecker ) => marked (
11
+ ts . displayPartsToString ( symbol . getDocumentationComment ( typeChecker ) ) ,
13
12
{ renderer}
14
13
) ;
15
14
@@ -23,21 +22,21 @@ const ANGULAR_LIFECYCLE_METHODS = [
23
22
'ngAfterViewInit' , 'ngAfterViewChecked' , 'writeValue' , 'registerOnChange' , 'registerOnTouched' , 'setDisabledState'
24
23
] ;
25
24
26
- function isInternalMember ( member ) {
25
+ function isInternalMember ( member , typeChecker ) {
27
26
// todo: could be an issue, as for now lets skip members without a symbol
28
27
if ( ! member . symbol ) {
29
28
return true ;
30
29
}
31
- const jsDoc = ts . displayPartsToString ( member . symbol . getDocumentationComment ( ) ) ;
30
+ const jsDoc = ts . displayPartsToString ( member . symbol . getDocumentationComment ( typeChecker ) ) ;
32
31
return jsDoc . trim ( ) . length === 0 || jsDoc . indexOf ( '@internal' ) > - 1 ;
33
32
}
34
33
35
34
function isAngularLifecycleHook ( methodName ) {
36
35
return ANGULAR_LIFECYCLE_METHODS . indexOf ( methodName ) >= 0 ;
37
36
}
38
37
39
- function isPrivateOrInternal ( member ) {
40
- return ( ( member . flags & ts . NodeFlags . Private ) !== 0 ) || isInternalMember ( member ) ;
38
+ function isPrivateOrInternal ( member , typeChecker ) {
39
+ return ( ( member . flags & ts . NodeFlags . Private ) !== 0 ) || isInternalMember ( member , typeChecker ) ;
41
40
}
42
41
43
42
class APIDocVisitor {
@@ -66,7 +65,7 @@ class APIDocVisitor {
66
65
67
66
visitInterfaceDeclaration ( fileName , interfaceDeclaration ) {
68
67
const symbol = this . program . getTypeChecker ( ) . getSymbolAtLocation ( interfaceDeclaration . name ) ;
69
- const description = getDescription ( symbol ) ;
68
+ const description = getDescription ( symbol , this . typeChecker ) ;
70
69
const className = interfaceDeclaration . name . text ;
71
70
const members = this . visitMembers ( interfaceDeclaration . members ) ;
72
71
@@ -81,7 +80,7 @@ class APIDocVisitor {
81
80
82
81
visitClassDeclaration ( fileName , classDeclaration ) {
83
82
const symbol = this . program . getTypeChecker ( ) . getSymbolAtLocation ( classDeclaration . name ) ;
84
- const description = getDescription ( symbol ) ;
83
+ const description = getDescription ( symbol , this . typeChecker ) ;
85
84
const className = classDeclaration . name . text ;
86
85
let directiveInfo , members ;
87
86
@@ -165,7 +164,7 @@ class APIDocVisitor {
165
164
} else if ( outDecorator ) {
166
165
outputs . push ( this . visitOutput ( members [ i ] , outDecorator ) ) ;
167
166
168
- } else if ( ! isPrivateOrInternal ( members [ i ] ) ) {
167
+ } else if ( ! isPrivateOrInternal ( members [ i ] , this . typeChecker ) ) {
169
168
if ( ( members [ i ] . kind === ts . SyntaxKind . MethodDeclaration ||
170
169
members [ i ] . kind === ts . SyntaxKind . MethodSignature ) &&
171
170
! isAngularLifecycleHook ( members [ i ] . name . text ) ) {
@@ -188,7 +187,7 @@ class APIDocVisitor {
188
187
visitMethodDeclaration ( method ) {
189
188
return {
190
189
name : method . name . text ,
191
- description : getDescription ( method . symbol ) ,
190
+ description : getDescription ( method . symbol , this . typeChecker ) ,
192
191
args : method . parameters ? method . parameters . map ( ( prop ) => this . visitArgument ( prop ) ) : [ ] ,
193
192
returnType : this . visitType ( method . type )
194
193
}
@@ -204,7 +203,7 @@ class APIDocVisitor {
204
203
name : inArgs . length ? inArgs [ 0 ] . text : property . name . text ,
205
204
defaultValue : property . initializer ? this . stringifyDefaultValue ( property . initializer ) : undefined ,
206
205
type : this . visitType ( property ) ,
207
- description : getDescription ( property . symbol )
206
+ description : getDescription ( property . symbol , this . typeChecker )
208
207
} ;
209
208
}
210
209
@@ -222,7 +221,7 @@ class APIDocVisitor {
222
221
const outArgs = outDecorator . expression . arguments ;
223
222
return {
224
223
name : outArgs . length ? outArgs [ 0 ] . text : property . name . text ,
225
- description : getDescription ( property . symbol )
224
+ description : getDescription ( property . symbol , this . typeChecker )
226
225
} ;
227
226
}
228
227
@@ -231,7 +230,7 @@ class APIDocVisitor {
231
230
name : property . name . text ,
232
231
defaultValue : property . initializer ? this . stringifyDefaultValue ( property . initializer ) : undefined ,
233
232
type : this . visitType ( property ) ,
234
- description : getDescription ( property . symbol )
233
+ description : getDescription ( property . symbol , this . typeChecker )
235
234
} ;
236
235
}
237
236
0 commit comments