Skip to content

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
@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.

DanielRosenwasser pushed a commit that referenced this pull request Jun 19, 2024
@sandersn sandersn removed this from PR Backlog Apr 22, 2025
@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 Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion violation in "move to new file" "Move to file" on global code unnecessarily imports/exports, generates invalid code

5 participants