diff --git a/CHANGELOG.md b/CHANGELOG.md index b91514186..ab656789a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Optimized icon caching to reduce file size in generated HTML documentation, #2287. - Added `MarkdownEvent.INCLUDE` for plugins, #2284. +### Bug Fixes + +- Comments are no longer removed from classes/interfaces containing call signatures, #2290. + ### Thanks! - @krisztianb diff --git a/src/lib/converter/plugins/CommentPlugin.ts b/src/lib/converter/plugins/CommentPlugin.ts index 42e167aa9..ae4e3e295 100644 --- a/src/lib/converter/plugins/CommentPlugin.ts +++ b/src/lib/converter/plugins/CommentPlugin.ts @@ -376,12 +376,16 @@ export class CommentPlugin extends ConverterComponent { return; } - const comment = reflection.comment; + const comment = reflection.kindOf(ReflectionKind.ClassOrInterface) + ? undefined + : reflection.comment; // Since this reflection has signatures, remove the comment from the parent // reflection. This is important so that in type aliases we don't end up with // a comment rendered twice. - delete reflection.comment; + if (!reflection.kindOf(ReflectionKind.ClassOrInterface)) { + delete reflection.comment; + } for (const signature of signatures) { const childComment = (signature.comment ||= comment?.clone()); diff --git a/src/test/converter/interface/specs.json b/src/test/converter/interface/specs.json index 801ed129f..df317345b 100644 --- a/src/test/converter/interface/specs.json +++ b/src/test/converter/interface/specs.json @@ -1870,6 +1870,14 @@ "variant": "declaration", "kind": 256, "flags": {}, + "comment": { + "summary": [ + { + "kind": "text", + "text": "Function signature of an event listener callback" + } + ] + }, "sources": [ { "fileName": "interface-implementation.ts", diff --git a/src/test/converter2/issues/gh2290.ts b/src/test/converter2/issues/gh2290.ts new file mode 100644 index 000000000..f0d7906b5 --- /dev/null +++ b/src/test/converter2/issues/gh2290.ts @@ -0,0 +1,14 @@ +/** Int comment */ +export interface CallSignature { + /** Sig comment */ + (x: string): void; +} + +/** Int comment */ +export interface CallSignature2 { + /** Sig comment */ + (x: string): void; + + /** Prop comment */ + prop: 123; +} diff --git a/src/test/issues.c2.test.ts b/src/test/issues.c2.test.ts index c0d851fa8..e531ddd10 100644 --- a/src/test/issues.c2.test.ts +++ b/src/test/issues.c2.test.ts @@ -27,7 +27,7 @@ import { TestLogger } from "./TestLogger"; import { clearCommentCache } from "../lib/converter/comments"; import { join } from "path"; import { existsSync } from "fs"; -import { getLinks, query } from "./utils"; +import { getComment, getLinks, query } from "./utils"; const base = getConverter2Base(); const app = getConverter2App(); @@ -1111,4 +1111,26 @@ describe("Issue Tests", () => { }, ]); }); + + it("Handles comments on interfaces with call signatures #2290", () => { + const project = convert(); + + equal(getComment(project, "CallSignature"), "Int comment"); + equal(getComment(project, "CallSignature2"), "Int comment"); + equal(getComment(project, "CallSignature2.prop"), "Prop comment"); + + equal( + Comment.combineDisplayParts( + query(project, "CallSignature").signatures![0].comment?.summary + ), + "Sig comment" + ); + + equal( + Comment.combineDisplayParts( + query(project, "CallSignature2").signatures![0].comment?.summary + ), + "Sig comment" + ); + }); }); diff --git a/src/test/utils.ts b/src/test/utils.ts index 9f87dfcad..756dd3eae 100644 --- a/src/test/utils.ts +++ b/src/test/utils.ts @@ -1,5 +1,6 @@ import { ok } from "assert"; import { + Comment, DeclarationReflection, ProjectReflection, Reflection, @@ -13,6 +14,10 @@ export function query(project: ProjectReflection, name: string) { return reflection; } +export function getComment(project: ProjectReflection, name: string) { + return Comment.combineDisplayParts(query(project, name).comment?.summary); +} + export function getLinks(refl: Reflection): Array<{ display: string; target: undefined | string | [ReflectionKind, string];