mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-13 09:12:52 -05:00
Revert code changes and create test case that triggers original assertion
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
This commit is contained in:
@@ -75,18 +75,24 @@ 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) {
|
||||
if (targetSymbol.flags & SymbolFlags.Module) {
|
||||
Debug.assert(declaration !== undefined, "expected module symbol to have a declaration");
|
||||
importAdder.addImportForModuleSymbol(symbol, isValidTypeOnlyUseSite, declaration);
|
||||
}
|
||||
else {
|
||||
// For symbols without a parent that aren't modules, fall back to verbatim import
|
||||
importAdder.addVerbatimImport(Debug.checkDefined(declaration ?? findAncestor(symbol.declarations?.[0], isAnyImportOrRequireStatement)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
importAdder.addImportFromExportedSymbol(targetSymbol, isValidTypeOnlyUseSite, declaration);
|
||||
}
|
||||
});
|
||||
|
||||
addImportsForMovedSymbols(targetFileImportsFromOldFile, oldFile.fileName, importAdder, program);
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
/// <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
|
||||
// Test for the debug assertion failure with symbols exported separately from declaration
|
||||
// This reproduces the issue reported in #62029
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export const someVar = 42;
|
||||
////[|export const anotherVar = 24;|]
|
||||
// @Filename: /bar.ts
|
||||
////class Bar {}
|
||||
////
|
||||
////export default Bar;
|
||||
|
||||
verify.moveToNewFile({
|
||||
newFileContents: {
|
||||
"/a.ts":
|
||||
`export const someVar = 42;
|
||||
`,
|
||||
// @Filename: /foo.ts
|
||||
////import Bar from './bar';
|
||||
////
|
||||
////[|function makeBar() {
|
||||
//// return new Bar();
|
||||
////}|]
|
||||
|
||||
"/anotherVar.ts":
|
||||
`export const anotherVar = 24;
|
||||
`,
|
||||
},
|
||||
});
|
||||
// Check that the refactor is available
|
||||
verify.applicableRefactorAvailableAtMarker("Move to a new file");
|
||||
Reference in New Issue
Block a user