mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
fix(48544): allow to convert default exports to names for import type nodes (#48550)
This commit is contained in:
parent
50a5bc839a
commit
9881c993fc
@ -1193,10 +1193,15 @@ namespace ts.FindAllReferences {
|
||||
cb: (ref: Identifier) => void,
|
||||
): void {
|
||||
const importTracker = createImportTracker(sourceFiles, new Set(sourceFiles.map(f => f.fileName)), checker, cancellationToken);
|
||||
const { importSearches, indirectUsers } = importTracker(exportSymbol, { exportKind: isDefaultExport ? ExportKind.Default : ExportKind.Named, exportingModuleSymbol }, /*isForRename*/ false);
|
||||
const { importSearches, indirectUsers, singleReferences } = importTracker(exportSymbol, { exportKind: isDefaultExport ? ExportKind.Default : ExportKind.Named, exportingModuleSymbol }, /*isForRename*/ false);
|
||||
for (const [importLocation] of importSearches) {
|
||||
cb(importLocation);
|
||||
}
|
||||
for (const singleReference of singleReferences) {
|
||||
if (isIdentifier(singleReference) && isImportTypeNode(singleReference.parent)) {
|
||||
cb(singleReference);
|
||||
}
|
||||
}
|
||||
for (const indirectUser of indirectUsers) {
|
||||
for (const node of getPossibleSymbolReferenceNodes(indirectUser, isDefaultExport ? "default" : exportName)) {
|
||||
// Import specifiers should be handled by importSearches
|
||||
|
||||
@ -212,6 +212,10 @@ namespace ts.refactor {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SyntaxKind.ImportType:
|
||||
const importTypeNode = parent as ImportTypeNode;
|
||||
changes.replaceNode(importingSourceFile, parent, factory.createImportTypeNode(importTypeNode.argument, factory.createIdentifier(exportName), importTypeNode.typeArguments, importTypeNode.isTypeOf));
|
||||
break;
|
||||
default:
|
||||
Debug.failBadSyntaxKind(parent);
|
||||
}
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @Filename: /a.ts
|
||||
/////*a*/export default class A {}/*b*/
|
||||
|
||||
// @Filename: /b.ts
|
||||
////export type A = typeof import("./a").default;
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert export",
|
||||
actionName: "Convert default export to named export",
|
||||
actionDescription: "Convert default export to named export",
|
||||
newContent: {
|
||||
"/a.ts": "export class A {}",
|
||||
"/b.ts": "export type A = typeof import(\"./a\").A;"
|
||||
},
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user