Skip to content

Commit 2624c28

Browse files
committed
Fix call signature handling on classes/interfaces
Resolves #2290
1 parent 5b9ead6 commit 2624c28

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
- Optimized icon caching to reduce file size in generated HTML documentation, #2287.
77
- Added `MarkdownEvent.INCLUDE` for plugins, #2284.
88

9+
### Bug Fixes
10+
11+
- Comments are no longer removed from classes/interfaces containing call signatures, #2290.
12+
913
### Thanks!
1014

1115
- @krisztianb

src/lib/converter/plugins/CommentPlugin.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,16 @@ export class CommentPlugin extends ConverterComponent {
376376
return;
377377
}
378378

379-
const comment = reflection.comment;
379+
const comment = reflection.kindOf(ReflectionKind.ClassOrInterface)
380+
? undefined
381+
: reflection.comment;
380382

381383
// Since this reflection has signatures, remove the comment from the parent
382384
// reflection. This is important so that in type aliases we don't end up with
383385
// a comment rendered twice.
384-
delete reflection.comment;
386+
if (!reflection.kindOf(ReflectionKind.ClassOrInterface)) {
387+
delete reflection.comment;
388+
}
385389

386390
for (const signature of signatures) {
387391
const childComment = (signature.comment ||= comment?.clone());

src/test/converter/interface/specs.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,14 @@
18701870
"variant": "declaration",
18711871
"kind": 256,
18721872
"flags": {},
1873+
"comment": {
1874+
"summary": [
1875+
{
1876+
"kind": "text",
1877+
"text": "Function signature of an event listener callback"
1878+
}
1879+
]
1880+
},
18731881
"sources": [
18741882
{
18751883
"fileName": "interface-implementation.ts",

src/test/converter2/issues/gh2290.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** Int comment */
2+
export interface CallSignature {
3+
/** Sig comment */
4+
(x: string): void;
5+
}
6+
7+
/** Int comment */
8+
export interface CallSignature2 {
9+
/** Sig comment */
10+
(x: string): void;
11+
12+
/** Prop comment */
13+
prop: 123;
14+
}

src/test/issues.c2.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { TestLogger } from "./TestLogger";
2727
import { clearCommentCache } from "../lib/converter/comments";
2828
import { join } from "path";
2929
import { existsSync } from "fs";
30-
import { getLinks, query } from "./utils";
30+
import { getComment, getLinks, query } from "./utils";
3131

3232
const base = getConverter2Base();
3333
const app = getConverter2App();
@@ -1111,4 +1111,26 @@ describe("Issue Tests", () => {
11111111
},
11121112
]);
11131113
});
1114+
1115+
it("Handles comments on interfaces with call signatures #2290", () => {
1116+
const project = convert();
1117+
1118+
equal(getComment(project, "CallSignature"), "Int comment");
1119+
equal(getComment(project, "CallSignature2"), "Int comment");
1120+
equal(getComment(project, "CallSignature2.prop"), "Prop comment");
1121+
1122+
equal(
1123+
Comment.combineDisplayParts(
1124+
query(project, "CallSignature").signatures![0].comment?.summary
1125+
),
1126+
"Sig comment"
1127+
);
1128+
1129+
equal(
1130+
Comment.combineDisplayParts(
1131+
query(project, "CallSignature2").signatures![0].comment?.summary
1132+
),
1133+
"Sig comment"
1134+
);
1135+
});
11141136
});

src/test/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ok } from "assert";
22
import {
3+
Comment,
34
DeclarationReflection,
45
ProjectReflection,
56
Reflection,
@@ -13,6 +14,10 @@ export function query(project: ProjectReflection, name: string) {
1314
return reflection;
1415
}
1516

17+
export function getComment(project: ProjectReflection, name: string) {
18+
return Comment.combineDisplayParts(query(project, name).comment?.summary);
19+
}
20+
1621
export function getLinks(refl: Reflection): Array<{
1722
display: string;
1823
target: undefined | string | [ReflectionKind, string];

0 commit comments

Comments
 (0)