Skip to content

Commit 42fc843

Browse files
author
Andy
authored
getEditsForFileRename: Don't update import with non-relative path if the imported file didn't move (microsoft#25159)
1 parent cb9c3e0 commit 42fc843

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/services/getEditsForFileRename.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ namespace ts {
125125
// TODO:GH#18217
126126
? getSourceFileToImportFromResolved(resolveModuleName(importLiteral.text, oldImportFromPath, program.getCompilerOptions(), host as ModuleResolutionHost), oldToNew, program)
127127
: getSourceFileToImport(importLiteral, sourceFile, program, host, oldToNew);
128-
// If neither the importing source file nor the imported file moved, do nothing.
129-
return toImport === undefined || !toImport.updated && !importingSourceFileMoved
130-
? undefined
131-
: moduleSpecifiers.getModuleSpecifier(program.getCompilerOptions(), sourceFile, newImportFromPath, toImport.newFileName, host, preferences);
128+
129+
// Need an update if the imported file moved, or the importing file moved and was using a relative path.
130+
return toImport !== undefined && (toImport.updated || (importingSourceFileMoved && pathIsRelative(importLiteral.text)))
131+
? moduleSpecifiers.getModuleSpecifier(program.getCompilerOptions(), sourceFile, newImportFromPath, toImport.newFileName, host, preferences)
132+
: undefined;
132133
});
133134
}
134135
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /sub/a.ts
4+
////export const a = 1;
5+
6+
// @Filename: /sub/b.ts
7+
////import { a } from "sub/a";
8+
9+
// @Filename: /tsconfig.json
10+
////{
11+
//// "compilerOptions": {
12+
//// "baseUrl": "."
13+
//// }
14+
////}
15+
16+
verify.getEditsForFileRename({
17+
oldPath: "/sub/b.ts",
18+
newPath: "/sub/c/d.ts",
19+
newFileContents: {},
20+
});

0 commit comments

Comments
 (0)