Browse Source

handle export *

contingency-plan
Rich-Harris 9 years ago
parent
commit
6646f156de
  1. 10
      src/Bundle.js
  2. 45
      src/Module.js
  3. 2
      test/function/export-all/_config.js

10
src/Bundle.js

@ -516,14 +516,8 @@ export default class Bundle {
const exportDeclaration = module.exports[ name ];
if ( exportDeclaration ) return this.trace( module, exportDeclaration.localName );
for ( let i = 0; i < module.exportDelegates.length; i += 1 ) {
const delegate = module.exportDelegates[i];
const delegateExportDeclaration = delegate.module.exports[ name ];
if ( delegateExportDeclaration ) {
return this.trace( delegate.module, delegateExportDeclaration.localName, es6 );
}
}
const exportDelegate = module.exportDelegates[ name ];
if ( exportDelegate ) return this.traceExport( exportDelegate.module, name, es6 );
throw new Error( `Could not trace binding '${name}' from ${module.id}` );
}

45
src/Module.js

@ -61,11 +61,9 @@ export default class Module {
this.imports = blank();
this.exports = blank();
this.reexports = blank();
this.exportDelegates = blank();
this.exportAlls = blank();
// array of all-export sources
this.exportDelegates = [];
this.exportAlls = [];
this.replacements = blank();
@ -90,7 +88,7 @@ export default class Module {
if ( node.type === 'ExportAllDeclaration' ) {
// Store `export * from '...'` statements in an array of delegates.
// When an unknown import is encountered, we see if one of them can satisfy it.
this.exportDelegates.push({
this.exportAlls.push({
statement,
source
});
@ -249,6 +247,11 @@ export default class Module {
});
});
this.exportAlls.forEach( delegate => {
const id = this.resolvedIds[ delegate.source ];
delegate.module = this.bundle.moduleById[ id ];
});
this.dependencies.forEach( source => {
const id = this.resolvedIds[ source ];
const module = this.bundle.moduleById[ id ];
@ -298,7 +301,7 @@ export default class Module {
keys( statement.stronglyDependsOn ).forEach( name => {
if ( statement.defines[ name ] ) return;
addDependency( strongDependencies, this.exportAlls[ name ] ) ||
addDependency( strongDependencies, this.exportDelegates[ name ] ) ||
addDependency( strongDependencies, this.imports[ name ] );
});
}
@ -310,7 +313,7 @@ export default class Module {
keys( statement.dependsOn ).forEach( name => {
if ( statement.defines[ name ] ) return;
addDependency( weakDependencies, this.exportAlls[ name ] ) ||
addDependency( weakDependencies, this.exportDelegates[ name ] ) ||
addDependency( weakDependencies, this.imports[ name ] );
});
});
@ -458,25 +461,25 @@ export default class Module {
return this.mark( exportDeclaration.localName );
}
const noExport = new Error( `Module ${this.id} does not export ${name} (imported by ${importer.id})` );
// See if there exists an export delegate that defines `name`.
for ( i = 0; i < this.exportDelegates.length; i += 1 ) {
const declaration = this.exportDelegates[i];
const result = declaration.module.mark( name );
let i;
for ( i = 0; i < this.exportAlls.length; i += 1 ) {
const declaration = this.exportAlls[i];
if ( !result.length ) throw noExport;
if ( declaration.module.exports[ name ] ) {
// It's found! This module exports `name` through declaration.
// It is however not imported into this scope.
this.exportDelegates[ name ] = declaration;
declaration.module.markExport( name );
// It's found! This module exports `name` through declaration.
// It is however not imported into this scope.
this.exportAlls[ name ] = declaration;
declaration.statement.dependsOn[ name ] =
declaration.statement.stronglyDependsOn[ name ] = true;
declaration.statement.dependsOn[ name ] =
declaration.statement.stronglyDependsOn[ name ] = result;
return result;
return;
}
}
throw new Error( `Module ${this.id} does not export ${name} (imported by ${importer.id})` );
}
parse ( ast ) {

2
test/function/export-all/_config.js

@ -1,5 +1,3 @@
var assert = require( 'assert' );
module.exports = {
description: 'allows export *'
};

Loading…
Cancel
Save