-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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(57451): Prevent self-imports when using the "Move to File" refactor #57530
Conversation
@microsoft-github-policy-service agree |
src/services/refactors/moveToFile.ts
Outdated
const pathToTargetFileWithExtension = resolvePath(getDirectoryPath(oldFile.path), targetFileName); | ||
|
||
// no self-imports | ||
if (sourceFile.fileName === pathToTargetFileWithExtension) return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made the changes
Thanks for working on this! This pr also fixes #54309 |
Fixes #57451