Skip to content

Commit 5c57e14

Browse files
author
Andy
authored
goToDefinition: Don't go to jsx constructor signature (#25382)
1 parent 18d8ad1 commit 5c57e14

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/services/goToDefinition.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ namespace ts.GoToDefinition {
2828
}
2929

3030
const calledDeclaration = tryGetSignatureDeclaration(typeChecker, node);
31-
if (calledDeclaration) {
31+
// 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))) {
3233
const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
3334
// For a function, if this is the original function definition, return just sigInfo.
3435
// If this is the original constructor definition, parent is the class.

tests/cases/fourslash/goToDefinitionSignatureAlias.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/// <reference path='fourslash.ts'/>
22

3+
// @jsx: preserve
4+
5+
// @Filename: /a.tsx
36
////function /*f*/f() {}
47
////const /*g*/g = f;
58
////const /*h*/h = g;
@@ -17,6 +20,13 @@
1720
////const o = { m: /*m*/() => 0 };
1821
////o.[|/*useM*/m|]();
1922

23+
////class Component { /*componentCtr*/constructor(props: {}) {} }
24+
////class /*MyComponent*/MyComponent extends Component {}
25+
////<[|/*jsxMyComponent*/MyComponent|] />
26+
////new [|/*newMyComponent*/MyComponent|]({});
27+
28+
verify.noErrors();
29+
2030
verify.goToDefinition({
2131
useF: "f",
2232
useG: ["g", "f"],
@@ -25,4 +35,7 @@ verify.goToDefinition({
2535
useI: "i",
2636
useJ: ["j", "i"],
2737
useM: "m",
38+
39+
jsxMyComponent: "MyComponent",
40+
newMyComponent: ["MyComponent", "componentCtr"],
2841
});

tests/cases/fourslash/tsxGoToDefinitionStatelessFunction2.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
//// let opt = <[|Main/*secondTarget*/Button|] children="chidlren" />;
2828
//// let opt = <[|Main/*thirdTarget*/Button|] onClick={()=>{}} />;
2929
//// let opt = <[|Main/*fourthTarget*/Button|] onClick={()=>{}} ignore-prop />;
30-
//// let opt = <[|Main/*fivethTarget*/Button|] goTo="goTo" />;
30+
//// let opt = <[|Main/*fifthTarget*/Button|] goTo="goTo" />;
3131
//// let opt = <[|Main/*sixthTarget*/Button|] wrong />;
3232

3333
verify.goToDefinition({
3434
firstTarget: "thirdSource",
3535
secondTarget: "thirdSource",
3636
thirdTarget: "firstSource",
3737
fourthTarget: "firstSource",
38-
fivethTarget: "secondSource",
38+
fifthTarget: "secondSource",
3939
sixthTarget: "thirdSource"
4040
});

0 commit comments

Comments
 (0)