Browse Source

ensure entry module exports are defined

contingency-plan
Rich Harris 10 years ago
parent
commit
778a71165d
  1. 2
      src/Bundle.js
  2. 1
      src/ExternalModule.js
  3. 27
      src/Module.js

2
src/Bundle.js

@ -65,7 +65,7 @@ export default class Bundle {
return this.fetchModule( this.entryPath, null )
.then( entryModule => {
this.entryModule = entryModule;
return entryModule.expandAllStatements();
return entryModule.expandAllStatements( true );
})
.then( statements => {
this.statements = statements;

1
src/ExternalModule.js

@ -2,6 +2,7 @@ export default class ExternalModule {
constructor ( id ) {
this.id = id;
this.name = null;
this.module = null;
this.isExternal = true;
this.importedByBundle = [];

27
src/Module.js

@ -164,16 +164,16 @@ export default class Module {
});
}
getCanonicalName ( name ) {
if ( has( this.suggestedNames, name ) ) {
name = this.suggestedNames[ name ];
getCanonicalName ( localName ) {
if ( has( this.suggestedNames, localName ) ) {
localName = this.suggestedNames[ localName ];
}
if ( !has( this.canonicalNames, name ) ) {
if ( !has( this.canonicalNames, localName ) ) {
let canonicalName;
if ( has( this.imports, name ) ) {
const importDeclaration = this.imports[ name ];
if ( has( this.imports, localName ) ) {
const importDeclaration = this.imports[ localName ];
const module = importDeclaration.module;
if ( importDeclaration.name === '*' ) {
@ -193,13 +193,13 @@ export default class Module {
}
else {
canonicalName = name;
canonicalName = localName;
}
this.canonicalNames[ name ] = canonicalName;
this.canonicalNames[ localName ] = canonicalName;
}
return this.canonicalNames[ name ];
return this.canonicalNames[ localName ];
}
define ( name ) {
@ -326,8 +326,6 @@ export default class Module {
// then include any statements that could modify the
// thing(s) this statement defines
.then( () => {
const definedByThisStatement = keys( statement._defines );
return sequence( keys( statement._defines ), name => {
const modifications = has( this.modifications, name ) && this.modifications[ name ];
@ -350,7 +348,7 @@ export default class Module {
});
}
expandAllStatements () {
expandAllStatements ( isEntryModule ) {
let allStatements = [];
return sequence( this.ast.body, statement => {
@ -361,7 +359,10 @@ export default class Module {
if ( /^Import/.test( statement.type ) ) return;
// skip `export { foo, bar, baz }`
if ( statement.type === 'ExportNamedDeclaration' && statement.specifiers.length ) return;
if ( statement.type === 'ExportNamedDeclaration' && statement.specifiers.length ) {
// but ensure they are defined, if this is the entry module
return isEntryModule ? this.expandStatement( statement ) : null;
}
// include everything else

Loading…
Cancel
Save