1- import { IntrinsicType , Type , UnionType } from "../../models" ;
1+ import {
2+ Comment ,
3+ DeclarationReflection ,
4+ IntrinsicType ,
5+ Reflection ,
6+ SignatureReflection ,
7+ Type ,
8+ UnionType ,
9+ } from "../../models" ;
210
311export function removeUndefined ( type : Type ) {
412 if ( type instanceof UnionType ) {
@@ -13,3 +21,73 @@ export function removeUndefined(type: Type) {
1321 }
1422 return type ;
1523}
24+
25+ /**
26+ * Copy the comment of the source reflection to the target reflection.
27+ *
28+ * @param target - Reflection with comment containing `inheritdoc` tag
29+ * @param source - Referenced reflection
30+ */
31+ export function copyComment ( target : Reflection , source : Reflection ) {
32+ if (
33+ target . comment &&
34+ source . comment &&
35+ target . comment . hasTag ( "inheritdoc" )
36+ ) {
37+ if (
38+ target instanceof DeclarationReflection &&
39+ source instanceof DeclarationReflection
40+ ) {
41+ target . typeParameters = source . typeParameters ;
42+ }
43+ if (
44+ target instanceof SignatureReflection &&
45+ source instanceof SignatureReflection
46+ ) {
47+ target . typeParameters = source . typeParameters ;
48+ /**
49+ * TSDoc overrides existing parameters entirely with inherited ones, while
50+ * existing implementation merges them.
51+ * To avoid breaking things, `inheritDoc` tag is additionally checked for the parameter,
52+ * so the previous behaviour will continue to work.
53+ *
54+ * TODO: When breaking change becomes acceptable remove legacy implementation
55+ */
56+ if ( target . comment . getTag ( "inheritdoc" ) ?. paramName ) {
57+ target . parameters = source . parameters ;
58+ } else {
59+ legacyCopyImplementation ( target , source ) ;
60+ }
61+ }
62+ target . comment . removeTags ( "inheritdoc" ) ;
63+ target . comment . copyFrom ( source . comment ) ;
64+ }
65+ }
66+
67+ /**
68+ * Copy comments from source reflection to target reflection, parameters are merged.
69+ *
70+ * @param target - Reflection with comment containing `inheritdoc` tag
71+ * @param source - Parent reflection
72+ */
73+ function legacyCopyImplementation (
74+ target : SignatureReflection ,
75+ source : SignatureReflection
76+ ) {
77+ if ( target . parameters && source . parameters ) {
78+ for (
79+ let index = 0 , count = target . parameters . length ;
80+ index < count ;
81+ index ++
82+ ) {
83+ const sourceParameter = source . parameters [ index ] ;
84+ if ( sourceParameter && sourceParameter . comment ) {
85+ const targetParameter = target . parameters [ index ] ;
86+ if ( ! targetParameter . comment ) {
87+ targetParameter . comment = new Comment ( ) ;
88+ targetParameter . comment . copyFrom ( sourceParameter . comment ) ;
89+ }
90+ }
91+ }
92+ }
93+ }
0 commit comments