Skip to content
2 changes: 1 addition & 1 deletion src/services/refactors/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function addTargetFileImports(
if (checker.isUnknownSymbol(targetSymbol)) {
importAdder.addVerbatimImport(Debug.checkDefined(declaration ?? findAncestor(symbol.declarations?.[0], isAnyImportOrRequireStatement)));
}
else if (targetSymbol.parent === undefined) {
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);
}
Expand Down
20 changes: 20 additions & 0 deletions tests/cases/fourslash/moveToNewFileSymbolWithoutParent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path='fourslash.ts'/>

// Test for move to new file with symbols that don't have a parent but aren't modules
// This reproduces the scenario that caused the debug assertion failure

// @Filename: /a.ts
////export const someVar = 42;
////[|export const anotherVar = 24;|]

verify.moveToNewFile({
newFileContents: {
"/a.ts":
`export const someVar = 42;
`,

"/anotherVar.ts":
`export const anotherVar = 24;
`,
},
});
Loading