Skip to content

fix(50654): "Move to a new file" breaks the declaration of referenced variable - #50681

Merged
Nathan Shively-Sanders (sandersn) merged 2 commits into
microsoft:mainfrom
a-tarasyuk:fix/50654
Oct 26, 2022
Merged

fix(50654): "Move to a new file" breaks the declaration of referenced variable#50681
Nathan Shively-Sanders (sandersn) merged 2 commits into
microsoft:mainfrom
a-tarasyuk:fix/50654

Conversation

@a-tarasyuk

Copy link
Copy Markdown
Contributor

Fixes #50654

@typescript-bot TypeScript Bot (typescript-bot) added the For Backlog Bug PRs that fix a backlog bug label Sep 8, 2022

@iisaduan Isabel Duan (iisaduan) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When testing changes locally, the test cases do not work in .ts files though the behavior for "move to a new file" should be the same.

Edit: tested with import = syntax in TS, in which the "move to new file" action does work with this fix, but the action does not work with require, which is less surprising because it's not supported by TS

@iisaduan Isabel Duan (iisaduan) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes look good to me, though I'd like another pair of eyes on this Nathan Shively-Sanders (@sandersn)

const checker = program.getTypeChecker();
const prologueDirectives = takeWhile(oldFile.statements, isPrologueDirective);
if (!oldFile.externalModuleIndicator && !oldFile.commonJsModuleIndicator) {
if (oldFile.externalModuleIndicator === undefined && oldFile.commonJsModuleIndicator === undefined && usage.oldImportsNeededByNewFile.size() === 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just out of curiosity, is there any reason why the change from !oldFile.externalModuleIndicator to oldFile.externalModuleIndicator === undefined was necessary?

@sandersn
Nathan Shively-Sanders (sandersn) merged commit 8b1ecdb into microsoft:main Oct 26, 2022
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 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

Archived in project

Development

Successfully merging this pull request may close these issues.

"Move to a new file" breaks the declaration of referenced variable

6 participants