@@ -46,23 +46,24 @@ namespace ts.JsDoc {
4646 let jsDocTagNameCompletionEntries : CompletionEntry [ ] ;
4747 let jsDocTagCompletionEntries : CompletionEntry [ ] ;
4848
49- export function getJsDocCommentsFromDeclarations ( declarations ?: Declaration [ ] ) {
49+ export function getJsDocCommentsFromDeclarations ( declarations : Declaration [ ] | undefined ) {
50+ if ( ! declarations ) return emptyArray ;
5051 // Only collect doc comments from duplicate declarations once:
5152 // In case of a union property there might be same declaration multiple times
5253 // which only varies in type parameter
5354 // Eg. const a: Array<string> | Array<number>; a.length
5455 // The property length will have two declarations of property length coming
5556 // from Array<T> - Array<string> and Array<number>
5657 const documentationComment : SymbolDisplayPart [ ] = [ ] ;
57- forEachUnique ( declarations , declaration => {
58+ for ( const declaration of declarations ) {
5859 for ( const { comment } of getCommentHavingNodes ( declaration ) ) {
5960 if ( comment === undefined ) continue ;
6061 if ( documentationComment . length ) {
6162 documentationComment . push ( lineBreakPart ( ) ) ;
6263 }
6364 documentationComment . push ( textPart ( comment ) ) ;
6465 }
65- } ) ;
66+ }
6667 return documentationComment ;
6768 }
6869
@@ -77,15 +78,9 @@ namespace ts.JsDoc {
7778 }
7879 }
7980
80- export function getJsDocTagsFromDeclarations ( declarations ? : Declaration [ ] ) : JSDocTagInfo [ ] {
81+ export function getJsDocTagsFromDeclarations ( declarations : Declaration [ ] | undefined ) : JSDocTagInfo [ ] | undefined {
8182 // 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 ) } ) ) ) ;
8984 }
9085
9186 function getCommentText ( tag : JSDocTag ) : string | undefined {
@@ -119,25 +114,6 @@ namespace ts.JsDoc {
119114 }
120115 }
121116
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-
141117 export function getJSDocTagNameCompletions ( ) : CompletionEntry [ ] {
142118 return jsDocTagNameCompletionEntries || ( jsDocTagNameCompletionEntries = map ( jsDocTagNames , tagName => {
143119 return {
0 commit comments