Browse Source

fix more tests, messily

contingency-plan
Rich Harris 10 years ago
parent
commit
419a37f145
  1. 17
      src/Bundle.js
  2. 15
      src/Module.js
  3. 4
      src/Statement.js
  4. 5
      src/finalisers/shared/getExportBlock.js

17
src/Bundle.js

@ -309,6 +309,7 @@ export default class Bundle {
keys( this.entryModule.reexports ).forEach( key => {
const reexportDeclaration = this.entryModule.reexports[ key ];
if ( reexportDeclaration.module.isExternal ) return;
const originalDeclaration = reexportDeclaration.module.findDeclaration( reexportDeclaration.importedName );
if ( originalDeclaration && originalDeclaration.type === 'VariableDeclaration' ) {
@ -530,6 +531,22 @@ export default class Bundle {
traceExport ( module, name, es6 ) {
const reexportDeclaration = module.reexports[ name ];
if ( reexportDeclaration ) {
if ( reexportDeclaration.module.isExternal ) {
if ( name === 'default' ) {
return reexportDeclaration.module.needsNamed && !es6 ?
`${reexportDeclaration.module.name}__default` :
reexportDeclaration.module.name;
}
if ( name === '*' ) {
return reexportDeclaration.module.name;
}
return es6 ?
name :
`${reexportDeclaration.module.name}.${name}`;
}
return this.traceExport( reexportDeclaration.module, reexportDeclaration.importedName );
}

15
src/Module.js

@ -239,7 +239,7 @@ export default class Module {
let module = this;
let name = specifier.exported.name;
while ( module.reexports[ name ] && module.reexports[ name ].isUsed ) {
while ( !module.isExternal && module.reexports[ name ] && module.reexports[ name ].isUsed ) {
reexport = module.reexports[ name ];
module = reexport.module;
name = reexport.importedName;
@ -266,15 +266,6 @@ export default class Module {
keys( statement.dependsOn ).forEach( name => {
if ( statement.defines[ name ] ) return;
let module = this;
let reexportDeclaration;
while ( module.reexports[ name ] ) {
reexportDeclaration = module.reexports[ name ];
module = reexportDeclaration.module;
name = reexportDeclaration.importedName;
}
addDependency( weakDependencies, reexportDeclaration ) ||
addDependency( weakDependencies, this.exportAlls[ name ] ) ||
addDependency( weakDependencies, this.imports[ name ] );
});
@ -395,7 +386,7 @@ export default class Module {
return module.markAllExportStatements();
}
return module.markExport( importDeclaration.name, 'TODO_suggestedName', this );
return module.markExport( importDeclaration.name, name, this );
});
}
@ -461,7 +452,7 @@ export default class Module {
return this.bundle.fetchModule( reexportDeclaration.source, this.id )
.then( otherModule => {
reexportDeclaration.module = otherModule;
return otherModule.markExport( reexportDeclaration.importedName, 'TODO_suggestedName', this );
return otherModule.markExport( reexportDeclaration.importedName, suggestedName, this );
});
}

4
src/Statement.js

@ -246,7 +246,9 @@ export default class Statement {
reexport.isUsed = true;
reexport.module = otherModule;
return otherModule.markExport( specifier.local.name, specifier.exported.name, this.module );
return otherModule.isExternal ?
null :
otherModule.markExport( specifier.local.name, specifier.exported.name, this.module );
});
});
}

5
src/finalisers/shared/getExportBlock.js

@ -11,7 +11,10 @@ export default function getExportBlock ( bundle, exportMode, mechanism = 'return
return bundle.toExport
.map( name => {
const prop = name === 'default' ? `['default']` : `.${name}`;
name = bundle.trace( bundle.entryModule, name );
const reexport = bundle.entryModule.reexports[ name ];
name = reexport ?
bundle.traceExport( bundle.entryModule, name ) :
bundle.trace( bundle.entryModule, name );
return `exports${prop} = ${name};`;
})
.join( '\n' );

Loading…
Cancel
Save