Browse Source

more fixes

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

38
src/Bundle.js

@ -162,19 +162,20 @@ export default class Bundle {
this.orderedModules.forEach( module => {
if ( !module.needsDefault && !module.needsAll ) return;
if ( module.needsDefault ) {
const defaultExport = module.exports.default;
if ( module.needsAll ) {
const namespaceName = getSafeName( module.suggestedNames[ '*' ] );
module.replacements[ '*' ] = namespaceName;
}
// only create a new name if either
// a) it's an expression (`export default 42`) or
// b) it's a name that is reassigned to (`export var a = 1; a = 2`)
if ( defaultExport.declaredName && !defaultExport.isModified ) return; // TODO encapsulate check for whether we need synthetic default name
const defaultExport = module.exports.default;
const defaultName = getSafeName( module.suggestedNames.default );
module.replacements.default = defaultName;
}
// only create a new name if either
// a) it's an expression (`export default 42`) or
// b) it's a name that is reassigned to (`export var a = 1; a = 2`)
if ( defaultExport.declaredName && !defaultExport.isModified ) return; // TODO encapsulate check for whether we need synthetic default name
// TODO namespace
const defaultName = getSafeName( module.suggestedNames.default );
module.replacements.default = defaultName;
});
this.orderedModules.forEach( module => {
@ -208,19 +209,21 @@ export default class Bundle {
otherModule.name;
}
// TODO namespaces
if ( importDeclaration.name === '*' ) {
return otherModule.name;
}
return `${otherModule.name}.${importDeclaration.name}`;
}
if ( importDeclaration.name === '*' ) {
return otherModule.replacements[ '*' ];
}
const exportDeclaration = otherModule.exports[ importDeclaration.name ];
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 ) {
while ( definers[ name ] || conflicts[ name ] ) { // TODO this seems wonky
name = `_${name}`;
@ -387,9 +390,10 @@ export default class Bundle {
const namespaceBlock = this.internalNamespaceModules.map( module => {
const exportKeys = keys( module.exports );
return `var ${module.namespaceName} = {\n` +
return `var ${module.replacements['*']} = {\n` +
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...
}).join( ',\n' ) +
`\n};\n\n`;

5
src/finalisers/shared/getExportBlock.js

@ -1,7 +1,10 @@
export default function getExportBlock ( bundle, exportMode, mechanism = 'return' ) {
if ( exportMode === '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};`;
}

Loading…
Cancel
Save