diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index d3148d5ae60f5..db95fd1ae162c 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -228,7 +228,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. @@ -740,10 +740,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: diff --git a/tests/baselines/reference/goToDefinitionJsxCall.baseline.jsonc b/tests/baselines/reference/goToDefinitionJsxCall.baseline.jsonc new file mode 100644 index 0000000000000..15ed34c959492 --- /dev/null +++ b/tests/baselines/reference/goToDefinitionJsxCall.baseline.jsonc @@ -0,0 +1,29 @@ +// === goToDefinition === +// === /tests/cases/fourslash/test.tsx === +// interface FC
{ +// (props: P, context?: any): string; +// } +// +// <|const [|Thing|]: FC = (props) =>
;|> +// const HelloWorld = () =>{ +// (props: P, context?: any): string; +// } +// +// const Thing: FC = (props) =>
; +// const HelloWorld = () => *GOTO DEF*/[|Thing|] />; + + // === Details === + [ + { + "kind": "const", + "name": "Thing", + "containerName": "", + "isLocal": false, + "isAmbient": false, + "unverified": false, + "failedAliasResolution": false + } + ] \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionJsxCall.ts b/tests/cases/fourslash/goToDefinitionJsxCall.ts new file mode 100644 index 0000000000000..5a3ceae80f668 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionJsxCall.ts @@ -0,0 +1,11 @@ +///{ +//// (props: P, context?: any): string; +//// } +//// +//// const Thing: FC = (props) =>
; +//// const HelloWorld = () => <[|/**/Thing|] />; + +verify.baselineGoToDefinition("");