@@ -13,15 +13,15 @@ import { printQuotedStringList } from './utils/printStringList';
1313import relativeId from './utils/relativeId' ;
1414
1515export default class ExternalModule {
16- readonly declarations : { [ name : string ] : ExternalVariable } = Object . create ( null ) ;
16+ readonly declarations = new Map < string , ExternalVariable > ( ) ;
1717 defaultVariableName = '' ;
1818 readonly dynamicImporters : string [ ] = [ ] ;
1919 execIndex = Infinity ;
2020 readonly exportedVariables = new Map < ExternalVariable , string > ( ) ;
2121 readonly importers : string [ ] = [ ] ;
2222 readonly info : ModuleInfo ;
2323 mostCommonSuggestion = 0 ;
24- readonly nameSuggestions : { [ name : string ] : number } = Object . create ( null ) ;
24+ readonly nameSuggestions = new Map < string , number > ( ) ;
2525 namespaceVariableName = '' ;
2626 reexported = false ;
2727 renderPath : string = undefined as never ;
@@ -78,12 +78,13 @@ export default class ExternalModule {
7878 }
7979
8080 getVariableForExportName ( name : string ) : [ variable : ExternalVariable ] {
81- let declaration = this . declarations [ name ] ;
81+ const declaration = this . declarations . get ( name ) ;
8282 if ( declaration ) return [ declaration ] ;
83+ const externalVariable = new ExternalVariable ( this , name ) ;
8384
84- this . declarations [ name ] = declaration = new ExternalVariable ( this , name ) ;
85- this . exportedVariables . set ( declaration , name ) ;
86- return [ declaration ] ;
85+ this . declarations . set ( name , externalVariable ) ;
86+ this . exportedVariables . set ( externalVariable , name ) ;
87+ return [ externalVariable ] ;
8788 }
8889
8990 setRenderPath ( options : NormalizedOutputOptions , inputBase : string ) : string {
@@ -98,27 +99,28 @@ export default class ExternalModule {
9899 }
99100
100101 suggestName ( name : string ) : void {
101- if ( ! this . nameSuggestions [ name ] ) this . nameSuggestions [ name ] = 0 ;
102- this . nameSuggestions [ name ] += 1 ;
102+ const value = ( this . nameSuggestions . get ( name ) ?? 0 ) + 1 ;
103+ this . nameSuggestions . set ( name , value ) ;
103104
104- if ( this . nameSuggestions [ name ] > this . mostCommonSuggestion ) {
105- this . mostCommonSuggestion = this . nameSuggestions [ name ] ;
105+ if ( value > this . mostCommonSuggestion ) {
106+ this . mostCommonSuggestion = value ;
106107 this . suggestedVariableName = name ;
107108 }
108109 }
109110
110111 warnUnusedImports ( ) : void {
111- const unused = Object . keys ( this . declarations ) . filter ( name => {
112- if ( name === '*' ) return false ;
113- const declaration = this . declarations [ name ] ;
114- return ! declaration . included && ! this . reexported && ! declaration . referenced ;
115- } ) ;
112+ const unused = Array . from ( this . declarations )
113+ . filter (
114+ ( [ name , declaration ] ) =>
115+ name !== '*' && ! declaration . included && ! this . reexported && ! declaration . referenced
116+ )
117+ . map ( ( [ name ] ) => name ) ;
118+
116119 if ( unused . length === 0 ) return ;
117120
118121 const importersSet = new Set < string > ( ) ;
119122 for ( const name of unused ) {
120- const { importers } = this . declarations [ name ] . module ;
121- for ( const importer of importers ) {
123+ for ( const importer of this . declarations . get ( name ) ! . module . importers ) {
122124 importersSet . add ( importer ) ;
123125 }
124126 }
0 commit comments