-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fixed crashes when moving namespace imports to other files in refactorings #60302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ export const enum ExportKind { | |
Named, | ||
Default, | ||
ExportEquals, | ||
Module, | ||
UMD, | ||
} | ||
|
||
|
@@ -557,6 +558,18 @@ export function getExportInfoMap(importingFile: SourceFile | FutureSourceFile, h | |
if (++moduleCount % 100 === 0) cancellationToken?.throwIfCancellationRequested(); | ||
const seenExports = new Set<__String>(); | ||
const checker = program.getTypeChecker(); | ||
if (isImportableSymbol(moduleSymbol, checker)) { | ||
cache.add( | ||
importingFile.path, | ||
moduleSymbol, | ||
moduleSymbol.escapedName, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect this might be somewhat questionable solution here, I'm not fully sold on it myself either. cc @andrewbranch - you might have some opinions here (or suggestions for an improved fix? :P) |
||
moduleSymbol, | ||
moduleFile, | ||
ExportKind.Module, | ||
isFromPackageJson, | ||
checker, | ||
); | ||
} | ||
const defaultInfo = getDefaultLikeExportInfo(moduleSymbol, checker); | ||
// Note: I think we shouldn't actually see resolved module symbols here, but weird merges | ||
// can cause it to happen: see 'completionsImport_mergedReExport.ts' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: /a.ts | ||
//// export type ExecutionPoint = string; | ||
//// | ||
// @Filename: /b.ts | ||
//// import * as A from "./a"; | ||
//// | ||
//// [|async function pointToFrameExecutionPoint(point: A.ExecutionPoint) {}|] | ||
//// | ||
// @Filename: /point.ts | ||
//// | ||
|
||
verify.moveToFile({ | ||
newFileContents: { | ||
"/b.ts": ` | ||
`, | ||
"/point.ts": | ||
`import * as A from "./a"; | ||
|
||
|
||
async function pointToFrameExecutionPoint(point: A.ExecutionPoint) { } | ||
`, | ||
}, | ||
interactiveRefactorArguments: { targetFile: "/point.ts" }, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: /a.ts | ||
//// export type ExecutionPoint = string; | ||
//// | ||
// @Filename: /b.ts | ||
//// import * as P from "./a"; | ||
//// | ||
//// [|async function fn(point: typeof P) {}|] | ||
//// | ||
// @Filename: /c.ts | ||
//// | ||
|
||
verify.moveToFile({ | ||
newFileContents: { | ||
"/b.ts": ` | ||
`, | ||
"/c.ts": | ||
`import * as P from "./a"; | ||
|
||
|
||
async function fn(point: typeof P) { } | ||
`, | ||
}, | ||
interactiveRefactorArguments: { targetFile: "/c.ts" }, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: /a.ts | ||
//// export type ExecutionPoint = string; | ||
//// | ||
// @Filename: /b.ts | ||
//// import * as A from "./a"; | ||
//// | ||
//// [|async function fn1(point: A.ExecutionPoint) {}|] | ||
//// | ||
//// async function fn2(point: A.ExecutionPoint) {} | ||
//// | ||
// @Filename: /point.ts | ||
//// | ||
|
||
verify.moveToFile({ | ||
newFileContents: { | ||
"/b.ts": `import * as A from "./a"; | ||
|
||
async function fn2(point: A.ExecutionPoint) {} | ||
`, | ||
"/point.ts": | ||
`import * as A from "./a"; | ||
|
||
|
||
async function fn1(point: A.ExecutionPoint) { } | ||
`, | ||
}, | ||
interactiveRefactorArguments: { targetFile: "/point.ts" }, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: /a.ts | ||
//// export type ExecutionPoint = string; | ||
//// | ||
// @Filename: /b.ts | ||
//// import * as A from "./a"; | ||
//// | ||
//// [|async function fn1(point: A.ExecutionPoint) {}|] | ||
//// | ||
// @Filename: /point.ts | ||
//// import { ExecutionPoint } from "./a"; | ||
//// | ||
//// async function fn2(point: ExecutionPoint) {} | ||
|
||
verify.moveToFile({ | ||
newFileContents: { | ||
"/b.ts": ` | ||
`, | ||
"/point.ts": | ||
`import * as A from "./a"; | ||
import { ExecutionPoint } from "./a"; | ||
|
||
async function fn2(point: ExecutionPoint) {} | ||
async function fn1(point: A.ExecutionPoint) { } | ||
`, | ||
}, | ||
interactiveRefactorArguments: { targetFile: "/point.ts" }, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: /a.ts | ||
//// export type ExecutionPoint = string; | ||
//// | ||
// @Filename: /b.ts | ||
//// export type ExecutionPoint = { point: string }; | ||
//// | ||
// @Filename: /c.ts | ||
//// import * as A from "./a"; | ||
//// | ||
//// [|async function fn1(point: A.ExecutionPoint) {}|] | ||
//// | ||
// @Filename: /point.ts | ||
//// import * as A from "./c"; | ||
//// | ||
//// async function fn2(point: A.ExecutionPoint) {} | ||
|
||
verify.moveToFile({ | ||
newFileContents: { | ||
"/c.ts": ` | ||
`, | ||
"/point.ts": | ||
`import * as A from "./a"; | ||
import * as A from "./c"; | ||
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we can see here, those refactorings introduce issues into target files. This is not a new problem from what I can tell. This refactoring just never tried to rename inserted symbols to avoid name clashes etc. At first, I thought those would be test cases that should be covered by this PR so I added them. I could just remove them now but I think they still have some value here, especially if this naming conflict is ever meant to be addressed in the future. |
||
|
||
async function fn2(point: A.ExecutionPoint) {} | ||
async function fn1(point: A.ExecutionPoint) { } | ||
`, | ||
}, | ||
interactiveRefactorArguments: { targetFile: "/point.ts" }, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: /a.ts | ||
//// export type ExecutionPoint = string; | ||
//// | ||
// @Filename: /b.ts | ||
//// import * as A from "./a"; | ||
//// | ||
//// [|async function fn1(point: A.ExecutionPoint) {}|] | ||
//// | ||
// @Filename: /point.ts | ||
//// import * as A from "./a"; | ||
//// | ||
//// async function fn2(point: A.ExecutionPoint) {} | ||
|
||
verify.moveToFile({ | ||
newFileContents: { | ||
"/b.ts": ` | ||
`, | ||
"/point.ts": | ||
`import * as A from "./a"; | ||
import * as A from "./a"; | ||
|
||
async function fn2(point: A.ExecutionPoint) {} | ||
async function fn1(point: A.ExecutionPoint) { } | ||
`, | ||
}, | ||
interactiveRefactorArguments: { targetFile: "/point.ts" }, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: /a.ts | ||
//// export type ExecutionPoint = string; | ||
//// | ||
// @Filename: /b.ts | ||
//// import * as A from "./a"; | ||
//// | ||
//// [|async function fn1(point: A.ExecutionPoint) {}|] | ||
//// | ||
// @Filename: /point.ts | ||
//// import * as A1 from "./a"; | ||
//// | ||
//// async function fn2(point: A1.ExecutionPoint) {} | ||
|
||
verify.moveToFile({ | ||
newFileContents: { | ||
"/b.ts": ` | ||
`, | ||
"/point.ts": | ||
`import * as A from "./a"; | ||
import * as A1 from "./a"; | ||
|
||
async function fn2(point: A1.ExecutionPoint) {} | ||
async function fn1(point: A.ExecutionPoint) { } | ||
`, | ||
}, | ||
interactiveRefactorArguments: { targetFile: "/point.ts" }, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: /a.ts | ||
//// export type ExecutionPoint = string; | ||
//// | ||
// @Filename: /b.ts | ||
//// import * as A from "./a"; | ||
//// | ||
//// [|async function fn1(point: A.ExecutionPoint) {}|] | ||
//// | ||
// @Filename: /point.ts | ||
//// type A = {}; | ||
//// export {}; | ||
|
||
verify.moveToFile({ | ||
newFileContents: { | ||
"/b.ts": ` | ||
`, | ||
"/point.ts": | ||
`import * as A from "./a"; | ||
|
||
type A = {}; | ||
export {}; | ||
async function fn1(point: A.ExecutionPoint) { } | ||
`, | ||
}, | ||
interactiveRefactorArguments: { targetFile: "/point.ts" }, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: /a.ts | ||
//// export type ExecutionPoint = string; | ||
//// | ||
// @Filename: /b.ts | ||
//// import * as A from "./a"; | ||
//// | ||
//// [|async function pointToFrameExecutionPoint(point: A.ExecutionPoint) {}|] | ||
//// | ||
|
||
verify.moveToNewFile({ | ||
newFileContents: { | ||
"/b.ts": ` | ||
`, | ||
"/pointToFrameExecutionPoint.ts": | ||
`import * as A from "./a"; | ||
|
||
|
||
async function pointToFrameExecutionPoint(point: A.ExecutionPoint) { } | ||
`, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// <reference path='fourslash.ts' /> | ||
|
||
// @Filename: /a.ts | ||
//// export type ExecutionPoint = string; | ||
//// | ||
// @Filename: /b.ts | ||
//// import * as A from "./a"; | ||
//// | ||
//// [|async function fn(a: typeof A) {}|] | ||
//// | ||
|
||
verify.moveToNewFile({ | ||
newFileContents: { | ||
"/b.ts": | ||
` | ||
`, | ||
"/fn.ts": | ||
`import * as A from "./a"; | ||
|
||
|
||
async function fn(a: typeof A) { } | ||
`, | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the crash is happening here today because the external module symbol doesn't have a
.parent