Skip to content

Commit ae6b6da

Browse files
committed
fix(47821): skip nodes with export modifiers
1 parent df673f7 commit ae6b6da

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

src/services/importTracker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,14 @@ namespace ts.FindAllReferences {
392392
if (cancellationToken) cancellationToken.throwIfCancellationRequested();
393393
forEachImport(sourceFile, (importDecl, moduleSpecifier) => {
394394
const moduleSymbol = checker.getSymbolAtLocation(moduleSpecifier);
395-
if (moduleSymbol) {
396-
const id = getSymbolId(moduleSymbol).toString();
395+
forEach(moduleSymbol?.declarations, declaration => {
396+
const id = getSymbolId(declaration.symbol).toString();
397397
let imports = map.get(id);
398398
if (!imports) {
399399
map.set(id, imports = []);
400400
}
401401
imports.push(importDecl);
402-
}
402+
});
403403
});
404404
}
405405

src/services/refactors/convertExport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ namespace ts.refactor {
6666
}
6767

6868
const exportingModuleSymbol = isSourceFile(exportNode.parent) ? exportNode.parent.symbol : exportNode.parent.parent.symbol;
69-
7069
const flags = getSyntacticModifierFlags(exportNode) || ((isExportAssignment(exportNode) && !exportNode.isExportEquals) ? ModifierFlags.ExportDefault : ModifierFlags.None);
7170

7271
const wasDefault = !!(flags & ModifierFlags.Default);
@@ -165,6 +164,7 @@ namespace ts.refactor {
165164
const checker = program.getTypeChecker();
166165
const exportSymbol = Debug.checkDefined(checker.getSymbolAtLocation(exportName), "Export name should resolve to a symbol");
167166
FindAllReferences.Core.eachExportReference(program.getSourceFiles(), checker, cancellationToken, exportSymbol, exportingModuleSymbol, exportName.text, wasDefault, ref => {
167+
if (exportName === ref) return;
168168
const importingSourceFile = ref.getSourceFile();
169169
if (wasDefault) {
170170
changeDefaultToNamedImport(importingSourceFile, ref, changes, exportName.text);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /node_modules/@types/foo/index.d.ts
4+
////export {};
5+
////declare module "foo" {
6+
//// /*a*/export function foo(): void;/*b*/
7+
////}
8+
9+
// @Filename: /b.ts
10+
////import { foo } from "foo";
11+
12+
goTo.select("a", "b");
13+
edit.applyRefactor({
14+
refactorName: "Convert export",
15+
actionName: "Convert named export to default export",
16+
actionDescription: "Convert named export to default export",
17+
newContent: {
18+
"/node_modules/@types/foo/index.d.ts":
19+
`export {};
20+
declare module "foo" {
21+
export default function foo(): void;
22+
}`,
23+
"/b.ts":
24+
`import foo from "foo";`
25+
}
26+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////export {};
4+
////declare module "foo" {
5+
//// /*a*/export function func(): void;/*b*/
6+
////}
7+
8+
goTo.select("a", "b");
9+
edit.applyRefactor({
10+
refactorName: "Convert export",
11+
actionName: "Convert named export to default export",
12+
actionDescription: "Convert named export to default export",
13+
newContent:
14+
`export {};
15+
declare module "foo" {
16+
export default function func(): void;
17+
}`
18+
});

0 commit comments

Comments
 (0)