Skip to content

Commit ccd519a

Browse files
committed
fix: Set inheritedFrom on accessor signatures
Resolves #1497 Also copy comments for inherited/implemented members which do not already have a comment - resolves #1498.
1 parent b449345 commit ccd519a

File tree

9 files changed

+62
-8
lines changed

9 files changed

+62
-8
lines changed

examples/basic/src/classes.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export interface NameInterface {
1616
*
1717
* It should be inherited by all subinterfaces.
1818
*
19-
* Links - these should all point to this property:
19+
* Links - these should all point to this property on the base class
2020
* - {@link name}
2121
* - {@link NameInterface.name}
22-
* - {@link "classes".NameInterface.name}
22+
* - {@link classes.NameInterface.name}
2323
* - {@link name Text} <-- This one goes away eventually
2424
* - {@link name|Text}
2525
* - {@link name | Text}

src/lib/converter/plugins/ImplementsPlugin.ts

+16
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ export class ImplementsPlugin extends ConverterComponent {
8383
);
8484
copyComment(classMember, interfaceMember);
8585

86+
if (
87+
interfaceMember.kindOf(ReflectionKind.Property) &&
88+
classMember.kindOf(ReflectionKind.Accessor)
89+
) {
90+
if (classMember.getSignature) {
91+
copyComment(classMember.getSignature, interfaceMember);
92+
classMember.getSignature.implementationOf =
93+
classMember.implementationOf;
94+
}
95+
if (classMember.setSignature) {
96+
copyComment(classMember.setSignature, interfaceMember);
97+
classMember.setSignature.implementationOf =
98+
classMember.implementationOf;
99+
}
100+
}
101+
86102
if (
87103
interfaceMember.kindOf(ReflectionKind.FunctionOrMethod) &&
88104
interfaceMember.signatures &&

src/lib/converter/plugins/InheritDocPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class InheritDocPlugin extends ConverterComponent {
6464
source instanceof DeclarationReflection &&
6565
item instanceof SignatureReflection
6666
) {
67-
const isFunction = source?.kindOf(
67+
const isFunction = source.kindOf(
6868
ReflectionKind.FunctionOrMethod
6969
);
7070
if (isFunction) {

src/lib/converter/utils/reflections.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function copyComment(target: Reflection, source: Reflection) {
4949
* TSDoc overrides existing parameters entirely with inherited ones, while
5050
* existing implementation merges them.
5151
* To avoid breaking things, `inheritDoc` tag is additionally checked for the parameter,
52-
* so the previous behaviour will continue to work.
52+
* so the previous behavior will continue to work.
5353
*
5454
* TODO: When breaking change becomes acceptable remove legacy implementation
5555
*/
@@ -61,6 +61,15 @@ export function copyComment(target: Reflection, source: Reflection) {
6161
}
6262
target.comment.removeTags("inheritdoc");
6363
target.comment.copyFrom(source.comment);
64+
} else if (!target.comment && source.comment) {
65+
if (
66+
target instanceof DeclarationReflection &&
67+
source instanceof DeclarationReflection
68+
) {
69+
target.typeParameters = source.typeParameters;
70+
}
71+
target.comment = new Comment();
72+
target.comment.copyFrom(source.comment);
6473
}
6574
}
6675

src/test/converter/interface/specs.json

+3
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,9 @@
10271027
"kind": 4096,
10281028
"kindString": "Call signature",
10291029
"flags": {},
1030+
"comment": {
1031+
"shortText": "Remove this subscription from its dispatcher"
1032+
},
10301033
"type": {
10311034
"type": "intrinsic",
10321035
"name": "void"

src/test/renderer/specs/classes/classes.subclassa.html

+21
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,27 @@ <h3>name</h3>
200200
<p>Implementation of <a href="../interfaces/classes.printnameinterface.html">PrintNameInterface</a>.<a href="../interfaces/classes.printnameinterface.html#name">name</a></p>
201201
<p>Overrides <a href="classes.baseclass.html">BaseClass</a>.<a href="classes.baseclass.html#name">name</a></p>
202202
</aside>
203+
<div class="tsd-comment tsd-typography">
204+
<div class="lead">
205+
<p>This is a interface member of INameInterface.</p>
206+
</div>
207+
<p>It should be inherited by all subinterfaces.</p>
208+
<p>Links - these should all point to this property on the base class</p>
209+
<ul>
210+
<li><a href="classes.subclassa.html#name">name</a></li>
211+
<li><a href="../interfaces/classes.nameinterface.html#name">NameInterface.name</a></li>
212+
<li><a href="../interfaces/classes.nameinterface.html#name">classes.NameInterface.name</a></li>
213+
<li><a href="classes.subclassa.html#name">Text</a> &lt;-- This one goes away eventually</li>
214+
<li><a href="classes.subclassa.html#name">Text</a></li>
215+
<li><a href="classes.subclassa.html#name">Text</a></li>
216+
<li><a href="../interfaces/classes.nameinterface.html#name">Text</a></li>
217+
</ul>
218+
<p>Links - these should point to the containing interface</p>
219+
<ul>
220+
<li><a href="../interfaces/classes.nameinterface.html">NameInterface</a></li>
221+
<li>{@link &quot;classes&quot;.NameInterface}</li>
222+
</ul>
223+
</div>
203224
</section>
204225
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static">
205226
<a name="instance" class="tsd-anchor"></a>

src/test/renderer/specs/classes/classes.subclassb.html

+5
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ <h3>name</h3>
170170
<aside class="tsd-sources">
171171
<p>Overrides <a href="classes.baseclass.html">BaseClass</a>.<a href="classes.baseclass.html#name">name</a></p>
172172
</aside>
173+
<div class="tsd-comment tsd-typography">
174+
<div class="lead">
175+
<p>This is a simple public member.</p>
176+
</div>
177+
</div>
173178
</section>
174179
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static">
175180
<a name="instance" class="tsd-anchor"></a>

src/test/renderer/specs/interfaces/classes.nameinterface.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ <h3>name</h3>
136136
<p>This is a interface member of INameInterface.</p>
137137
</div>
138138
<p>It should be inherited by all subinterfaces.</p>
139-
<p>Links - these should all point to this property:</p>
139+
<p>Links - these should all point to this property on the base class</p>
140140
<ul>
141141
<li><a href="classes.nameinterface.html#name">name</a></li>
142142
<li><a href="classes.nameinterface.html#name">NameInterface.name</a></li>
143-
<li>{@link &quot;classes&quot;.NameInterface.name}</li>
143+
<li><a href="classes.nameinterface.html#name">classes.NameInterface.name</a></li>
144144
<li><a href="classes.nameinterface.html#name">Text</a> &lt;-- This one goes away eventually</li>
145145
<li><a href="classes.nameinterface.html#name">Text</a></li>
146146
<li><a href="classes.nameinterface.html#name">Text</a></li>

src/test/renderer/specs/interfaces/classes.printnameinterface.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ <h3>name</h3>
132132
<p>This is a interface member of INameInterface.</p>
133133
</div>
134134
<p>It should be inherited by all subinterfaces.</p>
135-
<p>Links - these should all point to this property:</p>
135+
<p>Links - these should all point to this property on the base class</p>
136136
<ul>
137137
<li><a href="classes.printnameinterface.html#name">name</a></li>
138138
<li><a href="classes.nameinterface.html#name">NameInterface.name</a></li>
139-
<li>{@link &quot;classes&quot;.NameInterface.name}</li>
139+
<li><a href="classes.nameinterface.html#name">classes.NameInterface.name</a></li>
140140
<li><a href="classes.printnameinterface.html#name">Text</a> &lt;-- This one goes away eventually</li>
141141
<li><a href="classes.printnameinterface.html#name">Text</a></li>
142142
<li><a href="classes.printnameinterface.html#name">Text</a></li>

0 commit comments

Comments
 (0)