Skip to content

Commit

Permalink
fix: Set inheritedFrom on accessor signatures
Browse files Browse the repository at this point in the history
Resolves #1497

Also copy comments for inherited/implemented members which do not already have a comment - resolves #1498.
  • Loading branch information
Gerrit0 committed Feb 6, 2021
1 parent b449345 commit ccd519a
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/basic/src/classes.ts
Expand Up @@ -16,10 +16,10 @@ export interface NameInterface {
*
* It should be inherited by all subinterfaces.
*
* Links - these should all point to this property:
* Links - these should all point to this property on the base class
* - {@link name}
* - {@link NameInterface.name}
* - {@link "classes".NameInterface.name}
* - {@link classes.NameInterface.name}
* - {@link name Text} <-- This one goes away eventually
* - {@link name|Text}
* - {@link name | Text}
Expand Down
16 changes: 16 additions & 0 deletions src/lib/converter/plugins/ImplementsPlugin.ts
Expand Up @@ -83,6 +83,22 @@ export class ImplementsPlugin extends ConverterComponent {
);
copyComment(classMember, interfaceMember);

if (
interfaceMember.kindOf(ReflectionKind.Property) &&
classMember.kindOf(ReflectionKind.Accessor)
) {
if (classMember.getSignature) {
copyComment(classMember.getSignature, interfaceMember);
classMember.getSignature.implementationOf =
classMember.implementationOf;
}
if (classMember.setSignature) {
copyComment(classMember.setSignature, interfaceMember);
classMember.setSignature.implementationOf =
classMember.implementationOf;
}
}

if (
interfaceMember.kindOf(ReflectionKind.FunctionOrMethod) &&
interfaceMember.signatures &&
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/plugins/InheritDocPlugin.ts
Expand Up @@ -64,7 +64,7 @@ export class InheritDocPlugin extends ConverterComponent {
source instanceof DeclarationReflection &&
item instanceof SignatureReflection
) {
const isFunction = source?.kindOf(
const isFunction = source.kindOf(
ReflectionKind.FunctionOrMethod
);
if (isFunction) {
Expand Down
11 changes: 10 additions & 1 deletion src/lib/converter/utils/reflections.ts
Expand Up @@ -49,7 +49,7 @@ export function copyComment(target: Reflection, source: Reflection) {
* TSDoc overrides existing parameters entirely with inherited ones, while
* existing implementation merges them.
* To avoid breaking things, `inheritDoc` tag is additionally checked for the parameter,
* so the previous behaviour will continue to work.
* so the previous behavior will continue to work.
*
* TODO: When breaking change becomes acceptable remove legacy implementation
*/
Expand All @@ -61,6 +61,15 @@ export function copyComment(target: Reflection, source: Reflection) {
}
target.comment.removeTags("inheritdoc");
target.comment.copyFrom(source.comment);
} else if (!target.comment && source.comment) {
if (
target instanceof DeclarationReflection &&
source instanceof DeclarationReflection
) {
target.typeParameters = source.typeParameters;
}
target.comment = new Comment();
target.comment.copyFrom(source.comment);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/converter/interface/specs.json
Expand Up @@ -1027,6 +1027,9 @@
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"comment": {
"shortText": "Remove this subscription from its dispatcher"
},
"type": {
"type": "intrinsic",
"name": "void"
Expand Down
21 changes: 21 additions & 0 deletions src/test/renderer/specs/classes/classes.subclassa.html
Expand Up @@ -200,6 +200,27 @@ <h3>name</h3>
<p>Implementation of <a href="../interfaces/classes.printnameinterface.html">PrintNameInterface</a>.<a href="../interfaces/classes.printnameinterface.html#name">name</a></p>
<p>Overrides <a href="classes.baseclass.html">BaseClass</a>.<a href="classes.baseclass.html#name">name</a></p>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>This is a interface member of INameInterface.</p>
</div>
<p>It should be inherited by all subinterfaces.</p>
<p>Links - these should all point to this property on the base class</p>
<ul>
<li><a href="classes.subclassa.html#name">name</a></li>
<li><a href="../interfaces/classes.nameinterface.html#name">NameInterface.name</a></li>
<li><a href="../interfaces/classes.nameinterface.html#name">classes.NameInterface.name</a></li>
<li><a href="classes.subclassa.html#name">Text</a> &lt;-- This one goes away eventually</li>
<li><a href="classes.subclassa.html#name">Text</a></li>
<li><a href="classes.subclassa.html#name">Text</a></li>
<li><a href="../interfaces/classes.nameinterface.html#name">Text</a></li>
</ul>
<p>Links - these should point to the containing interface</p>
<ul>
<li><a href="../interfaces/classes.nameinterface.html">NameInterface</a></li>
<li>{@link &quot;classes&quot;.NameInterface}</li>
</ul>
</div>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static">
<a name="instance" class="tsd-anchor"></a>
Expand Down
5 changes: 5 additions & 0 deletions src/test/renderer/specs/classes/classes.subclassb.html
Expand Up @@ -170,6 +170,11 @@ <h3>name</h3>
<aside class="tsd-sources">
<p>Overrides <a href="classes.baseclass.html">BaseClass</a>.<a href="classes.baseclass.html#name">name</a></p>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>This is a simple public member.</p>
</div>
</div>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-static">
<a name="instance" class="tsd-anchor"></a>
Expand Down
4 changes: 2 additions & 2 deletions src/test/renderer/specs/interfaces/classes.nameinterface.html
Expand Up @@ -136,11 +136,11 @@ <h3>name</h3>
<p>This is a interface member of INameInterface.</p>
</div>
<p>It should be inherited by all subinterfaces.</p>
<p>Links - these should all point to this property:</p>
<p>Links - these should all point to this property on the base class</p>
<ul>
<li><a href="classes.nameinterface.html#name">name</a></li>
<li><a href="classes.nameinterface.html#name">NameInterface.name</a></li>
<li>{@link &quot;classes&quot;.NameInterface.name}</li>
<li><a href="classes.nameinterface.html#name">classes.NameInterface.name</a></li>
<li><a href="classes.nameinterface.html#name">Text</a> &lt;-- This one goes away eventually</li>
<li><a href="classes.nameinterface.html#name">Text</a></li>
<li><a href="classes.nameinterface.html#name">Text</a></li>
Expand Down
Expand Up @@ -132,11 +132,11 @@ <h3>name</h3>
<p>This is a interface member of INameInterface.</p>
</div>
<p>It should be inherited by all subinterfaces.</p>
<p>Links - these should all point to this property:</p>
<p>Links - these should all point to this property on the base class</p>
<ul>
<li><a href="classes.printnameinterface.html#name">name</a></li>
<li><a href="classes.nameinterface.html#name">NameInterface.name</a></li>
<li>{@link &quot;classes&quot;.NameInterface.name}</li>
<li><a href="classes.nameinterface.html#name">classes.NameInterface.name</a></li>
<li><a href="classes.printnameinterface.html#name">Text</a> &lt;-- This one goes away eventually</li>
<li><a href="classes.printnameinterface.html#name">Text</a></li>
<li><a href="classes.printnameinterface.html#name">Text</a></li>
Expand Down

0 comments on commit ccd519a

Please sign in to comment.