Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rename cause import change wrongly #38462

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/harness/vfsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,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");
Expand Down
6 changes: 3 additions & 3 deletions src/services/getEditsForFileRename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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: {},
});