From 23bde9a2687686a8e49cd7d9579444c04a51c60f Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 30 Jul 2022 07:14:34 -0600 Subject: [PATCH] Add support for comments on parameters Resolves #2019. --- CHANGELOG.md | 5 +++++ src/lib/converter/comments/discovery.ts | 2 ++ src/lib/converter/factories/signature.ts | 10 +++++++++- src/test/converter2/issues/gh2019.ts | 8 ++++++++ src/test/issueTests.ts | 17 +++++++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/test/converter2/issues/gh2019.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c187ffb5..5ba178ca5 100644 --- a/CHANGELOG.md +++ b/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. diff --git a/src/lib/converter/comments/discovery.ts b/src/lib/converter/comments/discovery.ts index 373ff5ad5..d81032075 100644 --- a/src/lib/converter/comments/discovery.ts +++ b/src/lib/converter/comments/discovery.ts @@ -52,6 +52,8 @@ const wantedKinds: Record = { ts.SyntaxKind.PropertySignature, ts.SyntaxKind.BinaryExpression, ts.SyntaxKind.PropertyAssignment, + // class X { constructor(/** Comment */ readonly z: any) } + ts.SyntaxKind.Parameter, ], [ReflectionKind.Method]: [ ts.SyntaxKind.FunctionDeclaration, diff --git a/src/lib/converter/factories/signature.ts b/src/lib/converter/factories/signature.ts index 00aefd594..2b6709182 100644 --- a/src/lib/converter/factories/signature.ts +++ b/src/lib/converter/factories/signature.ts @@ -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, @@ -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); diff --git a/src/test/converter2/issues/gh2019.ts b/src/test/converter2/issues/gh2019.ts new file mode 100644 index 000000000..a29968632 --- /dev/null +++ b/src/test/converter2/issues/gh2019.ts @@ -0,0 +1,8 @@ +export class A { + constructor( + /** + * Param comment + */ + readonly property: string + ) {} +} diff --git a/src/test/issueTests.ts b/src/test/issueTests.ts index 0e893f02c..a58432c9b 100644 --- a/src/test/issueTests.ts +++ b/src/test/issueTests.ts @@ -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");