Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/services/goToDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
29 changes: 29 additions & 0 deletions tests/baselines/reference/goToDefinitionJsxCall.baseline.jsonc
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions tests/cases/fourslash/goToDefinitionJsxCall.ts
Original file line number Diff line number Diff line change
@@ -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("");