Skip to content

Commit 4f2a12f

Browse files
committed
Fix missing comments on indirectly created var-fns
Resolves #2008
1 parent 3e5a1a2 commit 4f2a12f

File tree

9 files changed

+68
-6
lines changed

9 files changed

+68
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Bug Fixes
44

5+
- Fixed missing comments on callable variable-functions constructed indirectly, #2008.
56
- Fixed multiple reflections mapping to the same file name on case insensitive file systems, #2012.
67

78
## v0.23.8 (2022-07-17)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
"/tsdoc.json"
6767
],
6868
"scripts": {
69-
"test": "c8 mocha -r ts-node/register --config .config/mocha.fast.json",
69+
"test": "mocha -r ts-node/register --config .config/mocha.fast.json",
70+
"test:cov": "c8 mocha -r ts-node/register --config .config/mocha.fast.json",
7071
"build:c2": "node bin/typedoc --tsconfig src/test/converter2/tsconfig.json",
7172
"test:full": "c8 mocha -r ts-node/register --config .config/mocha.full.json",
7273
"test:visual": "node ./dist/test/capture-screenshots.js && reg-suit -c .config/regconfig.json compare",

src/lib/converter/comments/discovery.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const wantedKinds: Record<ReflectionKind, ts.SyntaxKind[]> = {
3737
[ReflectionKind.Function]: [
3838
ts.SyntaxKind.FunctionDeclaration,
3939
ts.SyntaxKind.BindingElement,
40+
ts.SyntaxKind.VariableDeclaration,
41+
ts.SyntaxKind.ExportAssignment,
42+
ts.SyntaxKind.PropertyAccessExpression,
4043
],
4144
[ReflectionKind.Class]: [
4245
ts.SyntaxKind.ClassDeclaration,
@@ -106,8 +109,12 @@ export function discoverComment(
106109
// See the gh1770 test for an example.
107110
if (
108111
kind & ReflectionKind.ContainsCallSignatures &&
109-
!(node as ts.FunctionDeclaration).body &&
110-
node.kind !== ts.SyntaxKind.BindingElement
112+
[
113+
ts.SyntaxKind.FunctionDeclaration,
114+
ts.SyntaxKind.MethodDeclaration,
115+
ts.SyntaxKind.Constructor,
116+
].includes(node.kind) &&
117+
!(node as ts.FunctionDeclaration).body
111118
) {
112119
continue;
113120
}

src/lib/converter/plugins/CommentPlugin.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,23 @@ export class CommentPlugin extends ConverterComponent {
439439
return false;
440440
}
441441

442-
return (
442+
const isHidden =
443443
comment.hasModifier("@hidden") ||
444444
comment.hasModifier("@ignore") ||
445-
(comment.hasModifier("@internal") && this.excludeInternal)
446-
);
445+
(comment.hasModifier("@internal") && this.excludeInternal);
446+
447+
if (
448+
isHidden &&
449+
reflection.kindOf(ReflectionKind.ContainsCallSignatures)
450+
) {
451+
return (reflection as DeclarationReflection)
452+
.getNonIndexSignatures()
453+
.every((sig) => {
454+
return !sig.comment || this.isHidden(sig);
455+
});
456+
}
457+
458+
return isHidden;
447459
}
448460
}
449461

src/test/converter/function/specs.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,14 @@
449449
"kind": 4096,
450450
"kindString": "Call signature",
451451
"flags": {},
452+
"comment": {
453+
"summary": [
454+
{
455+
"kind": "text",
456+
"text": "Returns true if fn returns true for every item in the iterator\n\nReturns true if the iterator is empty"
457+
}
458+
]
459+
},
452460
"typeParameter": [
453461
{
454462
"id": 101,
@@ -543,6 +551,14 @@
543551
"kind": 4096,
544552
"kindString": "Call signature",
545553
"flags": {},
554+
"comment": {
555+
"summary": [
556+
{
557+
"kind": "text",
558+
"text": "Returns true if fn returns true for every item in the iterator\n\nReturns true if the iterator is empty"
559+
}
560+
]
561+
},
546562
"typeParameter": [
547563
{
548564
"id": 108,

src/test/converter2/issues/gh2008.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const makeFn = () => () => {};
2+
3+
/** Docs */
4+
export const myFn = makeFn();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface Foo {
2+
/** a */
3+
method(): void;
4+
method(a: string): string;
5+
}

src/test/issueTests.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,11 @@ export const issueTests: {
666666
equal(b.signatures![0].sources?.[0].character, 0);
667667
},
668668

669+
gh2008(project) {
670+
const fn = query(project, "myFn").signatures![0];
671+
equal(Comment.combineDisplayParts(fn.comment?.summary), "Docs");
672+
},
673+
669674
gh2012(project) {
670675
project.hasOwnDocument = true;
671676
const model = query(project, "model");

src/test/validation.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,15 @@ describe("validateDocumentation", () => {
195195
);
196196
logger.expectNoOtherMessages();
197197
});
198+
199+
it("Should correctly handle interfaces", () => {
200+
const project = convertValidationFile("interface.ts");
201+
const logger = new TestLogger();
202+
validateDocumentation(project, logger, ["Method"]);
203+
204+
logger.expectMessage(
205+
"warn: Foo.method does not have any documentation."
206+
);
207+
logger.expectNoOtherMessages();
208+
});
198209
});

0 commit comments

Comments
 (0)