mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 12:03:44 -05:00
fix(39410): don't remove variables with type definition during converting named export to default (#39505)
This commit is contained in:
@@ -110,10 +110,11 @@ namespace ts.refactor {
|
||||
changes.insertNodeAfter(exportingSourceFile, exportKeyword, factory.createToken(SyntaxKind.DefaultKeyword));
|
||||
break;
|
||||
case SyntaxKind.VariableStatement:
|
||||
// If 'x' isn't used in this file, `export const x = 0;` --> `export default 0;`
|
||||
if (!FindAllReferences.Core.isSymbolReferencedInFile(exportName, checker, exportingSourceFile)) {
|
||||
// If 'x' isn't used in this file and doesn't have type definition, `export const x = 0;` --> `export default 0;`
|
||||
const decl = first(exportNode.declarationList.declarations);
|
||||
if (!FindAllReferences.Core.isSymbolReferencedInFile(exportName, checker, exportingSourceFile) && !decl.type) {
|
||||
// We checked in `getInfo` that an initializer exists.
|
||||
changes.replaceNode(exportingSourceFile, exportNode, factory.createExportDefault(Debug.checkDefined(first(exportNode.declarationList.declarations).initializer, "Initializer was previously known to be present")));
|
||||
changes.replaceNode(exportingSourceFile, exportNode, factory.createExportDefault(Debug.checkDefined(decl.initializer, "Initializer was previously known to be present")));
|
||||
break;
|
||||
}
|
||||
// falls through
|
||||
|
||||
Reference in New Issue
Block a user