@@ -162,7 +162,8 @@ function analyzeParameter(parameter: ParameterReflection): {
162
162
const name = parameter . name ;
163
163
const declarationName = name + ( isOptional ( parameter ) ? '?' : '' ) ;
164
164
const type = parameter . type ;
165
- const defaultValue = parameter . defaultValue ;
165
+ const commentDefault = extractDefaultFromComment ( parameter . comment ) ;
166
+ const defaultValue = parameter . defaultValue ?? commentDefault ;
166
167
167
168
let signatureText = '' ;
168
169
if ( defaultValue ) {
@@ -200,6 +201,7 @@ function analyzeParameterOptions(
200
201
return properties . map ( ( property ) => ( {
201
202
name : `${ name } .${ property . name } ${ isOptional ( property ) ? '?' : '' } ` ,
202
203
type : declarationTypeToText ( property ) ,
204
+ default : extractDefaultFromComment ( property . comment ) ,
203
205
description : mdToHtml (
204
206
toBlock ( property . comment ?? property . signatures ?. [ 0 ] . comment )
205
207
) ,
@@ -284,3 +286,25 @@ function signatureTypeToText(signature: SignatureReflection): string {
284
286
. map ( ( p ) => `${ p . name } : ${ typeToText ( p . type ) } ` )
285
287
. join ( ', ' ) } ) => ${ typeToText ( signature . type ) } `;
286
288
}
289
+
290
+ /**
291
+ * Extracts and removed the parameter default from the comments.
292
+ *
293
+ * @param comment The comment to extract the default from.
294
+ * @returns The extracted default value.
295
+ */
296
+ function extractDefaultFromComment ( comment ?: Comment ) : string {
297
+ if ( ! comment ) {
298
+ return ;
299
+ }
300
+ const text = comment . shortText ;
301
+ if ( ! text || text . trim ( ) === '' ) {
302
+ return ;
303
+ }
304
+ const result = / ( .* ) [ \n ] D e f a u l t s t o ` ( [ ^ ` ] + ) ` ./ . exec ( text ) ;
305
+ if ( ! result ) {
306
+ return ;
307
+ }
308
+ comment . shortText = result [ 1 ] ;
309
+ return result [ 2 ] ;
310
+ }
0 commit comments