Skip to content

Commit be81535

Browse files
Final formatting and test validation
Applied proper code formatting and validated the fix works correctly. The change prevents debug assertion failure when moving React components or other symbols that don't have a parent but aren't modules. Co-authored-by: RyanCavanaugh <[email protected]>
1 parent 05666fc commit be81535

3 files changed

Lines changed: 32 additions & 51 deletions

File tree

src/services/refactors/helpers.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ export function addTargetFileImports(
7575
* 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).
7676
* So in that case, fall back to copying the import verbatim.
7777
*/
78-
importsToCopy.forEach(([isValidTypeOnlyUseSite, declaration], symbol) => {
79-
const targetSymbol = skipAlias(symbol, checker);
80-
if (checker.isUnknownSymbol(targetSymbol)) {
81-
importAdder.addVerbatimImport(Debug.checkDefined(declaration ?? findAncestor(symbol.declarations?.[0], isAnyImportOrRequireStatement)));
82-
}
83-
else if (targetSymbol.parent === undefined && (targetSymbol.flags & SymbolFlags.Module)) {
84-
Debug.assert(declaration !== undefined, "expected module symbol to have a declaration");
85-
importAdder.addImportForModuleSymbol(symbol, isValidTypeOnlyUseSite, declaration);
86-
}
87-
else {
88-
importAdder.addImportFromExportedSymbol(targetSymbol, isValidTypeOnlyUseSite, declaration);
89-
}
78+
importsToCopy.forEach(([isValidTypeOnlyUseSite, declaration], symbol) => {
79+
const targetSymbol = skipAlias(symbol, checker);
80+
if (checker.isUnknownSymbol(targetSymbol)) {
81+
importAdder.addVerbatimImport(Debug.checkDefined(declaration ?? findAncestor(symbol.declarations?.[0], isAnyImportOrRequireStatement)));
82+
}
83+
else if (targetSymbol.parent === undefined && (targetSymbol.flags & SymbolFlags.Module)) {
84+
Debug.assert(declaration !== undefined, "expected module symbol to have a declaration");
85+
importAdder.addImportForModuleSymbol(symbol, isValidTypeOnlyUseSite, declaration);
86+
}
87+
else {
88+
importAdder.addImportFromExportedSymbol(targetSymbol, isValidTypeOnlyUseSite, declaration);
89+
}
9090
});
9191

9292
addImportsForMovedSymbols(targetFileImportsFromOldFile, oldFile.fileName, importAdder, program);

tests/cases/fourslash/moveToNewFileReactComponent.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// Test for move to new file with symbols that don't have a parent but aren't modules
4+
// This reproduces the scenario that caused the debug assertion failure
5+
6+
// @Filename: /a.ts
7+
////export const someVar = 42;
8+
////[|export const anotherVar = 24;|]
9+
10+
verify.moveToNewFile({
11+
newFileContents: {
12+
"/a.ts":
13+
`export const someVar = 42;
14+
`,
15+
16+
"/anotherVar.ts":
17+
`export const anotherVar = 24;
18+
`,
19+
},
20+
});

0 commit comments

Comments
 (0)