@@ -822,10 +822,6 @@ class ConcatenatedModule extends Module {
822822 const topLevelDeclarations = this . buildInfo . topLevelDeclarations ;
823823 if ( topLevelDeclarations !== undefined ) {
824824 for ( const decl of m . buildInfo . topLevelDeclarations ) {
825- // reserved names will always be renamed
826- if ( RESERVED_NAMES . has ( decl ) ) continue ;
827- // TODO actually this is incorrect since with renaming there could be more
828- // We should do the renaming during build
829825 topLevelDeclarations . add ( decl ) ;
830826 }
831827 }
@@ -1113,6 +1109,8 @@ class ConcatenatedModule extends Module {
11131109
11141110 // List of all used names to avoid conflicts
11151111 const allUsedNames = new Set ( RESERVED_NAMES ) ;
1112+ // Updated Top level declarations are created by renaming
1113+ const topLevelDeclarations = new Set ( ) ;
11161114
11171115 // List of additional names in scope for module references
11181116 /** @type {Map<string, { usedNames: Set<string>, alreadyCheckedScopes: Set<TODO> }> } */
@@ -1257,6 +1255,7 @@ class ConcatenatedModule extends Module {
12571255 ) ;
12581256 allUsedNames . add ( newName ) ;
12591257 info . internalNames . set ( name , newName ) ;
1258+ topLevelDeclarations . add ( newName ) ;
12601259 const source = info . source ;
12611260 const allIdentifiers = new Set (
12621261 references . map ( r => r . identifier ) . concat ( variable . identifiers )
@@ -1283,6 +1282,7 @@ class ConcatenatedModule extends Module {
12831282 } else {
12841283 allUsedNames . add ( name ) ;
12851284 info . internalNames . set ( name , name ) ;
1285+ topLevelDeclarations . add ( name ) ;
12861286 }
12871287 }
12881288 let namespaceObjectName ;
@@ -1300,6 +1300,7 @@ class ConcatenatedModule extends Module {
13001300 allUsedNames . add ( namespaceObjectName ) ;
13011301 }
13021302 info . namespaceObjectName = namespaceObjectName ;
1303+ topLevelDeclarations . add ( namespaceObjectName ) ;
13031304 break ;
13041305 }
13051306 case "external" : {
@@ -1311,6 +1312,7 @@ class ConcatenatedModule extends Module {
13111312 ) ;
13121313 allUsedNames . add ( externalName ) ;
13131314 info . name = externalName ;
1315+ topLevelDeclarations . add ( externalName ) ;
13141316 break ;
13151317 }
13161318 }
@@ -1323,6 +1325,7 @@ class ConcatenatedModule extends Module {
13231325 ) ;
13241326 allUsedNames . add ( externalNameInterop ) ;
13251327 info . interopNamespaceObjectName = externalNameInterop ;
1328+ topLevelDeclarations . add ( externalNameInterop ) ;
13261329 }
13271330 if (
13281331 info . module . buildMeta . exportsType === "default" &&
@@ -1336,6 +1339,7 @@ class ConcatenatedModule extends Module {
13361339 ) ;
13371340 allUsedNames . add ( externalNameInterop ) ;
13381341 info . interopNamespaceObject2Name = externalNameInterop ;
1342+ topLevelDeclarations . add ( externalNameInterop ) ;
13391343 }
13401344 if (
13411345 info . module . buildMeta . exportsType === "dynamic" ||
@@ -1349,6 +1353,7 @@ class ConcatenatedModule extends Module {
13491353 ) ;
13501354 allUsedNames . add ( externalNameInterop ) ;
13511355 info . interopDefaultAccessName = externalNameInterop ;
1356+ topLevelDeclarations . add ( externalNameInterop ) ;
13521357 }
13531358 }
13541359
@@ -1618,6 +1623,7 @@ ${defineGetters}`
16181623 const data = new Map ( ) ;
16191624 if ( chunkInitFragments . length > 0 )
16201625 data . set ( "chunkInitFragments" , chunkInitFragments ) ;
1626+ data . set ( "topLevelDeclarations" , topLevelDeclarations ) ;
16211627
16221628 /** @type {CodeGenerationResult } */
16231629 const resultEntry = {
0 commit comments