mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 10:46:28 -05:00
fix37816: goToDefinition skips call signatures for jsx components (#57969)
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
}
|
||||
]
|
||||
11
tests/cases/fourslash/goToDefinitionJsxCall.ts
Normal file
11
tests/cases/fourslash/goToDefinitionJsxCall.ts
Normal 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("");
|
||||
Reference in New Issue
Block a user