Skip to content

fix(58801): "Move to file" on global code unnecessarily imports/exports, generates invalid code #58811

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

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

a-tarasyuk
Copy link
Contributor

@a-tarasyuk a-tarasyuk commented Jun 9, 2024

Fixes #58801
Fixes #58806

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jun 9, 2024
Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

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

This looks right, though it seems like it doesn’t explain the export export export export export export function bug 😄 Was there any clue about why that happened as you were debugging?

@a-tarasyuk
Copy link
Contributor Author

@andrewbranch The moveToFile refactoring adds the same symbol to each declaration...

targetFileImportsFromOldFile.set(symbol, isValidTypeOnlyUseSite);

for (const decl of symbol.declarations) {
if (isInImport(decl)) {
const prevIsTypeOnly = oldImportsNeededByTargetFile.get(symbol);
oldImportsNeededByTargetFile.set(symbol, [
prevIsTypeOnly === undefined ? isValidTypeOnlyUseSite : prevIsTypeOnly && isValidTypeOnlyUseSite,
tryCast(decl, (d): d is codefix.ImportOrRequireAliasDeclaration => isImportSpecifier(d) || isImportClause(d) || isNamespaceImport(d) || isImportEqualsDeclaration(d) || isBindingElement(d) || isVariableDeclaration(d)),
]);
}
else if (isTopLevelDeclaration(decl) && sourceFileOfTopLevelDeclaration(decl) === oldFile && !movedSymbols.has(symbol)) {
targetFileImportsFromOldFile.set(symbol, isValidTypeOnlyUseSite);
}
}

@a-tarasyuk
Copy link
Contributor Author

It looks like these changes fix the crash mentioned in #58806., the moveToNewFile_global3.ts test covers this case.

@andrewbranch
Copy link
Member

Good to merge as soon as @navya9singh signs off!

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

I think I'm good with this, and I'd like to get it in for 5.5.2.

@DanielRosenwasser DanielRosenwasser merged commit e8fca15 into microsoft:main Jun 19, 2024
28 checks passed
@DanielRosenwasser
Copy link
Member

@typescript-bot cherry-pick this to release-5.5 and LKG

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 19, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
cherry-pick this to release-5.5 and LKG ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

Hey, @DanielRosenwasser! I've created #58923 for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
5 participants