From be815350362f56d483a1d00534710f7101b2a8a7 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 14 Jul 2025 18:47:47 +0000
Subject: [PATCH] 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 <6685088+RyanCavanaugh@users.noreply.github.com>
---
src/services/refactors/helpers.ts | 24 ++++++------
.../fourslash/moveToNewFileReactComponent.ts | 39 -------------------
.../moveToNewFileSymbolWithoutParent.ts | 20 ++++++++++
3 files changed, 32 insertions(+), 51 deletions(-)
delete mode 100644 tests/cases/fourslash/moveToNewFileReactComponent.ts
create mode 100644 tests/cases/fourslash/moveToNewFileSymbolWithoutParent.ts
diff --git a/src/services/refactors/helpers.ts b/src/services/refactors/helpers.ts
index 8fc99f2794e..71885488c63 100644
--- a/src/services/refactors/helpers.ts
+++ b/src/services/refactors/helpers.ts
@@ -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 && (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);
- }
+ 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);
diff --git a/tests/cases/fourslash/moveToNewFileReactComponent.ts b/tests/cases/fourslash/moveToNewFileReactComponent.ts
deleted file mode 100644
index d57027447d2..00000000000
--- a/tests/cases/fourslash/moveToNewFileReactComponent.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-///