@@ -31,7 +31,11 @@ const preparedCache = new Map();
3131 * @param apijson
3232 * @param directives
3333 */
34- function mergeOverlays ( apijson : ApiJSON , directives : Directives ) {
34+ function mergeOverlays (
35+ apijson : ApiJSON ,
36+ directives : Directives ,
37+ options = { generateGlobals : false } ,
38+ ) {
3539 const overlays = directives . overlays && directives . overlays [ apijson . library ] ;
3640 if ( overlays == null ) {
3741 return ; // no overlays defined
@@ -81,25 +85,36 @@ function mergeOverlays(apijson: ApiJSON, directives: Directives) {
8185 }
8286
8387 overlays . forEach ( ( overlay ) => {
88+ // do not generate esm-only symbols if generateGlobals is set
89+ if ( overlay . esmOnly && options . generateGlobals ) {
90+ return ;
91+ }
8492 log . verbose ( ` ${ overlay . name } ` ) ;
8593 const symbol = find ( overlay . name ) ;
8694 if ( symbol == null ) {
8795 // addition
8896 apijson . symbols . push ( overlay ) ;
8997 return ;
9098 }
91- // overlay
99+ // overlay needs to be merged into existing symbol
92100 Object . keys ( overlay ) . forEach ( ( prop ) => {
93101 if ( prop == "name" ) {
94102 return ; // ignore name property, it's the 'primary key' and can't be changed
95103 }
96104 if ( mapLikeProperties . has ( prop ) ) {
97- if ( ! Array . isArray ( symbol [ prop ] ) ) {
98- symbol [ prop ] = overlay [ prop ] ;
105+ // = methods, properties
106+ if ( ! Array . isArray ( symbol [ prop ] ) && Array . isArray ( overlay [ prop ] ) ) {
107+ symbol [ prop ] = overlay [ prop ] . filter (
108+ ( item ) => ! options . generateGlobals || ! item . esmOnly ,
109+ ) ;
99110 return ;
100111 }
101112 const symbolItems : ConcreteSymbol [ ] = symbol [ prop ] ;
102113 overlay [ prop ] . forEach ( ( overlayItem : ConcreteSymbol ) => {
114+ if ( overlayItem . esmOnly && options . generateGlobals ) {
115+ // skip esm-only ones in globals mode
116+ return ;
117+ }
103118 const item = symbolItems . find (
104119 ( symbolItem ) =>
105120 symbolItem . name === overlayItem . name &&
@@ -864,9 +879,9 @@ function markDeprecatedAliasesForEnums(
864879function _prepareApiJson (
865880 json : ApiJSON ,
866881 directives : Directives ,
867- options = { mainLibrary : false } ,
882+ options = { mainLibrary : false , generateGlobals : false } ,
868883) {
869- mergeOverlays ( json , directives ) ;
884+ mergeOverlays ( json , directives , { generateGlobals : options . generateGlobals } ) ;
870885 substituteSapClassInfoTypedef ( json ) ;
871886 convertCoreAndConfigurationIntoANamespace ( json , directives ) ;
872887 moveTypeParametersFromConstructorToClass ( json ) ;
@@ -904,17 +919,22 @@ export function fixApiJsons(
904919 targetLibJson : ApiJSON ,
905920 dependencies : ApiJSON [ ] ,
906921 directives : Directives ,
922+ generateGlobals ?: boolean ,
907923) {
908924 // Part 1: "prepare JSON"
909925 let targetLibFixedJson = _prepareApiJson ( targetLibJson , directives , {
910926 mainLibrary : true ,
927+ generateGlobals,
911928 } ) ;
912929
913930 let depsFixedJsons : ApiJSON [ ] = dependencies . map ( ( depjson ) => {
914931 const key = `${ depjson . library } -${ depjson . version } ` ;
915932 let preparedjson = preparedCache . get ( key ) ;
916933 if ( ! preparedjson ) {
917- preparedjson = _prepareApiJson ( depjson , directives ) ;
934+ preparedjson = _prepareApiJson ( depjson , directives , {
935+ mainLibrary : false ,
936+ generateGlobals,
937+ } ) ;
918938 preparedCache . set ( key , preparedjson ) ;
919939 }
920940 return JSON . parse ( JSON . stringify ( preparedjson ) ) ; // cloning needed to avoid multiple processing within the subsequent steps; // TODO: but this can likely be improved
0 commit comments