You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1002 B

import { blank } from './utils/object.js';
import makeLegalIdentifier from './utils/makeLegalIdentifier.js';
import { ExternalDeclaration } from './Declaration.js';
export default class ExternalModule {
constructor ( id ) {
this.id = id;
this.name = makeLegalIdentifier( id );
this.nameSuggestions = blank();
this.mostCommonSuggestion = 0;
this.isExternal = true;
this.declarations = blank();
this.exportsNames = false;
}
suggestName ( name ) {
if ( !this.nameSuggestions[ name ] ) this.nameSuggestions[ name ] = 0;
this.nameSuggestions[ name ] += 1;
if ( this.nameSuggestions[ name ] > this.mostCommonSuggestion ) {
this.mostCommonSuggestion = this.nameSuggestions[ name ];
this.name = name;
}
}
traceExport ( name ) {
if ( name !== 'default' && name !== '*' ) this.exportsNames = true;
if ( name === '*' ) this.exportsNamespace = true;
return this.declarations[ name ] || (
this.declarations[ name ] = new ExternalDeclaration( this, name )
);
}
}