@@ -57,7 +57,7 @@ namespace ts.refactor {
57
57
} ;
58
58
59
59
function getInfo ( context : RefactorContext , considerPartialSpans = true ) : ExportInfo | RefactorErrorInfo | undefined {
60
- const { file } = context ;
60
+ const { file, program } = context ;
61
61
const span = getRefactorContextSpan ( context ) ;
62
62
const token = getTokenAtPosition ( file , span . start ) ;
63
63
const exportNode = ! ! ( token . parent && getSyntacticModifierFlags ( token . parent ) & ModifierFlags . Export ) && considerPartialSpans ? token . parent : getParentNodeInSpan ( token , file , span ) ;
@@ -75,6 +75,11 @@ namespace ts.refactor {
75
75
return { error : getLocaleSpecificMessage ( Diagnostics . This_file_already_has_a_default_export ) } ;
76
76
}
77
77
78
+ const checker = program . getTypeChecker ( ) ;
79
+ const noSymbolError = ( id : Node ) =>
80
+ ( isIdentifier ( id ) && checker . getSymbolAtLocation ( id ) ) ? undefined
81
+ : { error : getLocaleSpecificMessage ( Diagnostics . Can_only_convert_named_export ) } ;
82
+
78
83
switch ( exportNode . kind ) {
79
84
case SyntaxKind . FunctionDeclaration :
80
85
case SyntaxKind . ClassDeclaration :
@@ -83,7 +88,9 @@ namespace ts.refactor {
83
88
case SyntaxKind . TypeAliasDeclaration :
84
89
case SyntaxKind . ModuleDeclaration : {
85
90
const node = exportNode as FunctionDeclaration | ClassDeclaration | InterfaceDeclaration | EnumDeclaration | TypeAliasDeclaration | NamespaceDeclaration ;
86
- return node . name && isIdentifier ( node . name ) ? { exportNode : node , exportName : node . name , wasDefault, exportingModuleSymbol } : undefined ;
91
+ if ( ! node . name ) return undefined ;
92
+ return noSymbolError ( node . name )
93
+ || { exportNode : node , exportName : node . name , wasDefault, exportingModuleSymbol } ;
87
94
}
88
95
case SyntaxKind . VariableStatement : {
89
96
const vs = exportNode as VariableStatement ;
@@ -94,12 +101,14 @@ namespace ts.refactor {
94
101
const decl = first ( vs . declarationList . declarations ) ;
95
102
if ( ! decl . initializer ) return undefined ;
96
103
Debug . assert ( ! wasDefault , "Can't have a default flag here" ) ;
97
- return isIdentifier ( decl . name ) ? { exportNode : vs , exportName : decl . name , wasDefault, exportingModuleSymbol } : undefined ;
104
+ return noSymbolError ( decl . name )
105
+ || { exportNode : vs , exportName : decl . name as Identifier , wasDefault, exportingModuleSymbol } ;
98
106
}
99
107
case SyntaxKind . ExportAssignment : {
100
108
const node = exportNode as ExportAssignment ;
101
- const exp = node . expression as Identifier ;
102
- return node . isExportEquals ? undefined : { exportNode : node , exportName : exp , wasDefault, exportingModuleSymbol } ;
109
+ if ( node . isExportEquals ) return undefined ;
110
+ return noSymbolError ( node . expression )
111
+ || { exportNode : node , exportName : node . expression as Identifier , wasDefault, exportingModuleSymbol } ;
103
112
}
104
113
default :
105
114
return undefined ;
0 commit comments