mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
fix(59116): Codefix add missing function declaration inserts function in wrong file (#59213)
This commit is contained in:
parent
f8336d1479
commit
7319968e90
@ -369,7 +369,7 @@ function getInfo(sourceFile: SourceFile, tokenPos: number, errorCode: number, ch
|
||||
const moduleDeclaration = find(symbol.declarations, isModuleDeclaration);
|
||||
const moduleDeclarationSourceFile = moduleDeclaration?.getSourceFile();
|
||||
if (moduleDeclaration && moduleDeclarationSourceFile && !isSourceFileFromLibrary(program, moduleDeclarationSourceFile)) {
|
||||
return { kind: InfoKind.Function, token, call: parent.parent, sourceFile, modifierFlags: ModifierFlags.Export, parentDeclaration: moduleDeclaration };
|
||||
return { kind: InfoKind.Function, token, call: parent.parent, sourceFile: moduleDeclarationSourceFile, modifierFlags: ModifierFlags.Export, parentDeclaration: moduleDeclaration };
|
||||
}
|
||||
|
||||
const moduleSourceFile = find(symbol.declarations, isSourceFile);
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @filename: /a.ts
|
||||
////export namespace A {
|
||||
//// export function test() {}
|
||||
////};
|
||||
|
||||
// @filename: /b.ts
|
||||
////import { A } from "./a";
|
||||
////
|
||||
////A.fn();
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.codeFix({
|
||||
description: [ts.Diagnostics.Add_missing_function_declaration_0.message, "fn"],
|
||||
index: 0,
|
||||
newFileContent: {
|
||||
"/a.ts":
|
||||
`export namespace A {
|
||||
export function test() {}
|
||||
|
||||
export function fn() {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
};`,
|
||||
}
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user