Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript definitions + tests #2914

Merged
merged 3 commits into from
Nov 14, 2024
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
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
import { TYPESCRIPT_TEST_CASES } from "./testCases/typescript";
import { testRootPathContext } from "./testUtils";

const TEST_CASES = [
{
nodeType: "function_declaration",
fileName: "file1.ts",
language: "TypeScript",
cursorPosition: { line: 10, character: 24 },
definitionPositions: [
{ row: 9, column: 34 }, // Person
{ row: 9, column: 44 }, // Address
],
},
{
nodeType: "method_declaration",
fileName: "file1.ts",
language: "TypeScript",
cursorPosition: { line: 22, character: 30 },
definitionPositions: [
{ row: 13, column: 29 }, // BaseClass
{ row: 13, column: 55 }, // FirstInterface
{ row: 13, column: 72 }, // SecondInterface
{ row: 21, column: 33 }, // Person
{ row: 21, column: 43 }, // Address
],
},
...TYPESCRIPT_TEST_CASES,
{
nodeType: "function_definition",
fileName: "file1.py",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import {
// @ts-ignore
} from "./types";

function getAddress(person: Person): Address {
return person.address;
}

class Group extends BaseClass implements FirstInterface, SecondInterface {
people: Person[];

Expand All @@ -20,6 +16,18 @@ class Group extends BaseClass implements FirstInterface, SecondInterface {
}

getPersonAddress(person: Person): Address {
return getAddress(person);
return person.address;
}

getHardcodedAddress(): Address {
return { street: "123 Main St", city: "Anytown" };
}

addPerson(person: Person) {
this.people = [...this.people, person];
}

addPeople(people: Person[]) {
this.people = [...this.people, ...people];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
Address,
Person,
// @ts-ignore
} from "./types";

function getAddress(person: Person): Address {
return person.address;
}

function getFirstAddress(people: Person[]): Address {
return people[0].address;
}

function logPerson(person: Person) {
console.log(`Name: ${person.name}, Age: ${person.age}`);
}

function getHardcodedAddress(): Address {
return { street: "123 Main St", city: "Anytown", zipCode: "12345" };
}

function getAddresses(people: Person[]): Address[] {
return people[0].address;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
export const TYPESCRIPT_TEST_CASES = [
{
nodeType: "function_declaration with a param and a return type",
fileName: "functions.ts",
language: "TypeScript",
cursorPosition: { line: 7, character: 24 },
definitionPositions: [
{ row: 6, column: 34 }, // Person
{ row: 6, column: 44 }, // Address
],
},
{
nodeType: "function_declaration with array param",
fileName: "functions.ts",
language: "TypeScript",
cursorPosition: { line: 11, character: 27 },
definitionPositions: [
{ row: 10, column: 39 }, // Person
{ row: 10, column: 51 }, // Address
],
},
{
nodeType: "function_declaration without return type",
fileName: "functions.ts",
language: "TypeScript",
cursorPosition: { line: 15, character: 58 },
definitionPositions: [
{ row: 14, column: 33 }, // Person
],
},
{
nodeType: "function_declaration without params",
fileName: "functions.ts",
language: "TypeScript",
cursorPosition: { line: 19, character: 70 },
definitionPositions: [
{ row: 18, column: 39 }, // Person
],
},
{
nodeType: "method_declaration",
fileName: "class.ts",
language: "TypeScript",
cursorPosition: { line: 18, character: 26 },
definitionPositions: [
{ row: 9, column: 29 }, // BaseClass
{ row: 9, column: 55 }, // FirstInterface
{ row: 9, column: 72 }, // SecondInterface
{ row: 17, column: 33 }, // Person
{ row: 17, column: 43 }, // Address
],
},
{
nodeType: "method_declaration without arguments",
fileName: "class.ts",
language: "TypeScript",
cursorPosition: { line: 22, character: 54 },
definitionPositions: [
{ row: 9, column: 29 }, // BaseClass
{ row: 9, column: 55 }, // FirstInterface
{ row: 9, column: 72 }, // SecondInterface
{ row: 21, column: 32 }, // Address
],
},
{
nodeType: "method_declaration without return type",
fileName: "class.ts",
language: "TypeScript",
cursorPosition: { line: 26, character: 43 },
definitionPositions: [
{ row: 9, column: 29 }, // BaseClass
{ row: 9, column: 55 }, // FirstInterface
{ row: 9, column: 72 }, // SecondInterface
{ row: 25, column: 26 }, // Person
],
},
{
nodeType: "method_declaration with array type arguments",
fileName: "class.ts",
language: "TypeScript",
cursorPosition: { line: 30, character: 46 },
definitionPositions: [
{ row: 9, column: 29 }, // BaseClass
{ row: 9, column: 55 }, // FirstInterface
{ row: 9, column: 72 }, // SecondInterface
{ row: 29, column: 26 }, // Person
],
},
];
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
; Pattern for capturing the return type
(
(function_declaration
(formal_parameters
(_
(type_annotation) @param_type
)
(function_declaration
(type_annotation) @return_type
)
)

; Pattern for parameters with direct type_identifier
(
(function_declaration
(formal_parameters
(_
(type_annotation
(type_identifier) @param_type
)
)
)
)
)

; Pattern for parameters with one level of nesting
(
(function_declaration
(formal_parameters
(_
(type_annotation
(_
(type_identifier) @param_type
)
)
(type_annotation) @return_type
)
)
)
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
; Pattern for capturing the return type
(
(method_definition
(formal_parameters
(_
(type_annotation) @param_type
)
(method_definition
(type_annotation) @return_type
)
)

; Pattern for parameters with direct type_identifier
(
(method_definition
(formal_parameters
(_
(type_annotation
(type_identifier) @param_type
)
)
)
)
)

; Pattern for parameters with one level of nesting
(
(method_definition
(formal_parameters
(_
(type_annotation
(_
(type_identifier) @param_type
)
)
(type_annotation) @return_type
)
)
)
)
Loading