From 30555f17766d0d428866c165c616065573b2409f Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 29 Oct 2022 15:01:02 -0600 Subject: [PATCH] Fix comment discovery for `@inheritDoc` Resolves #2087 --- CHANGELOG.md | 4 ++++ src/lib/converter/plugins/InheritDocPlugin.ts | 18 ++++++++++++++++++ src/test/converter2/issues/gh2087.ts | 9 +++++++++ src/test/issueTests.ts | 8 ++++++++ 4 files changed, 39 insertions(+) create mode 100644 src/test/converter2/issues/gh2087.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f50b4a0ff..e2c6ecad4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +### Bug Fixes + +- Fixed comment discovery for `@inheritDoc` if inheriting from a function type alias, #2087. + ## v0.23.19 (2022-10-28) ### Bug Fixes diff --git a/src/lib/converter/plugins/InheritDocPlugin.ts b/src/lib/converter/plugins/InheritDocPlugin.ts index 268220f79..4ba1f0317 100644 --- a/src/lib/converter/plugins/InheritDocPlugin.ts +++ b/src/lib/converter/plugins/InheritDocPlugin.ts @@ -2,6 +2,7 @@ import { Comment, DeclarationReflection, ReflectionKind, + ReflectionType, SignatureReflection, } from "../../models"; import { Component, ConverterComponent } from "../components"; @@ -105,6 +106,23 @@ export class InheritDocPlugin extends ConverterComponent { private copyComment(source: Reflection, target: Reflection) { if (!target.comment) return; + if ( + !source.comment && + source instanceof DeclarationReflection && + source.signatures + ) { + source = source.signatures[0]; + } + + if ( + !source.comment && + source instanceof DeclarationReflection && + source.type instanceof ReflectionType && + source.type.declaration.signatures + ) { + source = source.type.declaration.signatures[0]; + } + if (!source.comment) { this.application.logger.warn( `${target.getFullName()} tried to copy a comment from ${source.getFullName()} with @inheritDoc, but the source has no associated comment.` diff --git a/src/test/converter2/issues/gh2087.ts b/src/test/converter2/issues/gh2087.ts new file mode 100644 index 000000000..7fe250cc0 --- /dev/null +++ b/src/test/converter2/issues/gh2087.ts @@ -0,0 +1,9 @@ +/** Foo type comment */ +export type Foo = () => number; + +export class Bar { + /** + * {@inheritDoc Foo:type} + */ + x = 1; +} diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index 1587e93f7..c35c209e0 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -817,4 +817,12 @@ export const issueTests: { const sig = cap.signatures![0]; equal(sig.type?.toString(), "Capitalize"); }, + + gh2087(project) { + const x = query(project, "Bar.x"); + equal( + Comment.combineDisplayParts(x.comment?.summary), + "Foo type comment" + ); + }, };