Browse Source

combine declaredName and identifier

contingency-plan
Rich-Harris 10 years ago
parent
commit
e7bbd516d1
  1. 6
      src/Bundle.js
  2. 12
      src/Module.js
  3. 3
      src/finalisers/shared/getExportBlock.js

6
src/Bundle.js

@ -56,8 +56,8 @@ export default class Bundle {
// `export default function foo () {...}` -
// use the declared name for the export
if ( defaultExport.declaredName ) {
entryModule.suggestName( 'default', defaultExport.declaredName );
if ( defaultExport.identifier ) {
entryModule.suggestName( 'default', defaultExport.identifier );
}
// `export default a + b` - generate an export name
@ -175,7 +175,7 @@ export default class Bundle {
// 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 && defaultExport.declaredName && !defaultExport.isModified ) return; // TODO encapsulate check for whether we need synthetic default name
if ( defaultExport && defaultExport.identifier && !defaultExport.isModified ) return; // TODO encapsulate check for whether we need synthetic default name
const defaultName = getSafeName( module.suggestedNames.default );
module.replacements.default = defaultName;

12
src/Module.js

@ -83,14 +83,16 @@ export default class Module {
const isDeclaration = /Declaration$/.test( node.declaration.type );
const isAnonymous = /(?:Class|Function)Expression$/.test( node.declaration.type );
const declaredName = isDeclaration && node.declaration.id.name;
const identifier = node.declaration.type === 'Identifier' && node.declaration.name;
const identifier = isDeclaration ?
node.declaration.id.name :
node.declaration.type === 'Identifier' ?
node.declaration.name :
null;
this.exports.default = {
statement,
name: 'default',
localName: declaredName || 'default',
declaredName,
localName: identifier || 'default',
identifier,
isDeclaration,
isAnonymous,
@ -389,7 +391,7 @@ export default class Module {
else if ( name === 'default' && this.exports.default.isDeclaration ) {
// We have something like `export default foo` - so we just start again,
// searching for `foo` instead of default
promise = this.mark( this.exports.default.name );
promise = this.mark( this.exports.default.name ); // TODO this can't be right... this.exports.default.name === 'default'
}
else {

3
src/finalisers/shared/getExportBlock.js

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

Loading…
Cancel
Save