Skip to content

Commit 23bde9a

Browse files
committed
Add support for comments on parameters
Resolves #2019.
1 parent 95f9bc1 commit 23bde9a

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Unreleased
22

3+
### Features
4+
5+
- Added support for detecting comments directly before parameters as the parameter comment, #2019.
6+
- Added support for using the comment directly before a constructor parameter that declares a property as the property comment, #2019.
7+
38
### Bug Fixes
49

510
- Fixed schema URL for TSDoc preventing the use of `typedoc/tsdoc.json` in TSDoc extends, #2015.

src/lib/converter/comments/discovery.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ const wantedKinds: Record<ReflectionKind, ts.SyntaxKind[]> = {
5252
ts.SyntaxKind.PropertySignature,
5353
ts.SyntaxKind.BinaryExpression,
5454
ts.SyntaxKind.PropertyAssignment,
55+
// class X { constructor(/** Comment */ readonly z: any) }
56+
ts.SyntaxKind.Parameter,
5557
],
5658
[ReflectionKind.Method]: [
5759
ts.SyntaxKind.FunctionDeclaration,

src/lib/converter/factories/signature.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { Context } from "../context";
1616
import { ConverterEvents } from "../converter-events";
1717
import { convertDefaultValue } from "../convert-expression";
1818
import { removeUndefined } from "../utils/reflections";
19-
import { getJsDocComment, getSignatureComment } from "../comments";
19+
import { getComment, getJsDocComment, getSignatureComment } from "../comments";
2020

2121
export function createSignature(
2222
context: Context,
@@ -131,6 +131,14 @@ function convertParameters(
131131
context.logger
132132
);
133133
}
134+
paramRefl.comment ||= getComment(
135+
param,
136+
paramRefl.kind,
137+
context.converter.config,
138+
context.logger,
139+
context.converter.commentStyle
140+
);
141+
134142
context.registerReflection(paramRefl, param);
135143
context.trigger(ConverterEvents.CREATE_PARAMETER, paramRefl);
136144

src/test/converter2/issues/gh2019.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export class A {
2+
constructor(
3+
/**
4+
* Param comment
5+
*/
6+
readonly property: string
7+
) {}
8+
}

src/test/issueTests.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,23 @@ export const issueTests: {
679679
equal(Model.getAlias(), "Model-1");
680680
},
681681

682+
gh2019(project) {
683+
const param = query(project, "A.constructor").signatures![0]
684+
.parameters![0];
685+
const prop = query(project, "A.property");
686+
687+
equal(
688+
Comment.combineDisplayParts(param.comment?.summary),
689+
"Param comment",
690+
"Constructor parameter"
691+
);
692+
equal(
693+
Comment.combineDisplayParts(prop.comment?.summary),
694+
"Param comment",
695+
"Property"
696+
);
697+
},
698+
682699
gh2020(project) {
683700
const opt = query(project, "Options");
684701
equal(Comment.combineDisplayParts(opt.comment?.summary), "Desc");

0 commit comments

Comments
 (0)