@@ -50,27 +50,31 @@ export const wrapComment = (comment: string, additionalTags: DocumentationTag[]
50
50
if ( additionalTags . length ) {
51
51
result . push ( ' *' ) ;
52
52
const nodePlatforms : string [ ] = [ ] ;
53
- result . push ( ...( additionalTags . map ( tag => {
54
- switch ( tag ) {
55
- case DocumentationTag . STABILITY_DEPRECATED :
56
- return ' * @deprecated' ;
57
- case DocumentationTag . STABILITY_EXPERIMENTAL :
58
- return ' * @experimental' ;
59
- case DocumentationTag . OS_LINUX :
60
- nodePlatforms . push ( 'linux' ) ;
61
- break ;
62
- case DocumentationTag . OS_MACOS :
63
- nodePlatforms . push ( 'darwin' ) ;
64
- break ;
65
- case DocumentationTag . OS_MAS :
66
- nodePlatforms . push ( 'mas' ) ;
67
- break ;
68
- case DocumentationTag . OS_WINDOWS :
69
- nodePlatforms . push ( 'win32' ) ;
70
- break ;
71
- }
72
- return '' ;
73
- } ) . filter ( tag => tag ) ) )
53
+ result . push (
54
+ ...additionalTags
55
+ . map ( tag => {
56
+ switch ( tag ) {
57
+ case DocumentationTag . STABILITY_DEPRECATED :
58
+ return ' * @deprecated' ;
59
+ case DocumentationTag . STABILITY_EXPERIMENTAL :
60
+ return ' * @experimental' ;
61
+ case DocumentationTag . OS_LINUX :
62
+ nodePlatforms . push ( 'linux' ) ;
63
+ break ;
64
+ case DocumentationTag . OS_MACOS :
65
+ nodePlatforms . push ( 'darwin' ) ;
66
+ break ;
67
+ case DocumentationTag . OS_MAS :
68
+ nodePlatforms . push ( 'mas' ) ;
69
+ break ;
70
+ case DocumentationTag . OS_WINDOWS :
71
+ nodePlatforms . push ( 'win32' ) ;
72
+ break ;
73
+ }
74
+ return '' ;
75
+ } )
76
+ . filter ( tag => tag ) ,
77
+ ) ;
74
78
if ( nodePlatforms . length ) {
75
79
result . push ( ` * @platform ${ nodePlatforms . join ( ',' ) } ` ) ;
76
80
}
@@ -253,9 +257,9 @@ export const isEmitter = (module: Pick<ModuleDocumentationContainer, 'name'>) =>
253
257
'touchbarbutton' ,
254
258
'net' ,
255
259
'netlog' ,
256
- 'protocol'
260
+ 'protocol' ,
257
261
] ;
258
- return ! ( nonEventEmitters . includes ( module . name . toLowerCase ( ) ) )
262
+ return ! nonEventEmitters . includes ( module . name . toLowerCase ( ) ) ;
259
263
} ;
260
264
export const isPrimitive = ( type : string ) => {
261
265
const primitives = [ 'boolean' , 'number' , 'any' , 'string' , 'void' , 'unknown' ] ;
@@ -285,6 +289,29 @@ export const genMethodString = (
285
289
includeType = true ,
286
290
paramTypePrefix = '' ,
287
291
) : string => {
292
+ const createMethodObjectParamType = (
293
+ objectParam : DetailedObjectType & TypeInformation & DocumentationBlock & { required : boolean } ,
294
+ ) => {
295
+ if ( 'constructor' === moduleMethod . name . toLowerCase ( ) ) {
296
+ objectParam . name = objectParam . name || 'options' ;
297
+ }
298
+ if ( objectParam . name === 'options' ) {
299
+ if (
300
+ [ 'show' , 'hide' , 'open' , 'close' , 'start' , 'stop' , 'constructor' ] . includes (
301
+ moduleMethod . name . toLowerCase ( ) ,
302
+ )
303
+ ) {
304
+ return paramInterfaces . createParamInterface (
305
+ objectParam ,
306
+ _ . upperFirst ( module . name ) + _ . upperFirst ( moduleMethod . name ) ,
307
+ ) ;
308
+ }
309
+
310
+ return paramInterfaces . createParamInterface ( objectParam , _ . upperFirst ( moduleMethod . name ) ) ;
311
+ }
312
+
313
+ return paramInterfaces . createParamInterface ( objectParam , '' , _ . upperFirst ( moduleMethod . name ) ) ;
314
+ } ;
288
315
return `${ includeType ? '(' : '' } ${ ( moduleMethod . parameters || [ ] )
289
316
. map ( param => {
290
317
let paramType : string | null = param as any ;
@@ -294,34 +321,15 @@ export const genMethodString = (
294
321
DocumentationBlock & { required : boolean } ;
295
322
if ( param . type === 'Object' && objectParam . properties && objectParam . properties . length ) {
296
323
// Check if we have the same structure for a different name
297
- if ( param . name === 'options' ) {
298
- if (
299
- [ 'show' , 'hide' , 'open' , 'close' , 'start' , 'stop' , 'constructor' ] . includes (
300
- moduleMethod . name . toLowerCase ( ) ,
301
- )
302
- ) {
303
- paramType = paramInterfaces . createParamInterface (
304
- objectParam ,
305
- _ . upperFirst ( module . name ) + _ . upperFirst ( moduleMethod . name ) ,
306
- ) ;
307
- } else {
308
- paramType = paramInterfaces . createParamInterface (
309
- objectParam ,
310
- _ . upperFirst ( moduleMethod . name ) ,
311
- ) ;
312
- }
313
- } else {
314
- paramType = paramInterfaces . createParamInterface (
315
- objectParam ,
316
- '' ,
317
- _ . upperFirst ( moduleMethod . name ) ,
318
- ) ;
319
- }
324
+ paramType = createMethodObjectParamType ( objectParam ) ;
320
325
}
321
326
322
327
if ( Array . isArray ( param . type ) ) {
323
328
param . type = param . type . map ( paramType => {
324
329
const functionParam = paramType as DetailedFunctionType ;
330
+ const objectParam = paramType as DetailedObjectType &
331
+ TypeInformation &
332
+ DocumentationBlock & { required : boolean } ;
325
333
if ( paramType . type === 'Function' && functionParam . parameters ) {
326
334
return Object . assign ( { } , paramType , {
327
335
type : genMethodString (
@@ -333,6 +341,11 @@ export const genMethodString = (
333
341
} as any /* FIXME: */ ,
334
342
) ,
335
343
} ) ;
344
+ } else if ( paramType . type === 'Object' && objectParam . properties ) {
345
+ return {
346
+ ...objectParam ,
347
+ type : createMethodObjectParamType ( objectParam ) ,
348
+ } ;
336
349
}
337
350
return paramType ;
338
351
} ) ;
0 commit comments