mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-15 03:09:59 -05:00
Fix move to file refactor issue with React components
Added proper check for SymbolFlags.Module before calling addImportForModuleSymbol to prevent debug assertion failure when moving non-module symbols like React components. Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
This commit is contained in:
@@ -75,18 +75,18 @@ export function addTargetFileImports(
|
||||
* but sometimes it fails because of unresolved imports from files, or when a source file is not available for the target file (in this case when creating a new file).
|
||||
* So in that case, fall back to copying the import verbatim.
|
||||
*/
|
||||
importsToCopy.forEach(([isValidTypeOnlyUseSite, declaration], symbol) => {
|
||||
const targetSymbol = skipAlias(symbol, checker);
|
||||
if (checker.isUnknownSymbol(targetSymbol)) {
|
||||
importAdder.addVerbatimImport(Debug.checkDefined(declaration ?? findAncestor(symbol.declarations?.[0], isAnyImportOrRequireStatement)));
|
||||
}
|
||||
else if (targetSymbol.parent === undefined) {
|
||||
Debug.assert(declaration !== undefined, "expected module symbol to have a declaration");
|
||||
importAdder.addImportForModuleSymbol(symbol, isValidTypeOnlyUseSite, declaration);
|
||||
}
|
||||
else {
|
||||
importAdder.addImportFromExportedSymbol(targetSymbol, isValidTypeOnlyUseSite, declaration);
|
||||
}
|
||||
importsToCopy.forEach(([isValidTypeOnlyUseSite, declaration], symbol) => {
|
||||
const targetSymbol = skipAlias(symbol, checker);
|
||||
if (checker.isUnknownSymbol(targetSymbol)) {
|
||||
importAdder.addVerbatimImport(Debug.checkDefined(declaration ?? findAncestor(symbol.declarations?.[0], isAnyImportOrRequireStatement)));
|
||||
}
|
||||
else if (targetSymbol.parent === undefined && (targetSymbol.flags & SymbolFlags.Module)) {
|
||||
Debug.assert(declaration !== undefined, "expected module symbol to have a declaration");
|
||||
importAdder.addImportForModuleSymbol(symbol, isValidTypeOnlyUseSite, declaration);
|
||||
}
|
||||
else {
|
||||
importAdder.addImportFromExportedSymbol(targetSymbol, isValidTypeOnlyUseSite, declaration);
|
||||
}
|
||||
});
|
||||
|
||||
addImportsForMovedSymbols(targetFileImportsFromOldFile, oldFile.fileName, importAdder, program);
|
||||
|
||||
Reference in New Issue
Block a user