@@ -114,7 +114,7 @@ interface DocgenEventJson {
114114}
115115
116116interface DocgenParamJson {
117- default ?: string ;
117+ default ?: boolean | number | string ;
118118 description : string ;
119119 name : string ;
120120 nullable ?: boolean ;
@@ -155,7 +155,7 @@ interface DocgenMethodJson {
155155interface DocgenPropertyJson {
156156 abstract ?: boolean ;
157157 access ?: DocgenAccess ;
158- default ?: string ;
158+ default ?: boolean | number | string ;
159159 deprecated ?: DocgenDeprecated ;
160160 description : string ;
161161 meta : DocgenMetaJson ;
@@ -1264,7 +1264,7 @@ export class ApiModelGenerator {
12641264 const apiItemMetadata : ApiItemMetadata = this . _collector . fetchApiItemMetadata ( astDeclaration ) ;
12651265 const docComment : tsdoc . DocComment | undefined = jsDoc
12661266 ? this . _tsDocParser . parseString (
1267- `/**\n * ${ this . _fixLinkTags ( jsDoc . description ) ?? '' } \n${
1267+ `/**\n * ${ this . _fixLinkTags ( jsDoc . description ) ?? '' } ${ jsDoc . default ? ` (default: ${ this . _escapeSpecialChars ( jsDoc . default ) } )` : '' } \n${
12681268 'see' in jsDoc ? jsDoc . see . map ( ( see ) => ` * @see ${ see } \n` ) . join ( '' ) : ''
12691269 } ${ 'readonly' in jsDoc && jsDoc . readonly ? ' * @readonly\n' : '' } ${
12701270 'deprecated' in jsDoc && jsDoc . deprecated
@@ -1342,7 +1342,7 @@ export class ApiModelGenerator {
13421342 const apiItemMetadata : ApiItemMetadata = this . _collector . fetchApiItemMetadata ( astDeclaration ) ;
13431343 const docComment : tsdoc . DocComment | undefined = jsDoc
13441344 ? this . _tsDocParser . parseString (
1345- `/**\n * ${ this . _fixLinkTags ( jsDoc . description ) ?? '' } \n${
1345+ `/**\n * ${ this . _fixLinkTags ( jsDoc . description ) ?? '' } ${ jsDoc . default ? ` (default: ${ this . _escapeSpecialChars ( jsDoc . default ) } )` : '' } \n${
13461346 'see' in jsDoc ? jsDoc . see . map ( ( see ) => ` * @see ${ see } \n` ) . join ( '' ) : ''
13471347 } ${ 'readonly' in jsDoc && jsDoc . readonly ? ' * @readonly\n' : '' } ${
13481348 'deprecated' in jsDoc && jsDoc . deprecated
@@ -1510,15 +1510,17 @@ export class ApiModelGenerator {
15101510 const excerptTokens : IExcerptToken [ ] = [
15111511 {
15121512 kind : ExcerptTokenKind . Content ,
1513- text : `on('${ name } ', (${
1514- jsDoc . params ?. length ? `${ jsDoc . params [ 0 ] ?. name } ${ jsDoc . params [ 0 ] ?. nullable ? '?' : '' } : ` : ') => {})'
1513+ text : `public on(eventName: '${ name } ', listener: (${
1514+ jsDoc . params ?. length
1515+ ? `${ jsDoc . params [ 0 ] ?. name } ${ jsDoc . params [ 0 ] ?. optional ? '?' : '' } : `
1516+ : ') => void): this;'
15151517 } `,
15161518 } ,
15171519 ] ;
15181520 const parameters : IApiParameterOptions [ ] = [ ] ;
15191521 for ( let index = 0 ; index < ( jsDoc . params ?. length ?? 0 ) - 1 ; index ++ ) {
15201522 const parameter = jsDoc . params ! [ index ] ! ;
1521- const newTokens = this . _mapVarType ( parameter . type ) ;
1523+ const newTokens = this . _mapVarType ( parameter . type , parameter . nullable ) ;
15221524 parameters . push ( {
15231525 parameterName : parameter . name ,
15241526 parameterTypeTokenRange : {
@@ -1537,7 +1539,7 @@ export class ApiModelGenerator {
15371539
15381540 if ( jsDoc . params ?. length ) {
15391541 const parameter = jsDoc . params ! [ jsDoc . params . length - 1 ] ! ;
1540- const newTokens = this . _mapVarType ( parameter . type ) ;
1542+ const newTokens = this . _mapVarType ( parameter . type , parameter . nullable ) ;
15411543 parameters . push ( {
15421544 parameterName : parameter . name ,
15431545 parameterTypeTokenRange : {
@@ -1550,7 +1552,7 @@ export class ApiModelGenerator {
15501552 excerptTokens . push ( ...newTokens ) ;
15511553 excerptTokens . push ( {
15521554 kind : ExcerptTokenKind . Content ,
1553- text : `) => {}) ` ,
1555+ text : `) => void): this; ` ,
15541556 } ) ;
15551557 }
15561558
@@ -1746,6 +1748,14 @@ export class ApiModelGenerator {
17461748 return sourceLocation ;
17471749 }
17481750
1751+ private _escapeSpecialChars ( input : boolean | number | string ) {
1752+ if ( typeof input !== 'string' ) {
1753+ return input ;
1754+ }
1755+
1756+ return input . replaceAll ( / (?< char > [ { } ] ) / g, '\\$<char>' ) ;
1757+ }
1758+
17491759 private _fixLinkTags ( input ?: string ) : string | undefined {
17501760 return input
17511761 ?. replaceAll ( linkRegEx , ( _match , _p1 , _p2 , _p3 , _p4 , _p5 , _offset , _string , groups ) => {
@@ -1765,7 +1775,7 @@ export class ApiModelGenerator {
17651775 . replaceAll ( '* ' , '\n * * ' ) ;
17661776 }
17671777
1768- private _mapVarType ( typey : DocgenVarTypeJson ) : IExcerptToken [ ] {
1778+ private _mapVarType ( typey : DocgenVarTypeJson , nullable ?: boolean ) : IExcerptToken [ ] {
17691779 const mapper = Array . isArray ( typey ) ? typey : ( typey . types ?? [ ] ) ;
17701780 const lookup : { [ K in ts . SyntaxKind ] ?: string } = {
17711781 [ ts . SyntaxKind . ClassDeclaration ] : 'class' ,
@@ -1808,7 +1818,22 @@ export class ApiModelGenerator {
18081818 { kind : ExcerptTokenKind . Content , text : symbol ?? '' } ,
18091819 ] ;
18101820 } , [ ] ) ;
1811- return index === 0 ? result : [ { kind : ExcerptTokenKind . Content , text : ' | ' } , ...result ] ;
1821+ return index === 0
1822+ ? mapper . length === 1 && ( nullable || ( 'nullable' in typey && typey . nullable ) )
1823+ ? [
1824+ ...result ,
1825+ { kind : ExcerptTokenKind . Content , text : ' | ' } ,
1826+ { kind : ExcerptTokenKind . Reference , text : 'null' } ,
1827+ ]
1828+ : result
1829+ : index === mapper . length - 1 && ( nullable || ( 'nullable' in typey && typey . nullable ) )
1830+ ? [
1831+ { kind : ExcerptTokenKind . Content , text : ' | ' } ,
1832+ ...result ,
1833+ { kind : ExcerptTokenKind . Content , text : ' | ' } ,
1834+ { kind : ExcerptTokenKind . Reference , text : 'null' } ,
1835+ ]
1836+ : [ { kind : ExcerptTokenKind . Content , text : ' | ' } , ...result ] ;
18121837 } )
18131838 . filter ( ( excerpt ) => excerpt . text . length ) ;
18141839 }
@@ -1823,7 +1848,7 @@ export class ApiModelGenerator {
18231848 isOptional : Boolean ( prop . nullable ) ,
18241849 isReadonly : Boolean ( prop . readonly ) ,
18251850 docComment : this . _tsDocParser . parseString (
1826- `/**\n * ${ this . _fixLinkTags ( prop . description ) ?? '' } \n${
1851+ `/**\n * ${ this . _fixLinkTags ( prop . description ) ?? '' } ${ prop . default ? ` (default: ${ this . _escapeSpecialChars ( prop . default ) } )` : '' } \n${
18271852 prop . see ?. map ( ( see ) => ` * @see ${ see } \n` ) . join ( '' ) ?? ''
18281853 } ${ prop . readonly ? ' * @readonly\n' : '' } */`,
18291854 ) . docComment ,
0 commit comments