From e7bbd516d189a3426064668d0bb3f5afa32f7b9b Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 15 Aug 2015 22:09:22 -0400 Subject: [PATCH] combine declaredName and identifier --- src/Bundle.js | 6 +++--- src/Module.js | 12 +++++++----- src/finalisers/shared/getExportBlock.js | 3 +-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index 0976938..061062f 100644 --- a/src/Bundle.js +++ b/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; diff --git a/src/Module.js b/src/Module.js index 36a6be3..91b3cd5 100644 --- a/src/Module.js +++ b/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 { diff --git a/src/finalisers/shared/getExportBlock.js b/src/finalisers/shared/getExportBlock.js index 1d6c274..f97bfef 100644 --- a/src/finalisers/shared/getExportBlock.js +++ b/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};`; }