@@ -12,6 +12,7 @@ import {
12
12
TypeInformation ,
13
13
DetailedFunctionType ,
14
14
ElementDocumentationContainer ,
15
+ DocumentationTag ,
15
16
} from '@electron/docs-parser' ;
16
17
17
18
const modules : Record < string , string [ ] > = { } ;
@@ -65,7 +66,7 @@ export const generateModuleDeclaration = (
65
66
_ . concat ( [ ] , module . instanceEvents || [ ] , module . events || [ ] )
66
67
. sort ( ( a , b ) => a . name . localeCompare ( b . name ) )
67
68
. forEach ( moduleEvent => {
68
- utils . extendArray ( moduleAPI , utils . wrapComment ( moduleEvent . description ) ) ;
69
+ utils . extendArray ( moduleAPI , utils . wrapComment ( moduleEvent . description , moduleEvent . additionalTags ) ) ;
69
70
let listener = 'Function' ;
70
71
71
72
if ( moduleEvent . parameters && moduleEvent . parameters . length ) {
@@ -102,7 +103,7 @@ export const generateModuleDeclaration = (
102
103
}
103
104
104
105
let newType = argType || utils . typify ( eventListenerArg ) ;
105
- const functionListenerArg = eventListenerArg as DetailedFunctionType &
106
+ const functionListenerArg = eventListenerArg as any as DetailedFunctionType &
106
107
DocumentationBlock &
107
108
TypeInformation ;
108
109
if ( newType === 'Function' ) {
@@ -133,7 +134,7 @@ export const generateModuleDeclaration = (
133
134
if ( module . type === 'Element' ) {
134
135
if ( module . events ) {
135
136
module . events . forEach ( domEvent => {
136
- utils . extendArray ( moduleAPI , utils . wrapComment ( domEvent . description ) ) ;
137
+ utils . extendArray ( moduleAPI , utils . wrapComment ( domEvent . description , domEvent . additionalTags ) ) ;
137
138
let eventType = 'Event' ;
138
139
139
140
if ( domEvent . parameters && domEvent . parameters . length ) {
@@ -189,7 +190,7 @@ export const generateModuleDeclaration = (
189
190
[ 'on' , 'once' , 'removeAllListeners' , 'removeListener' ] . includes ( moduleMethod . name ) ;
190
191
191
192
const addMethod = ( moduleMethod : MethodDocumentationBlock , prefix = '' ) => {
192
- utils . extendArray ( moduleAPI , utils . wrapComment ( moduleMethod . description ) ) ;
193
+ utils . extendArray ( moduleAPI , utils . wrapComment ( moduleMethod . description , moduleMethod . additionalTags ) ) ;
193
194
let returnType : string | TypeInformation = returnsThis ( moduleMethod ) ? 'this' : 'void' ;
194
195
195
196
if ( moduleMethod . returns ) {
@@ -245,6 +246,7 @@ export const generateModuleDeclaration = (
245
246
...module . constructorMethod ,
246
247
description : module . name ,
247
248
returns : null ,
249
+ additionalTags : [ ] ,
248
250
} ) ;
249
251
}
250
252
@@ -273,7 +275,8 @@ export const generateModuleDeclaration = (
273
275
. sort ( ( a , b ) => a . name . localeCompare ( b . name ) )
274
276
. forEach ( prop => {
275
277
const isOptional = ! prop . required ? '?' : '' ;
276
- moduleAPI . push ( `${ prop . name } ${ isOptional } : ${ utils . typify ( prop ) } ;` ) ;
278
+ const isReadonly = prop . additionalTags . includes ( DocumentationTag . AVAILABILITY_READONLY ) ? 'readonly ' : '' ;
279
+ moduleAPI . push ( `${ isReadonly } ${ prop . name } ${ isOptional } : ${ utils . typify ( prop ) } ;` ) ;
277
280
} ) ;
278
281
}
279
282
@@ -282,12 +285,8 @@ export const generateModuleDeclaration = (
282
285
module . staticProperties
283
286
. sort ( ( a , b ) => a . name . localeCompare ( b . name ) )
284
287
. forEach ( prop => {
285
- // if (prop.type === 'Class') {
286
- // moduleAPI.push(`static ${prop.name}: typeof ${prop.name};`);
287
- // generateModuleDeclaration(prop, -1, API);
288
- // } else {
289
- moduleAPI . push ( `static ${ prop . name } : ${ utils . typify ( prop ) } ;` ) ;
290
- // }
288
+ const isReadonly = prop . additionalTags . includes ( DocumentationTag . AVAILABILITY_READONLY ) ? 'readonly ' : '' ;
289
+ moduleAPI . push ( `static${ isReadonly } ${ prop . name } : ${ utils . typify ( prop ) } ;` ) ;
291
290
} ) ;
292
291
}
293
292
@@ -305,16 +304,17 @@ export const generateModuleDeclaration = (
305
304
306
305
const isStatic = isStaticVersion ? 'static ' : '' ;
307
306
const isOptional = utils . isOptional ( p ) ? '?' : '' ;
307
+ const isReadonly = p . additionalTags . includes ( DocumentationTag . AVAILABILITY_READONLY ) ? 'readonly ' : '' ;
308
308
type = type || utils . typify ( paramType ) ;
309
309
310
- utils . extendArray ( moduleAPI , utils . wrapComment ( p . description ) ) ;
310
+ utils . extendArray ( moduleAPI , utils . wrapComment ( p . description , p . additionalTags ) ) ;
311
311
if ( module . name === 'process' && p . name === 'versions' ) return ;
312
312
313
313
if ( p . name . match ( / ^ \d / ) ) {
314
314
// Wrap key in quotes if it starts with a number, e.g. `2d_canvas`
315
- moduleAPI . push ( `'${ isStatic } ${ p . name } ${ isOptional } ': ${ type } ;` ) ;
315
+ moduleAPI . push ( `'${ isStatic } ${ isReadonly } ${ p . name } ${ isOptional } ': ${ type } ;` ) ;
316
316
} else {
317
- moduleAPI . push ( `${ isStatic } ${ p . name } ${ isOptional } : ${ type } ;` ) ;
317
+ moduleAPI . push ( `${ isStatic } ${ isReadonly } ${ p . name } ${ isOptional } : ${ type } ;` ) ;
318
318
}
319
319
} ) ;
320
320
}
0 commit comments