Skip to content

Commit

Permalink
Add support for comments on parameters
Browse files Browse the repository at this point in the history
Resolves #2019.
  • Loading branch information
Gerrit0 committed Jul 30, 2022
1 parent 95f9bc1 commit 23bde9a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Unreleased

### Features

- Added support for detecting comments directly before parameters as the parameter comment, #2019.
- Added support for using the comment directly before a constructor parameter that declares a property as the property comment, #2019.

### Bug Fixes

- Fixed schema URL for TSDoc preventing the use of `typedoc/tsdoc.json` in TSDoc extends, #2015.
Expand Down
2 changes: 2 additions & 0 deletions src/lib/converter/comments/discovery.ts
Expand Up @@ -52,6 +52,8 @@ const wantedKinds: Record<ReflectionKind, ts.SyntaxKind[]> = {
ts.SyntaxKind.PropertySignature,
ts.SyntaxKind.BinaryExpression,
ts.SyntaxKind.PropertyAssignment,
// class X { constructor(/** Comment */ readonly z: any) }
ts.SyntaxKind.Parameter,
],
[ReflectionKind.Method]: [
ts.SyntaxKind.FunctionDeclaration,
Expand Down
10 changes: 9 additions & 1 deletion src/lib/converter/factories/signature.ts
Expand Up @@ -16,7 +16,7 @@ import type { Context } from "../context";
import { ConverterEvents } from "../converter-events";
import { convertDefaultValue } from "../convert-expression";
import { removeUndefined } from "../utils/reflections";
import { getJsDocComment, getSignatureComment } from "../comments";
import { getComment, getJsDocComment, getSignatureComment } from "../comments";

export function createSignature(
context: Context,
Expand Down Expand Up @@ -131,6 +131,14 @@ function convertParameters(
context.logger
);
}
paramRefl.comment ||= getComment(
param,
paramRefl.kind,
context.converter.config,
context.logger,
context.converter.commentStyle
);

context.registerReflection(paramRefl, param);
context.trigger(ConverterEvents.CREATE_PARAMETER, paramRefl);

Expand Down
8 changes: 8 additions & 0 deletions src/test/converter2/issues/gh2019.ts
@@ -0,0 +1,8 @@
export class A {
constructor(
/**
* Param comment
*/
readonly property: string
) {}
}
17 changes: 17 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -679,6 +679,23 @@ export const issueTests: {
equal(Model.getAlias(), "Model-1");
},

gh2019(project) {
const param = query(project, "A.constructor").signatures![0]
.parameters![0];
const prop = query(project, "A.property");

equal(
Comment.combineDisplayParts(param.comment?.summary),
"Param comment",
"Constructor parameter"
);
equal(
Comment.combineDisplayParts(prop.comment?.summary),
"Param comment",
"Property"
);
},

gh2020(project) {
const opt = query(project, "Options");
equal(Comment.combineDisplayParts(opt.comment?.summary), "Desc");
Expand Down

0 comments on commit 23bde9a

Please sign in to comment.