goToDefinition: Don't go to jsx constructor signature (#25382)

This commit is contained in:
Andy 2018-07-02 17:18:07 -07:00 committed by GitHub
parent 18d8ad120c
commit 5c57e14000
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View file

@ -28,7 +28,8 @@ namespace ts.GoToDefinition {
}
const calledDeclaration = tryGetSignatureDeclaration(typeChecker, node);
if (calledDeclaration) {
// Don't go to the component constructor definition for a JSX element, just go to the component definition.
if (calledDeclaration && !(isJsxOpeningLikeElement(node.parent) && isConstructorDeclaration(calledDeclaration))) {
const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
// For a function, if this is the original function definition, return just sigInfo.
// If this is the original constructor definition, parent is the class.

View file

@ -1,5 +1,8 @@
/// <reference path='fourslash.ts'/>
// @jsx: preserve
// @Filename: /a.tsx
////function /*f*/f() {}
////const /*g*/g = f;
////const /*h*/h = g;
@ -17,6 +20,13 @@
////const o = { m: /*m*/() => 0 };
////o.[|/*useM*/m|]();
////class Component { /*componentCtr*/constructor(props: {}) {} }
////class /*MyComponent*/MyComponent extends Component {}
////<[|/*jsxMyComponent*/MyComponent|] />
////new [|/*newMyComponent*/MyComponent|]({});
verify.noErrors();
verify.goToDefinition({
useF: "f",
useG: ["g", "f"],
@ -25,4 +35,7 @@ verify.goToDefinition({
useI: "i",
useJ: ["j", "i"],
useM: "m",
jsxMyComponent: "MyComponent",
newMyComponent: ["MyComponent", "componentCtr"],
});

View file

@ -27,7 +27,7 @@
//// let opt = <[|Main/*secondTarget*/Button|] children="chidlren" />;
//// let opt = <[|Main/*thirdTarget*/Button|] onClick={()=>{}} />;
//// let opt = <[|Main/*fourthTarget*/Button|] onClick={()=>{}} ignore-prop />;
//// let opt = <[|Main/*fivethTarget*/Button|] goTo="goTo" />;
//// let opt = <[|Main/*fifthTarget*/Button|] goTo="goTo" />;
//// let opt = <[|Main/*sixthTarget*/Button|] wrong />;
verify.goToDefinition({
@ -35,6 +35,6 @@ verify.goToDefinition({
secondTarget: "thirdSource",
thirdTarget: "firstSource",
fourthTarget: "firstSource",
fivethTarget: "secondSource",
fifthTarget: "secondSource",
sixthTarget: "thirdSource"
});