Browse Source

more fixes

contingency-plan
Rich-Harris 10 years ago
parent
commit
e0c554a801
  1. 26
      src/Bundle.js
  2. 5
      src/finalisers/shared/getExportBlock.js

26
src/Bundle.js

@ -162,7 +162,11 @@ export default class Bundle {
this.orderedModules.forEach( module => { this.orderedModules.forEach( module => {
if ( !module.needsDefault && !module.needsAll ) return; if ( !module.needsDefault && !module.needsAll ) return;
if ( module.needsDefault ) { if ( module.needsAll ) {
const namespaceName = getSafeName( module.suggestedNames[ '*' ] );
module.replacements[ '*' ] = namespaceName;
}
const defaultExport = module.exports.default; const defaultExport = module.exports.default;
// only create a new name if either // only create a new name if either
@ -172,9 +176,6 @@ export default class Bundle {
const defaultName = getSafeName( module.suggestedNames.default ); const defaultName = getSafeName( module.suggestedNames.default );
module.replacements.default = defaultName; module.replacements.default = defaultName;
}
// TODO namespace
}); });
this.orderedModules.forEach( module => { this.orderedModules.forEach( module => {
@ -208,19 +209,21 @@ export default class Bundle {
otherModule.name; otherModule.name;
} }
// TODO namespaces if ( importDeclaration.name === '*' ) {
return otherModule.name;
}
return `${otherModule.name}.${importDeclaration.name}`; return `${otherModule.name}.${importDeclaration.name}`;
} }
if ( importDeclaration.name === '*' ) {
return otherModule.replacements[ '*' ];
}
const exportDeclaration = otherModule.exports[ importDeclaration.name ]; const exportDeclaration = otherModule.exports[ importDeclaration.name ];
return trace( otherModule, exportDeclaration.localName ); return trace( otherModule, exportDeclaration.localName );
} }
// TODO assign names to default/namespace exports, based on suggestions
// TODO trace bindings and rename within modules here (rather than later
// with getCanonicalName)
function getSafeName ( name ) { function getSafeName ( name ) {
while ( definers[ name ] || conflicts[ name ] ) { // TODO this seems wonky while ( definers[ name ] || conflicts[ name ] ) { // TODO this seems wonky
name = `_${name}`; name = `_${name}`;
@ -387,9 +390,10 @@ export default class Bundle {
const namespaceBlock = this.internalNamespaceModules.map( module => { const namespaceBlock = this.internalNamespaceModules.map( module => {
const exportKeys = keys( module.exports ); const exportKeys = keys( module.exports );
return `var ${module.namespaceName} = {\n` + return `var ${module.replacements['*']} = {\n` +
exportKeys.map( key => { exportKeys.map( key => {
const localName = module.exports[ key ].localName; let localName = module.exports[ key ].localName;
localName = module.replacements[ localName ] || localName;
return `${indentString}get ${key} () { return ${localName}; }`; // TODO... return `${indentString}get ${key} () { return ${localName}; }`; // TODO...
}).join( ',\n' ) + }).join( ',\n' ) +
`\n};\n\n`; `\n};\n\n`;

5
src/finalisers/shared/getExportBlock.js

@ -1,7 +1,10 @@
export default function getExportBlock ( bundle, exportMode, mechanism = 'return' ) { export default function getExportBlock ( bundle, exportMode, mechanism = 'return' ) {
if ( exportMode === 'default' ) { if ( exportMode === 'default' ) {
const defaultExport = bundle.entryModule.exports.default; const defaultExport = bundle.entryModule.exports.default;
let defaultExportName = bundle.entryModule.replacements.default || defaultExport.statement.node.declaration.name;
const defaultExportName = bundle.entryModule.replacements.default ||
defaultExport.declaredName || // TODO can these be unified?
defaultExport.statement.node.declaration.name;
return `${mechanism} ${defaultExportName};`; return `${mechanism} ${defaultExportName};`;
} }

Loading…
Cancel
Save