mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix rename cause import change wrongly (#38462)
* use canonical file name when resolve module * renameSync in vfs supports same folder. * Update src/harness/vfsUtil.ts Co-authored-by: Ron Buckton <ron.buckton@microsoft.com> * change tss rather than compiler. * remove useless comment. * use fileName rather than path. Co-authored-by: Song Gao <song.gao@laserfiche.com> Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
This commit is contained in:
co-authored by
Ron Buckton
Song Gao
parent
f697d26ca1
commit
8293e517c0
@@ -596,7 +596,9 @@ namespace vfs {
|
||||
if (existingNode) {
|
||||
if (isDirectory(node)) {
|
||||
if (!isDirectory(existingNode)) throw createIOError("ENOTDIR");
|
||||
if (this._getLinks(existingNode).size > 0) throw createIOError("ENOTEMPTY");
|
||||
// if both old and new arguments point to the same directory, just pass. So we could rename /src/a/1 to /src/A/1 in Win.
|
||||
// if not and the directory pointed by the new path is not empty, throw an error.
|
||||
if (this.stringComparer(oldpath, newpath) !== 0 && this._getLinks(existingNode).size > 0) throw createIOError("ENOTEMPTY");
|
||||
}
|
||||
else {
|
||||
if (isDirectory(existingNode)) throw createIOError("EISDIR");
|
||||
|
||||
@@ -126,8 +126,8 @@ namespace ts {
|
||||
): void {
|
||||
const allFiles = program.getSourceFiles();
|
||||
for (const sourceFile of allFiles) {
|
||||
const newFromOld = oldToNew(sourceFile.path) as Path;
|
||||
const newImportFromPath = newFromOld !== undefined ? newFromOld : sourceFile.path;
|
||||
const newFromOld = oldToNew(sourceFile.fileName);
|
||||
const newImportFromPath = newFromOld ?? sourceFile.fileName;
|
||||
const newImportFromDirectory = getDirectoryPath(newImportFromPath);
|
||||
|
||||
const oldFromNew: string | undefined = newToOld(sourceFile.fileName);
|
||||
@@ -157,7 +157,7 @@ namespace ts {
|
||||
|
||||
// Need an update if the imported file moved, or the importing file moved and was using a relative path.
|
||||
return toImport !== undefined && (toImport.updated || (importingSourceFileMoved && pathIsRelative(importLiteral.text)))
|
||||
? moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), newImportFromPath, toImport.newFileName, createModuleSpecifierResolutionHost(program, host), importLiteral.text)
|
||||
? moduleSpecifiers.updateModuleSpecifier(program.getCompilerOptions(), getCanonicalFileName(newImportFromPath) as Path, toImport.newFileName, createModuleSpecifierResolutionHost(program, host), importLiteral.text)
|
||||
: undefined;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a/b/file1.ts
|
||||
////import { foo } from "foo";
|
||||
|
||||
// @Filename: /a/node_modules/foo/index.d.ts
|
||||
////export const foo = 0;
|
||||
|
||||
verify.getEditsForFileRename({
|
||||
oldPath: "/a/b",
|
||||
newPath: "/a/B",
|
||||
newFileContents: {},
|
||||
});
|
||||
Reference in New Issue
Block a user