Skip to content

Commit

Permalink
Fix missing comments on indirectly created var-fns
Browse files Browse the repository at this point in the history
Resolves #2008
  • Loading branch information
Gerrit0 committed Jul 23, 2022
1 parent 3e5a1a2 commit 4f2a12f
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,7 @@

### Bug Fixes

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

## v0.23.8 (2022-07-17)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -66,7 +66,8 @@
"/tsdoc.json"
],
"scripts": {
"test": "c8 mocha -r ts-node/register --config .config/mocha.fast.json",
"test": "mocha -r ts-node/register --config .config/mocha.fast.json",
"test:cov": "c8 mocha -r ts-node/register --config .config/mocha.fast.json",
"build:c2": "node bin/typedoc --tsconfig src/test/converter2/tsconfig.json",
"test:full": "c8 mocha -r ts-node/register --config .config/mocha.full.json",
"test:visual": "node ./dist/test/capture-screenshots.js && reg-suit -c .config/regconfig.json compare",
Expand Down
11 changes: 9 additions & 2 deletions src/lib/converter/comments/discovery.ts
Expand Up @@ -37,6 +37,9 @@ const wantedKinds: Record<ReflectionKind, ts.SyntaxKind[]> = {
[ReflectionKind.Function]: [
ts.SyntaxKind.FunctionDeclaration,
ts.SyntaxKind.BindingElement,
ts.SyntaxKind.VariableDeclaration,
ts.SyntaxKind.ExportAssignment,
ts.SyntaxKind.PropertyAccessExpression,
],
[ReflectionKind.Class]: [
ts.SyntaxKind.ClassDeclaration,
Expand Down Expand Up @@ -106,8 +109,12 @@ export function discoverComment(
// See the gh1770 test for an example.
if (
kind & ReflectionKind.ContainsCallSignatures &&
!(node as ts.FunctionDeclaration).body &&
node.kind !== ts.SyntaxKind.BindingElement
[
ts.SyntaxKind.FunctionDeclaration,
ts.SyntaxKind.MethodDeclaration,
ts.SyntaxKind.Constructor,
].includes(node.kind) &&
!(node as ts.FunctionDeclaration).body
) {
continue;
}
Expand Down
18 changes: 15 additions & 3 deletions src/lib/converter/plugins/CommentPlugin.ts
Expand Up @@ -439,11 +439,23 @@ export class CommentPlugin extends ConverterComponent {
return false;
}

return (
const isHidden =
comment.hasModifier("@hidden") ||
comment.hasModifier("@ignore") ||
(comment.hasModifier("@internal") && this.excludeInternal)
);
(comment.hasModifier("@internal") && this.excludeInternal);

if (
isHidden &&
reflection.kindOf(ReflectionKind.ContainsCallSignatures)
) {
return (reflection as DeclarationReflection)
.getNonIndexSignatures()
.every((sig) => {
return !sig.comment || this.isHidden(sig);
});
}

return isHidden;
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/test/converter/function/specs.json
Expand Up @@ -449,6 +449,14 @@
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "Returns true if fn returns true for every item in the iterator\n\nReturns true if the iterator is empty"
}
]
},
"typeParameter": [
{
"id": 101,
Expand Down Expand Up @@ -543,6 +551,14 @@
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "Returns true if fn returns true for every item in the iterator\n\nReturns true if the iterator is empty"
}
]
},
"typeParameter": [
{
"id": 108,
Expand Down
4 changes: 4 additions & 0 deletions src/test/converter2/issues/gh2008.ts
@@ -0,0 +1,4 @@
const makeFn = () => () => {};

/** Docs */
export const myFn = makeFn();
5 changes: 5 additions & 0 deletions src/test/converter2/validation/interface.ts
@@ -0,0 +1,5 @@
export interface Foo {
/** a */
method(): void;
method(a: string): string;
}
5 changes: 5 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -666,6 +666,11 @@ export const issueTests: {
equal(b.signatures![0].sources?.[0].character, 0);
},

gh2008(project) {
const fn = query(project, "myFn").signatures![0];
equal(Comment.combineDisplayParts(fn.comment?.summary), "Docs");
},

gh2012(project) {
project.hasOwnDocument = true;
const model = query(project, "model");
Expand Down
11 changes: 11 additions & 0 deletions src/test/validation.test.ts
Expand Up @@ -195,4 +195,15 @@ describe("validateDocumentation", () => {
);
logger.expectNoOtherMessages();
});

it("Should correctly handle interfaces", () => {
const project = convertValidationFile("interface.ts");
const logger = new TestLogger();
validateDocumentation(project, logger, ["Method"]);

logger.expectMessage(
"warn: Foo.method does not have any documentation."
);
logger.expectNoOtherMessages();
});
});

0 comments on commit 4f2a12f

Please sign in to comment.