@@ -54,7 +54,8 @@ namespace ts.JsDoc {
54
54
// from Array<T> - Array<string> and Array<number>
55
55
const documentationComment : SymbolDisplayPart [ ] = [ ] ;
56
56
forEachUnique ( declarations , declaration => {
57
- for ( const comment of getCommentsFromDeclaration ( declaration ) ) {
57
+ for ( const { comment } of getCommentHavingNodes ( declaration ) ) {
58
+ if ( comment === undefined ) continue ;
58
59
if ( documentationComment . length ) {
59
60
documentationComment . push ( lineBreakPart ( ) ) ;
60
61
}
@@ -64,20 +65,15 @@ namespace ts.JsDoc {
64
65
return documentationComment ;
65
66
}
66
67
67
- function getCommentsFromDeclaration ( declaration : Declaration ) : string [ ] {
68
+ function getCommentHavingNodes ( declaration : Declaration ) : ReadonlyArray < JSDoc | JSDocTag > {
68
69
switch ( declaration . kind ) {
69
70
case SyntaxKind . JSDocPropertyTag :
70
- return [ ( declaration as JSDocPropertyTag ) . comment ] ;
71
+ return [ declaration as JSDocPropertyTag ] ;
72
+ case SyntaxKind . JSDocTypedefTag :
73
+ return [ ( declaration as JSDocTypedefTag ) . parent ] ;
71
74
default :
72
- return mapDefined ( getAllJSDocs ( declaration ) , doc => doc . comment ) ;
73
- }
74
- }
75
-
76
- function getAllJSDocs ( node : Node ) : ( JSDoc | JSDocTag ) [ ] {
77
- if ( isJSDocTypedefTag ( node ) ) {
78
- return [ node . parent ] ;
75
+ return getJSDocCommentsAndTags ( declaration ) ;
79
76
}
80
- return getJSDocCommentsAndTags ( node ) ;
81
77
}
82
78
83
79
export function getJsDocTagsFromDeclarations ( declarations ?: Declaration [ ] ) : JSDocTagInfo [ ] {
@@ -91,7 +87,7 @@ namespace ts.JsDoc {
91
87
return tags ;
92
88
}
93
89
94
- function getCommentText ( tag : JSDocTag ) : string {
90
+ function getCommentText ( tag : JSDocTag ) : string | undefined {
95
91
const { comment } = tag ;
96
92
switch ( tag . kind ) {
97
93
case SyntaxKind . JSDocAugmentsTag :
@@ -106,15 +102,19 @@ namespace ts.JsDoc {
106
102
const { name } = tag as JSDocTypedefTag | JSDocPropertyTag | JSDocParameterTag ;
107
103
return name ? withNode ( name ) : comment ;
108
104
default :
109
- return comment ;
105
+ return comment || "" ;
110
106
}
111
107
112
108
function withNode ( node : Node ) {
113
- return ` ${ node . getText ( ) } ${ comment } ` ;
109
+ return addComment ( node . getText ( ) ) ;
114
110
}
115
111
116
112
function withList ( list : NodeArray < Node > ) : string {
117
- return `${ list . map ( x => x . getText ( ) ) } ${ comment } ` ;
113
+ return addComment ( list . map ( x => x . getText ( ) ) . join ( ", " ) ) ;
114
+ }
115
+
116
+ function addComment ( s : string ) {
117
+ return comment === undefined ? s : `${ s } ${ comment } ` ;
118
118
}
119
119
}
120
120
0 commit comments