Skip to content

Commit b183418

Browse files
author
Andy
authored
Fix bug: Don't go to *any* constructor signature for jsx element (#26715)
1 parent 1b5de9d commit b183418

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/services/goToDefinition.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace ts.GoToDefinition {
2929

3030
const calledDeclaration = tryGetSignatureDeclaration(typeChecker, node);
3131
// Don't go to the component constructor definition for a JSX element, just go to the component definition.
32-
if (calledDeclaration && !(isJsxOpeningLikeElement(node.parent) && isConstructorDeclaration(calledDeclaration))) {
32+
if (calledDeclaration && !(isJsxOpeningLikeElement(node.parent) && isConstructorLike(calledDeclaration))) {
3333
const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
3434
// For a function, if this is the original function definition, return just sigInfo.
3535
// If this is the original constructor definition, parent is the class.
@@ -319,4 +319,15 @@ namespace ts.GoToDefinition {
319319
// Don't go to a function type, go to the value having that type.
320320
return tryCast(signature && signature.declaration, (d): d is SignatureDeclaration => isFunctionLike(d) && !isFunctionTypeNode(d));
321321
}
322+
323+
function isConstructorLike(node: Node): boolean {
324+
switch (node.kind) {
325+
case SyntaxKind.Constructor:
326+
case SyntaxKind.ConstructorType:
327+
case SyntaxKind.ConstructSignature:
328+
return true;
329+
default:
330+
return false;
331+
}
332+
}
322333
}

tests/cases/fourslash/goToDefinitionSignatureAlias.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@
2121
////o.[|/*useM*/m|]();
2222

2323
////class Component { /*componentCtr*/constructor(props: {}) {} }
24+
////type ComponentClass = /*ComponentClass*/new () => Component;
25+
////interface ComponentClass2 { /*ComponentClass2*/new(): Component; }
26+
////
2427
////class /*MyComponent*/MyComponent extends Component {}
25-
////<[|/*jsxMyComponent*/MyComponent|] />
28+
////<[|/*jsxMyComponent*/MyComponent|] />;
2629
////new [|/*newMyComponent*/MyComponent|]({});
30+
////
31+
////declare const /*MyComponent2*/MyComponent2: ComponentClass;
32+
////<[|/*jsxMyComponent2*/MyComponent2|] />;
33+
////new [|/*newMyComponent2*/MyComponent2|]();
34+
////
35+
////declare const /*MyComponent3*/MyComponent3: ComponentClass2;
36+
////<[|/*jsxMyComponent3*/MyComponent3|] />;
37+
////new [|/*newMyComponent3*/MyComponent3|]();
2738

2839
verify.noErrors();
2940

@@ -38,4 +49,10 @@ verify.goToDefinition({
3849

3950
jsxMyComponent: "MyComponent",
4051
newMyComponent: ["MyComponent", "componentCtr"],
52+
53+
jsxMyComponent2: "MyComponent2",
54+
newMyComponent2: ["MyComponent2", "ComponentClass"],
55+
56+
jsxMyComponent3: "MyComponent3",
57+
newMyComponent3: ["MyComponent3", "ComponentClass2"],
4158
});

0 commit comments

Comments
 (0)