fix(59116): Codefix add missing function declaration inserts function in wrong file (#59213)

This commit is contained in:
Oleksandr T. 2024-07-25 05:45:52 +03:00 committed by GitHub
parent f8336d1479
commit 7319968e90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -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);

View File

@ -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.");
}
};`,
}
});