fix37816: goToDefinition skips call signatures for jsx components (#57969)

This commit is contained in:
Isabel Duan
2024-05-10 13:45:45 -07:00
committed by GitHub
parent 9f9682c0a0
commit 0c1b36fb65
3 changed files with 43 additions and 2 deletions

View File

@@ -225,7 +225,7 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
const calledDeclaration = tryGetSignatureDeclaration(typeChecker, node);
// Don't go to the component constructor definition for a JSX element, just go to the component definition.
if (calledDeclaration && !(isJsxOpeningLikeElement(node.parent) && isConstructorLike(calledDeclaration))) {
if (calledDeclaration && !(isJsxOpeningLikeElement(node.parent) && isJsxConstructorLike(calledDeclaration))) {
const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration, failedAliasResolution);
// For a function, if this is the original function definition, return just sigInfo.
// If this is the original constructor definition, parent is the class.
@@ -741,10 +741,11 @@ function tryGetSignatureDeclaration(typeChecker: TypeChecker, node: Node): Signa
return tryCast(signature && signature.declaration, (d): d is SignatureDeclaration => isFunctionLike(d) && !isFunctionTypeNode(d));
}
function isConstructorLike(node: Node): boolean {
function isJsxConstructorLike(node: Node): boolean {
switch (node.kind) {
case SyntaxKind.Constructor:
case SyntaxKind.ConstructorType:
case SyntaxKind.CallSignature:
case SyntaxKind.ConstructSignature:
return true;
default:

View File

@@ -0,0 +1,29 @@
// === goToDefinition ===
// === /tests/cases/fourslash/test.tsx ===
// interface FC<P = {}> {
// (props: P, context?: any): string;
// }
//
// <|const [|Thing|]: FC = (props) => <div></div>;|>
// const HelloWorld = () => <Thing />;
// === /tests/cases/fourslash/./test.tsx ===
// interface FC<P = {}> {
// (props: P, context?: any): string;
// }
//
// const Thing: FC = (props) => <div></div>;
// const HelloWorld = () => </*GOTO DEF*/[|Thing|] />;
// === Details ===
[
{
"kind": "const",
"name": "Thing",
"containerName": "",
"isLocal": false,
"isAmbient": false,
"unverified": false,
"failedAliasResolution": false
}
]

View File

@@ -0,0 +1,11 @@
/// <reference path='fourslash.ts' />
// @filename: ./test.tsx
//// interface FC<P = {}> {
//// (props: P, context?: any): string;
//// }
////
//// const Thing: FC = (props) => <div></div>;
//// const HelloWorld = () => <[|/**/Thing|] />;
verify.baselineGoToDefinition("");