Skip to content

Fix debug assertion failure in move to file refactor for React components #62067

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
9 changes: 8 additions & 1 deletion src/services/refactors/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ export function addTargetFileImports(
}
else if (targetSymbol.parent === undefined) {
Debug.assert(declaration !== undefined, "expected module symbol to have a declaration");
importAdder.addImportForModuleSymbol(symbol, isValidTypeOnlyUseSite, declaration);
const aliasedSymbol = checker.getAliasedSymbol(symbol);
if (aliasedSymbol.flags & SymbolFlags.Module) {
importAdder.addImportForModuleSymbol(symbol, isValidTypeOnlyUseSite, declaration);
}
else {
// If the aliased symbol is not a module, fall back to verbatim import
importAdder.addVerbatimImport(Debug.checkDefined(declaration ?? findAncestor(symbol.declarations?.[0], isAnyImportOrRequireStatement)));
}
}
else {
importAdder.addImportFromExportedSymbol(targetSymbol, isValidTypeOnlyUseSite, declaration);
Expand Down