Browse Source

handle tricky `export { default as foo } from ...` case

contingency-plan
Rich-Harris 10 years ago
parent
commit
ae93c679cb
  1. 13
      src/Bundle.js
  2. 21
      src/Module.js

13
src/Bundle.js

@ -394,8 +394,17 @@ export default class Bundle {
return `var ${module.replacements['*']} = {\n` +
exportKeys.map( key => {
let localName = module.exports[ key ].localName;
localName = module.replacements[ localName ] || localName;
let actualModule = module;
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;
localName = actualModule.replacements[ localName ] || localName;
return `${indentString}get ${key} () { return ${localName}; }`; // TODO...
}).join( ',\n' ) +
`\n};\n\n`;

21
src/Module.js

@ -108,11 +108,6 @@ export default class Module {
const localName = specifier.local.name;
const exportedName = specifier.exported.name;
this.exports[ exportedName ] = {
localName,
exportedName
};
// export { foo } from './foo';
if ( source ) {
this.imports[ localName ] = {
@ -121,6 +116,12 @@ export default class Module {
name: localName
};
}
this.exports[ exportedName ] = {
localName,
exportedName,
linkedImport: source ? this.imports[ localName ] : null
};
});
}
@ -350,7 +351,7 @@ export default class Module {
this.bundle.internalNamespaceModules.push( module );
}
return module.markAllStatements();
return module.markAllExportStatements();
}
const exportDeclaration = module.exports[ importDeclaration.name ];
@ -467,6 +468,14 @@ export default class Module {
});
}
markAllExportStatements () {
return sequence( this.statements, statement => {
return statement.isExportDeclaration ?
statement.mark() :
null;
});
}
// TODO rename this to parse, once https://github.com/rollup/rollup/issues/42 is fixed
_parse ( ast ) {
// The ast can be supplied programmatically (but usually won't be)

Loading…
Cancel
Save