7
7
ReflectionKind ,
8
8
TypeParameterReflection ,
9
9
DeclarationReflection ,
10
+ SignatureReflection ,
10
11
} from "../../models/reflections/index" ;
11
12
import { Component , ConverterComponent } from "../components" ;
12
13
import {
@@ -17,7 +18,7 @@ import {
17
18
import { Converter } from "../converter" ;
18
19
import { Context } from "../context" ;
19
20
import { partition , uniq } from "lodash" ;
20
- import { SourceReference } from "../../models" ;
21
+ import { ReflectionType , SourceReference } from "../../models" ;
21
22
import { BindOption , filterMap , removeIfPresent } from "../../utils" ;
22
23
23
24
/**
@@ -269,54 +270,74 @@ export class CommentPlugin extends ConverterComponent {
269
270
return ;
270
271
}
271
272
272
- const signatures = reflection . getAllSignatures ( ) ;
273
- if ( signatures . length ) {
274
- const comment = reflection . comment ;
275
- if ( comment && comment . hasTag ( "returns" ) ) {
276
- comment . returns = comment . getTag ( "returns" ) ! . text ;
277
- comment . removeTags ( "returns" ) ;
278
- }
273
+ if ( reflection . type instanceof ReflectionType ) {
274
+ this . addCommentToSignatures (
275
+ reflection ,
276
+ reflection . type . declaration . getNonIndexSignatures ( )
277
+ ) ;
278
+ } else {
279
+ this . addCommentToSignatures (
280
+ reflection ,
281
+ reflection . getNonIndexSignatures ( )
282
+ ) ;
283
+ }
284
+ }
279
285
280
- signatures . forEach ( ( signature ) => {
281
- let childComment = signature . comment ;
282
- if ( childComment && childComment . hasTag ( "returns" ) ) {
283
- childComment . returns = childComment . getTag ( "returns" ) ! . text ;
284
- childComment . removeTags ( "returns" ) ;
285
- }
286
+ private addCommentToSignatures (
287
+ reflection : DeclarationReflection ,
288
+ signatures : SignatureReflection [ ]
289
+ ) {
290
+ if ( ! signatures . length ) {
291
+ return ;
292
+ }
286
293
287
- if ( comment ) {
288
- if ( ! childComment ) {
289
- childComment = signature . comment = new Comment ( ) ;
290
- }
294
+ let movedComment = false ;
295
+ const comment = reflection . comment ;
296
+ if ( comment && comment . hasTag ( "returns" ) ) {
297
+ comment . returns = comment . getTag ( "returns" ) ! . text ;
298
+ comment . removeTags ( "returns" ) ;
299
+ }
291
300
292
- childComment . shortText =
293
- childComment . shortText || comment . shortText ;
294
- childComment . text = childComment . text || comment . text ;
295
- childComment . returns =
296
- childComment . returns || comment . returns ;
297
- childComment . tags = childComment . tags || comment . tags ;
298
- }
301
+ signatures . forEach ( ( signature ) => {
302
+ let childComment = signature . comment ;
303
+ if ( childComment && childComment . hasTag ( "returns" ) ) {
304
+ childComment . returns = childComment . getTag ( "returns" ) ! . text ;
305
+ childComment . removeTags ( "returns" ) ;
306
+ }
299
307
300
- if ( signature . parameters ) {
301
- signature . parameters . forEach ( ( parameter ) => {
302
- let tag : CommentTag | undefined ;
303
- if ( childComment ) {
304
- tag = childComment . getTag ( "param" , parameter . name ) ;
305
- }
306
- if ( comment && ! tag ) {
307
- tag = comment . getTag ( "param" , parameter . name ) ;
308
- }
309
- if ( tag ) {
310
- parameter . comment = new Comment ( tag . text ) ;
311
- }
312
- } ) ;
308
+ if ( comment ) {
309
+ if ( ! childComment ) {
310
+ movedComment = true ;
311
+ childComment = signature . comment = new Comment ( ) ;
313
312
}
314
313
315
- childComment ?. removeTags ( "param" ) ;
316
- } ) ;
314
+ childComment . shortText =
315
+ childComment . shortText || comment . shortText ;
316
+ childComment . text = childComment . text || comment . text ;
317
+ childComment . returns = childComment . returns || comment . returns ;
318
+ childComment . tags = childComment . tags || comment . tags ;
319
+ }
317
320
318
- comment ?. removeTags ( "param" ) ;
319
- }
321
+ if ( signature . parameters ) {
322
+ signature . parameters . forEach ( ( parameter ) => {
323
+ let tag : CommentTag | undefined ;
324
+ if ( childComment ) {
325
+ tag = childComment . getTag ( "param" , parameter . name ) ;
326
+ }
327
+ if ( comment && ! tag ) {
328
+ tag = comment . getTag ( "param" , parameter . name ) ;
329
+ }
330
+ if ( tag ) {
331
+ parameter . comment = new Comment ( tag . text ) ;
332
+ }
333
+ } ) ;
334
+ }
335
+
336
+ childComment ?. removeTags ( "param" ) ;
337
+ } ) ;
338
+
339
+ comment ?. removeTags ( "param" ) ;
340
+ if ( movedComment ) reflection . comment = void 0 ;
320
341
}
321
342
322
343
private removeExcludedTags ( comment : Comment ) {
0 commit comments