@@ -25,6 +25,7 @@ import type { TranslatedString } from "../../internationalization/internationali
25
25
export class ImplementsPlugin extends ConverterComponent {
26
26
private resolved = new WeakSet < Reflection > ( ) ;
27
27
private postponed = new WeakMap < Reflection , Set < DeclarationReflection > > ( ) ;
28
+ private revivingSerialized = false ;
28
29
29
30
/**
30
31
* Create a new ImplementsPlugin instance.
@@ -44,7 +45,7 @@ export class ImplementsPlugin extends ConverterComponent {
44
45
this . onSignature . bind ( this ) ,
45
46
1000 ,
46
47
) ;
47
- this . application . on ( ApplicationEvents . REVIVE , this . resolve . bind ( this ) ) ;
48
+ this . application . on ( ApplicationEvents . REVIVE , this . onRevive . bind ( this ) ) ;
48
49
}
49
50
50
51
/**
@@ -55,7 +56,7 @@ export class ImplementsPlugin extends ConverterComponent {
55
56
classReflection : DeclarationReflection ,
56
57
interfaceReflection : DeclarationReflection ,
57
58
) {
58
- handleInheritedComments ( classReflection , interfaceReflection ) ;
59
+ this . handleInheritedComments ( classReflection , interfaceReflection ) ;
59
60
if ( ! interfaceReflection . children ) {
60
61
return ;
61
62
}
@@ -109,7 +110,7 @@ export class ImplementsPlugin extends ConverterComponent {
109
110
}
110
111
}
111
112
112
- handleInheritedComments ( classMember , interfaceMember ) ;
113
+ this . handleInheritedComments ( classMember , interfaceMember ) ;
113
114
} ) ;
114
115
}
115
116
@@ -130,7 +131,7 @@ export class ImplementsPlugin extends ConverterComponent {
130
131
) ;
131
132
132
133
for ( const parent of extendedTypes ) {
133
- handleInheritedComments ( reflection , parent . reflection ) ;
134
+ this . handleInheritedComments ( reflection , parent . reflection ) ;
134
135
135
136
for ( const parentMember of parent . reflection . children ?? [ ] ) {
136
137
const child = findMatchingMember ( parentMember , reflection ) ;
@@ -157,7 +158,7 @@ export class ImplementsPlugin extends ConverterComponent {
157
158
project ,
158
159
) ;
159
160
160
- handleInheritedComments ( child , parentMember ) ;
161
+ this . handleInheritedComments ( child , parentMember ) ;
161
162
}
162
163
}
163
164
}
@@ -167,6 +168,12 @@ export class ImplementsPlugin extends ConverterComponent {
167
168
this . resolve ( context . project ) ;
168
169
}
169
170
171
+ private onRevive ( project : ProjectReflection ) {
172
+ this . revivingSerialized = true ;
173
+ this . resolve ( project ) ;
174
+ this . revivingSerialized = false ;
175
+ }
176
+
170
177
private resolve ( project : ProjectReflection ) {
171
178
for ( const id in project . reflections ) {
172
179
const refl = project . reflections [ id ] ;
@@ -362,6 +369,105 @@ export class ImplementsPlugin extends ConverterComponent {
362
369
}
363
370
}
364
371
}
372
+
373
+ /**
374
+ * Responsible for copying comments from "parent" reflections defined
375
+ * in either a base class or implemented interface to the child class.
376
+ */
377
+ private handleInheritedComments (
378
+ child : DeclarationReflection ,
379
+ parent : DeclarationReflection ,
380
+ ) {
381
+ this . copyComment ( child , parent ) ;
382
+
383
+ if (
384
+ parent . kindOf ( ReflectionKind . Property ) &&
385
+ child . kindOf ( ReflectionKind . Accessor )
386
+ ) {
387
+ if ( child . getSignature ) {
388
+ this . copyComment ( child . getSignature , parent ) ;
389
+ child . getSignature . implementationOf = child . implementationOf ;
390
+ }
391
+ if ( child . setSignature ) {
392
+ this . copyComment ( child . setSignature , parent ) ;
393
+ child . setSignature . implementationOf = child . implementationOf ;
394
+ }
395
+ }
396
+ if (
397
+ parent . kindOf ( ReflectionKind . Accessor ) &&
398
+ child . kindOf ( ReflectionKind . Accessor )
399
+ ) {
400
+ if ( parent . getSignature && child . getSignature ) {
401
+ this . copyComment ( child . getSignature , parent . getSignature ) ;
402
+ }
403
+ if ( parent . setSignature && child . setSignature ) {
404
+ this . copyComment ( child . setSignature , parent . setSignature ) ;
405
+ }
406
+ }
407
+
408
+ if (
409
+ parent . kindOf ( ReflectionKind . FunctionOrMethod ) &&
410
+ parent . signatures &&
411
+ child . signatures
412
+ ) {
413
+ for ( const [ cs , ps ] of zip ( child . signatures , parent . signatures ) ) {
414
+ this . copyComment ( cs , ps ) ;
415
+ }
416
+ } else if (
417
+ parent . kindOf ( ReflectionKind . Property ) &&
418
+ parent . type instanceof ReflectionType &&
419
+ parent . type . declaration . signatures &&
420
+ child . signatures
421
+ ) {
422
+ for ( const [ cs , ps ] of zip (
423
+ child . signatures ,
424
+ parent . type . declaration . signatures ,
425
+ ) ) {
426
+ this . copyComment ( cs , ps ) ;
427
+ }
428
+ }
429
+ }
430
+
431
+ /**
432
+ * Copy the comment of the source reflection to the target reflection with a JSDoc style copy
433
+ * function. The TSDoc copy function is in the InheritDocPlugin.
434
+ */
435
+ private copyComment ( target : Reflection , source : Reflection ) {
436
+ if ( ! shouldCopyComment ( target , source , this . revivingSerialized ) ) {
437
+ return ;
438
+ }
439
+
440
+ target . comment = source . comment ! . clone ( ) ;
441
+
442
+ if (
443
+ target instanceof DeclarationReflection &&
444
+ source instanceof DeclarationReflection
445
+ ) {
446
+ for ( const [ tt , ts ] of zip (
447
+ target . typeParameters || [ ] ,
448
+ source . typeParameters || [ ] ,
449
+ ) ) {
450
+ this . copyComment ( tt , ts ) ;
451
+ }
452
+ }
453
+ if (
454
+ target instanceof SignatureReflection &&
455
+ source instanceof SignatureReflection
456
+ ) {
457
+ for ( const [ tt , ts ] of zip (
458
+ target . typeParameters || [ ] ,
459
+ source . typeParameters || [ ] ,
460
+ ) ) {
461
+ this . copyComment ( tt , ts ) ;
462
+ }
463
+ for ( const [ pt , ps ] of zip (
464
+ target . parameters || [ ] ,
465
+ source . parameters || [ ] ,
466
+ ) ) {
467
+ this . copyComment ( pt , ps ) ;
468
+ }
469
+ }
470
+ }
365
471
}
366
472
367
473
function constructorInheritance (
@@ -419,7 +525,9 @@ function createLink(
419
525
}
420
526
421
527
// Intentionally create broken links here. These will be replaced with real links during
422
- // resolution if we can do so.
528
+ // resolution if we can do so. We create broken links rather than real links because in the
529
+ // case of an inherited symbol, we'll end up referencing a single symbol ID rather than one
530
+ // for each class.
423
531
function link (
424
532
target : DeclarationReflection | SignatureReflection | undefined ,
425
533
) {
@@ -448,111 +556,30 @@ function createLink(
448
556
}
449
557
}
450
558
451
- /**
452
- * Responsible for copying comments from "parent" reflections defined
453
- * in either a base class or implemented interface to the child class.
454
- */
455
- function handleInheritedComments (
456
- child : DeclarationReflection ,
457
- parent : DeclarationReflection ,
559
+ function shouldCopyComment (
560
+ target : Reflection ,
561
+ source : Reflection ,
562
+ revivingSerialized : boolean ,
458
563
) {
459
- copyComment ( child , parent ) ;
460
-
461
- if (
462
- parent . kindOf ( ReflectionKind . Property ) &&
463
- child . kindOf ( ReflectionKind . Accessor )
464
- ) {
465
- if ( child . getSignature ) {
466
- copyComment ( child . getSignature , parent ) ;
467
- child . getSignature . implementationOf = child . implementationOf ;
468
- }
469
- if ( child . setSignature ) {
470
- copyComment ( child . setSignature , parent ) ;
471
- child . setSignature . implementationOf = child . implementationOf ;
472
- }
473
- }
474
- if (
475
- parent . kindOf ( ReflectionKind . Accessor ) &&
476
- child . kindOf ( ReflectionKind . Accessor )
477
- ) {
478
- if ( parent . getSignature && child . getSignature ) {
479
- copyComment ( child . getSignature , parent . getSignature ) ;
480
- }
481
- if ( parent . setSignature && child . setSignature ) {
482
- copyComment ( child . setSignature , parent . setSignature ) ;
483
- }
564
+ if ( ! source . comment ) {
565
+ return false ;
484
566
}
485
567
486
- if (
487
- parent . kindOf ( ReflectionKind . FunctionOrMethod ) &&
488
- parent . signatures &&
489
- child . signatures
490
- ) {
491
- for ( const [ cs , ps ] of zip ( child . signatures , parent . signatures ) ) {
492
- copyComment ( cs , ps ) ;
493
- }
494
- } else if (
495
- parent . kindOf ( ReflectionKind . Property ) &&
496
- parent . type instanceof ReflectionType &&
497
- parent . type . declaration . signatures &&
498
- child . signatures
499
- ) {
500
- for ( const [ cs , ps ] of zip (
501
- child . signatures ,
502
- parent . type . declaration . signatures ,
503
- ) ) {
504
- copyComment ( cs , ps ) ;
568
+ if ( target . comment ) {
569
+ // If we're reviving, then the revived project might have a better comment
570
+ // on source, so copy it.
571
+ if ( revivingSerialized && source . comment . similarTo ( target . comment ) ) {
572
+ return true ;
505
573
}
506
- }
507
- }
508
574
509
- /**
510
- * Copy the comment of the source reflection to the target reflection with a JSDoc style copy
511
- * function. The TSDoc copy function is in the InheritDocPlugin.
512
- */
513
- function copyComment ( target : Reflection , source : Reflection ) {
514
- if ( target . comment ) {
515
575
// We might still want to copy, if the child has a JSDoc style inheritDoc tag.
516
576
const tag = target . comment . getTag ( "@inheritDoc" ) ;
517
577
if ( ! tag || tag . name ) {
518
- return ;
578
+ return false ;
519
579
}
520
580
}
521
581
522
- if ( ! source . comment ) {
523
- return ;
524
- }
525
-
526
- target . comment = source . comment . clone ( ) ;
527
-
528
- if (
529
- target instanceof DeclarationReflection &&
530
- source instanceof DeclarationReflection
531
- ) {
532
- for ( const [ tt , ts ] of zip (
533
- target . typeParameters || [ ] ,
534
- source . typeParameters || [ ] ,
535
- ) ) {
536
- copyComment ( tt , ts ) ;
537
- }
538
- }
539
- if (
540
- target instanceof SignatureReflection &&
541
- source instanceof SignatureReflection
542
- ) {
543
- for ( const [ tt , ts ] of zip (
544
- target . typeParameters || [ ] ,
545
- source . typeParameters || [ ] ,
546
- ) ) {
547
- copyComment ( tt , ts ) ;
548
- }
549
- for ( const [ pt , ps ] of zip (
550
- target . parameters || [ ] ,
551
- source . parameters || [ ] ,
552
- ) ) {
553
- copyComment ( pt , ps ) ;
554
- }
555
- }
582
+ return true ;
556
583
}
557
584
558
585
function findMatchingMember (
0 commit comments