UNPKG

813 BJavaScriptView Raw
1export default class ExternalModule {
2 constructor ( id ) {
3 this.id = id;
4 this.name = null;
5 this.module = null;
6
7 this.isExternal = true;
8 this.importedByBundle = [];
9
10 this.canonicalNames = {};
11 this.suggestedNames = {};
12
13 this.needsDefault = null;
14 this.needsNamed = null;
15 }
16
17 getCanonicalName ( name ) {
18 if ( name === 'default' ) {
19 return this.needsNamed ? `${this.name}__default` : this.name;
20 }
21
22 if ( name === '*' ) {
23 return this.name;
24 }
25
26 // TODO this depends on the output format... works for CJS etc but not ES6
27 return `${this.name}.${name}`;
28 }
29
30 rename ( name, replacement ) {
31 this.canonicalNames[ name ] = replacement;
32 }
33
34 suggestName ( exportName, suggestion ) {
35 if ( !this.suggestedNames[ exportName ] ) {
36 this.suggestedNames[ exportName ] = suggestion;
37 }
38 }
39}