Skip to content

Conversation

@eloyrobillard
Copy link
Contributor

Fixes #57451

@eloyrobillard
Copy link
Contributor Author

@microsoft-github-policy-service agree

Comment on lines 432 to 440
const pathToTargetFileWithExtension = resolvePath(getDirectoryPath(oldFile.path), targetFileName);

// no self-imports
if (sourceFile.fileName === pathToTargetFileWithExtension) return;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const pathToTargetFileWithExtension = resolvePath(getDirectoryPath(oldFile.path), targetFileName);
// no self-imports
if (sourceFile.fileName === pathToTargetFileWithExtension) return;
const pathToTargetFileWithExtension = resolvePath(getDirectoryPath(getNormalizedAbsolutePath(oldFile.fileName, program.getCurrentDirectory())), targetFileName);
// no self imports
if (getStringComparer(!program.useCaseSensitiveFileNames())(pathToTargetFileWithExtension, sourceFile.fileName) === Comparison.EqualTo) return;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@navya9singh we also need to replace usage of sourceFile.path in makeImportOrReqiure so its not using canonical path but actual file name:

 const pathToTargetFile = resolvePath(getDirectoryPath(sourceFile.path), targetFileNameWithExtension);

to

const pathToTargetFile = resolvePath(getDirectoryPath(getNormalizedAbsolutePath(sourceFile.fileName, program.getCurrentDirectory())), targetFileNameWithExtension);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made the changes

@navya9singh
Copy link
Member

Thanks for working on this! This pr also fixes #54309

@sheetalkamat sheetalkamat merged commit ede8ad8 into microsoft:main Mar 20, 2024
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect import destination after using Move to file

4 participants