@@ -68,7 +68,10 @@ const CTX_CMT_NOT_ALLOWED_IN = ['content', 'devtools'];
68
68
const CTX_CMT_ALLOWED_IN = [ 'proxy' ] ;
69
69
70
70
function pascalCase ( s : string ) : string {
71
- return s . split ( '_' ) . map ( x => x . charAt ( 0 ) . toUpperCase ( ) + x . slice ( 1 ) ) . join ( '' ) ;
71
+ return s
72
+ . split ( '_' )
73
+ . map ( ( x ) => x . charAt ( 0 ) . toUpperCase ( ) + x . slice ( 1 ) )
74
+ . join ( '' ) ;
72
75
}
73
76
74
77
// Formats an allowedContexts array to a readable string
@@ -495,7 +498,16 @@ export default class Converter {
495
498
let properties = this . convertObjectProperties ( type ) ;
496
499
// If it has no properties, just say it's some type of object
497
500
if ( properties . length > 0 ) {
498
- out += `{\n${ properties . join ( ';\n' ) } ;\n}` ;
501
+ if ( type . id && ! root ) {
502
+ const typeName = `_${ pascalCase ( type . id ! ) } ` ;
503
+ this . additionalTypes . push (
504
+ `${ commentFromSchema ( type ) } interface ${ typeName } {\n${ properties . join ( ';\n' ) } ;\n}`
505
+ ) ;
506
+ // And then just reference it by name in output
507
+ out += typeName ;
508
+ } else {
509
+ out += `{\n${ properties . join ( ';\n' ) } ;\n}` ;
510
+ }
499
511
} else {
500
512
out += 'object' ;
501
513
}
@@ -665,11 +677,12 @@ export default class Converter {
665
677
if ( properties === undefined ) return [ ] ;
666
678
let convertedProperties = [ ] ;
667
679
// For each property, just add it as a const, appending | undefined if it's optional
668
- for ( let prop of Object . keys ( properties ) ) {
680
+ for ( let [ propName , prop ] of Object . entries ( properties ) ) {
681
+ prop . id = propName ;
669
682
convertedProperties . push (
670
- `${ commentFromSchema ( properties [ prop ] ) } const ${ prop } : ${ this . convertType (
671
- properties [ prop ]
672
- ) } ${ properties [ prop ] . optional ? ' | undefined' : '' } ;`
683
+ `${ commentFromSchema ( prop ) } const ${ propName } : ${ this . convertType ( prop ) } ${
684
+ prop . optional ? ' | undefined' : ''
685
+ } ;`
673
686
) ;
674
687
}
675
688
return convertedProperties ;
@@ -744,7 +757,7 @@ export default class Converter {
744
757
if ( callback ) {
745
758
// Remove callback from parameters as we're gonna handle it as a promise return
746
759
func . parameters = func . parameters ! . filter ( ( x ) => x !== callback ) ;
747
- let parameters = this . convertParameters ( callback . parameters , false , func . name ) ;
760
+ let parameters = this . convertParameters ( callback . parameters , false , pascalCase ( ` ${ func . name } _return` ) ) ;
748
761
if ( parameters . length > 1 ) {
749
762
// Since these files are originally chrome, some things are a bit weird
750
763
// Callbacks (which is what chrome uses) have no issues with returning multiple values
0 commit comments