Browse Source

fix namespace reexports

contingency-plan
Rich Harris 10 years ago
parent
commit
7521fe7e25
  1. 38
      src/Bundle.js

38
src/Bundle.js

@ -339,23 +339,31 @@ export default class Bundle {
// prepend bundle with internal namespaces // prepend bundle with internal namespaces
const indentString = magicString.getIndentString(); const indentString = magicString.getIndentString();
const namespaceBlock = this.internalNamespaceModules.map( module => { const namespaceBlock = this.internalNamespaceModules.map( module => {
const exportKeys = keys( module.exports ); const exports = keys( module.exports ).map( key => {
const exportDeclaration = module.exports[ key ];
return `var ${module.replacements['*']} = {\n` + let localName = exportDeclaration.localName;
exportKeys.map( key => { localName = module.replacements[ localName ] || localName;
let actualModule = module; return `${indentString}get ${key} () { return ${localName}; }`;
let exportDeclaration = module.exports[ key ]; });
// special case - `export { default as foo } from './foo'`
while ( exportDeclaration.linkedImport ) {
actualModule = exportDeclaration.linkedImport.module;
exportDeclaration = actualModule.exports[ exportDeclaration.linkedImport.name ];
}
let localName = exportDeclaration.localName; const reexports = keys( module.reexports ).map( key => {
localName = actualModule.replacements[ localName ] || localName; let exportingModule = module;
return `${indentString}get ${key} () { return ${localName}; }`; // TODO... let actualKey = key;
}).join( ',\n' ) + let reexport;
while ( exportingModule.reexports[ key ] ) {
reexport = exportingModule.reexports[ key ];
exportingModule = reexport.module;
key = reexport.importedName;
}
key = exportingModule.replacements[ key ] || key;
return `${indentString}get ${actualKey} () { return ${key}; }`;
});
return `var ${module.replacements['*']} = {\n` +
exports.concat( reexports ).join( ',\n' ) +
`\n};\n\n`; `\n};\n\n`;
}).join( '' ); }).join( '' );

Loading…
Cancel
Save