@@ -46,23 +46,24 @@ namespace ts.JsDoc {
46
46
let jsDocTagNameCompletionEntries : CompletionEntry [ ] ;
47
47
let jsDocTagCompletionEntries : CompletionEntry [ ] ;
48
48
49
- export function getJsDocCommentsFromDeclarations ( declarations ?: Declaration [ ] ) {
49
+ export function getJsDocCommentsFromDeclarations ( declarations : Declaration [ ] | undefined ) {
50
+ if ( ! declarations ) return emptyArray ;
50
51
// Only collect doc comments from duplicate declarations once:
51
52
// In case of a union property there might be same declaration multiple times
52
53
// which only varies in type parameter
53
54
// Eg. const a: Array<string> | Array<number>; a.length
54
55
// The property length will have two declarations of property length coming
55
56
// from Array<T> - Array<string> and Array<number>
56
57
const documentationComment : SymbolDisplayPart [ ] = [ ] ;
57
- forEachUnique ( declarations , declaration => {
58
+ for ( const declaration of declarations ) {
58
59
for ( const { comment } of getCommentHavingNodes ( declaration ) ) {
59
60
if ( comment === undefined ) continue ;
60
61
if ( documentationComment . length ) {
61
62
documentationComment . push ( lineBreakPart ( ) ) ;
62
63
}
63
64
documentationComment . push ( textPart ( comment ) ) ;
64
65
}
65
- } ) ;
66
+ }
66
67
return documentationComment ;
67
68
}
68
69
@@ -77,15 +78,9 @@ namespace ts.JsDoc {
77
78
}
78
79
}
79
80
80
- export function getJsDocTagsFromDeclarations ( declarations ? : Declaration [ ] ) : JSDocTagInfo [ ] {
81
+ export function getJsDocTagsFromDeclarations ( declarations : Declaration [ ] | undefined ) : JSDocTagInfo [ ] | undefined {
81
82
// Only collect doc comments from duplicate declarations once.
82
- const tags : JSDocTagInfo [ ] = [ ] ;
83
- forEachUnique ( declarations , declaration => {
84
- for ( const tag of getJSDocTags ( declaration ) ) {
85
- tags . push ( { name : tag . tagName . text , text : getCommentText ( tag ) } ) ;
86
- }
87
- } ) ;
88
- return tags ;
83
+ return flatMap ( declarations , d => getJSDocTags ( d ) . map ( tag => ( { name : tag . tagName . text , text : getCommentText ( tag ) } ) ) ) ;
89
84
}
90
85
91
86
function getCommentText ( tag : JSDocTag ) : string | undefined {
@@ -119,25 +114,6 @@ namespace ts.JsDoc {
119
114
}
120
115
}
121
116
122
- /**
123
- * Iterates through 'array' by index and performs the callback on each element of array until the callback
124
- * returns a truthy value, then returns that value.
125
- * If no such value is found, the callback is applied to each element of array and undefined is returned.
126
- */
127
- function forEachUnique < T , U > ( array : T [ ] , callback : ( element : T , index : number ) => U ) : U {
128
- if ( array ) {
129
- for ( let i = 0 ; i < array . length ; i ++ ) {
130
- if ( array . indexOf ( array [ i ] ) === i ) {
131
- const result = callback ( array [ i ] , i ) ;
132
- if ( result ) {
133
- return result ;
134
- }
135
- }
136
- }
137
- }
138
- return undefined ;
139
- }
140
-
141
117
export function getJSDocTagNameCompletions ( ) : CompletionEntry [ ] {
142
118
return jsDocTagNameCompletionEntries || ( jsDocTagNameCompletionEntries = map ( jsDocTagNames , tagName => {
143
119
return {
0 commit comments