@@ -48,7 +48,7 @@ namespace ts.refactor {
48
48
} ) ;
49
49
50
50
// If a VariableStatement, will have exactly one VariableDeclaration, with an Identifier for a name.
51
- type ExportToConvert = FunctionDeclaration | ClassDeclaration | InterfaceDeclaration | EnumDeclaration | NamespaceDeclaration | TypeAliasDeclaration | VariableStatement ;
51
+ type ExportToConvert = FunctionDeclaration | ClassDeclaration | InterfaceDeclaration | EnumDeclaration | NamespaceDeclaration | TypeAliasDeclaration | VariableStatement | ExportAssignment ;
52
52
interface ExportInfo {
53
53
readonly exportNode : ExportToConvert ;
54
54
readonly exportName : Identifier ; // This is exportNode.name except for VariableStatement_s.
@@ -67,7 +67,8 @@ namespace ts.refactor {
67
67
68
68
const exportingModuleSymbol = isSourceFile ( exportNode . parent ) ? exportNode . parent . symbol : exportNode . parent . parent . symbol ;
69
69
70
- const flags = getSyntacticModifierFlags ( exportNode ) ;
70
+ const flags = getSyntacticModifierFlags ( exportNode ) || ( ( isExportAssignment ( exportNode ) && ! exportNode . isExportEquals ) ? ModifierFlags . ExportDefault : ModifierFlags . None ) ;
71
+
71
72
const wasDefault = ! ! ( flags & ModifierFlags . Default ) ;
72
73
// If source file already has a default export, don't offer refactor.
73
74
if ( ! ( flags & ModifierFlags . Export ) || ! wasDefault && exportingModuleSymbol . exports ! . has ( InternalSymbolName . Default ) ) {
@@ -95,6 +96,11 @@ namespace ts.refactor {
95
96
Debug . assert ( ! wasDefault , "Can't have a default flag here" ) ;
96
97
return isIdentifier ( decl . name ) ? { exportNode : vs , exportName : decl . name , wasDefault, exportingModuleSymbol } : undefined ;
97
98
}
99
+ case SyntaxKind . ExportAssignment : {
100
+ const node = exportNode as ExportAssignment ;
101
+ const exp = node . expression as Identifier ;
102
+ return node . isExportEquals ? undefined : { exportNode : node , exportName : exp , wasDefault, exportingModuleSymbol } ;
103
+ }
98
104
default :
99
105
return undefined ;
100
106
}
@@ -107,7 +113,14 @@ namespace ts.refactor {
107
113
108
114
function changeExport ( exportingSourceFile : SourceFile , { wasDefault, exportNode, exportName } : ExportInfo , changes : textChanges . ChangeTracker , checker : TypeChecker ) : void {
109
115
if ( wasDefault ) {
110
- changes . delete ( exportingSourceFile , Debug . checkDefined ( findModifier ( exportNode , SyntaxKind . DefaultKeyword ) , "Should find a default keyword in modifier list" ) ) ;
116
+ if ( isExportAssignment ( exportNode ) && ! exportNode . isExportEquals ) {
117
+ const exp = exportNode . expression as Identifier ;
118
+ const spec = makeExportSpecifier ( exp . text , exp . text ) ;
119
+ changes . replaceNode ( exportingSourceFile , exportNode , factory . createExportDeclaration ( /*decorators*/ undefined , /*modifiers*/ undefined , /*isTypeOnly*/ false , factory . createNamedExports ( [ spec ] ) ) ) ;
120
+ }
121
+ else {
122
+ changes . delete ( exportingSourceFile , Debug . checkDefined ( findModifier ( exportNode , SyntaxKind . DefaultKeyword ) , "Should find a default keyword in modifier list" ) ) ;
123
+ }
111
124
}
112
125
else {
113
126
const exportKeyword = Debug . checkDefined ( findModifier ( exportNode , SyntaxKind . ExportKeyword ) , "Should find an export keyword in modifier list" ) ;
@@ -134,7 +147,7 @@ namespace ts.refactor {
134
147
changes . insertNodeAfter ( exportingSourceFile , exportNode , factory . createExportDefault ( factory . createIdentifier ( exportName . text ) ) ) ;
135
148
break ;
136
149
default :
137
- Debug . assertNever ( exportNode , `Unexpected exportNode kind ${ ( exportNode as ExportToConvert ) . kind } ` ) ;
150
+ Debug . fail ( `Unexpected exportNode kind ${ ( exportNode as ExportToConvert ) . kind } ` ) ;
138
151
}
139
152
}
140
153
}
0 commit comments