From e5f7b4ac23eef31599487f3b3dd3c76e26f2fa7d Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Tue, 26 Mar 2024 17:45:50 -0700 Subject: [PATCH 1/2] add test --- .../goToDefinitionJsxCall.baseline.jsonc | 40 +++++++++++++++++++ .../cases/fourslash/goToDefinitionJsxCall.ts | 11 +++++ 2 files changed, 51 insertions(+) create mode 100644 tests/baselines/reference/goToDefinitionJsxCall.baseline.jsonc create mode 100644 tests/cases/fourslash/goToDefinitionJsxCall.ts diff --git a/tests/baselines/reference/goToDefinitionJsxCall.baseline.jsonc b/tests/baselines/reference/goToDefinitionJsxCall.baseline.jsonc new file mode 100644 index 0000000000000..8d5f1c29ed0b6 --- /dev/null +++ b/tests/baselines/reference/goToDefinitionJsxCall.baseline.jsonc @@ -0,0 +1,40 @@ +// === goToDefinition === +// === /tests/cases/fourslash/test.tsx === +// interface FC

{ +// [|{| defId: 1 |}(props: P, context?: any): string;|] +// } +// +// <|const [|{| defId: 0 |}Thing|]: FC = (props) =>

;|> +// const HelloWorld = () => ; + +// === /tests/cases/fourslash/./test.tsx === +// interface FC

{ +// (props: P, context?: any): string; +// } +// +// const Thing: FC = (props) =>

; +// const HelloWorld = () => ; + + // === Details === + [ + { + "defId": 0, + "kind": "const", + "name": "Thing", + "containerName": "", + "isLocal": false, + "isAmbient": false, + "unverified": false, + "failedAliasResolution": false + }, + { + "defId": 1, + "kind": "index", + "name": "__call", + "containerName": "FC", + "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..6b2683ccde023 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionJsxCall.ts @@ -0,0 +1,11 @@ +/// + +// @filename: ./test.tsx +//// interface FC

{ +//// (props: P, context?: any): string; +//// } +//// +//// const Thing: FC = (props) =>

; +//// const HelloWorld = () => <[|/**/Thing|]/>; + +verify.baselineGoToDefinition(""); From 79c845195b859e09796440fbd00516137b619628 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Wed, 27 Mar 2024 14:20:15 -0700 Subject: [PATCH 2/2] skip callSignatures as a definition for jsx --- src/services/goToDefinition.ts | 5 +++-- .../goToDefinitionJsxCall.baseline.jsonc | 19 ++++--------------- .../cases/fourslash/goToDefinitionJsxCall.ts | 2 +- 3 files changed, 8 insertions(+), 18 deletions(-) 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 index 8d5f1c29ed0b6..15ed34c959492 100644 --- a/tests/baselines/reference/goToDefinitionJsxCall.baseline.jsonc +++ b/tests/baselines/reference/goToDefinitionJsxCall.baseline.jsonc @@ -1,11 +1,11 @@ // === goToDefinition === // === /tests/cases/fourslash/test.tsx === // interface FC

{ -// [|{| defId: 1 |}(props: P, context?: any): string;|] +// (props: P, context?: any): string; // } // -// <|const [|{| defId: 0 |}Thing|]: FC = (props) =>

;|> -// const HelloWorld = () => ; +// <|const [|Thing|]: FC = (props) =>
;|> +// const HelloWorld = () => ; // === /tests/cases/fourslash/./test.tsx === // interface FC

{ @@ -13,12 +13,11 @@ // } // // const Thing: FC = (props) =>

; -// const HelloWorld = () => ; +// const HelloWorld = () => ; // === Details === [ { - "defId": 0, "kind": "const", "name": "Thing", "containerName": "", @@ -26,15 +25,5 @@ "isAmbient": false, "unverified": false, "failedAliasResolution": false - }, - { - "defId": 1, - "kind": "index", - "name": "__call", - "containerName": "FC", - "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 index 6b2683ccde023..5a3ceae80f668 100644 --- a/tests/cases/fourslash/goToDefinitionJsxCall.ts +++ b/tests/cases/fourslash/goToDefinitionJsxCall.ts @@ -6,6 +6,6 @@ //// } //// //// const Thing: FC = (props) =>
; -//// const HelloWorld = () => <[|/**/Thing|]/>; +//// const HelloWorld = () => <[|/**/Thing|] />; verify.baselineGoToDefinition("");