UNPKG

959 BJavaScriptView Raw
1import { blank } from './utils/object.js';
2import makeLegalIdentifier from './utils/makeLegalIdentifier.js';
3import { ExternalDeclaration } from './Declaration.js';
4
5export default class ExternalModule {
6 constructor ( id ) {
7 this.id = id;
8 this.name = makeLegalIdentifier( id );
9
10 this.nameSuggestions = blank();
11 this.mostCommonSuggestion = 0;
12
13 this.isExternal = true;
14 this.declarations = blank();
15
16 this.exportsNames = false;
17 }
18
19 suggestName ( name ) {
20 if ( !this.nameSuggestions[ name ] ) this.nameSuggestions[ name ] = 0;
21 this.nameSuggestions[ name ] += 1;
22
23 if ( this.nameSuggestions[ name ] > this.mostCommonSuggestion ) {
24 this.mostCommonSuggestion = this.nameSuggestions[ name ];
25 this.name = name;
26 }
27 }
28
29 traceExport ( name ) {
30 if ( name !== 'default' && name !== '*' ) {
31 this.exportsNames = true;
32 }
33
34 return this.declarations[ name ] || (
35 this.declarations[ name ] = new ExternalDeclaration( this, name )
36 );
37 }
38}