From 187979af2b16e1f8720b84a7bf8526db73a6300c Mon Sep 17 00:00:00 2001 From: KJ7LNW <93454819+KJ7LNW@users.noreply.github.com> Date: Mon, 24 Mar 2025 10:32:18 -0700 Subject: [PATCH] feat: add test declarations support in typescript tree-sitter queries (#1899) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add parsing support for: - Jest describe/test/it blocks - npm test exports This enables proper identification of test definitions in TypeScript files: ``` // File: multi-search-replace.test.ts (192 definitions) │| 2 - 1565 ||describe("MultiSearchReplaceDiffStrategy", () => { │| 3 - 632 || describe("exact matching", () => { │| 10 - 28 || it("should replace matching content", async () => { || ||---- │| 30 - 48 || it("should match content with different surrounding whitespace", async () => { || ||---- │| 50 - 68 || it("should match content with different indentation in search block", async () => { || ||---- │| 70 - 88 || it("should handle tab-based indentation", async () => { || ||---- ``` Signed-off-by: Eric Wheeler Co-authored-by: Eric Wheeler --- src/services/tree-sitter/queries/typescript.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/services/tree-sitter/queries/typescript.ts b/src/services/tree-sitter/queries/typescript.ts index b30c10e915..3db50f7f84 100644 --- a/src/services/tree-sitter/queries/typescript.ts +++ b/src/services/tree-sitter/queries/typescript.ts @@ -29,4 +29,19 @@ export default ` (class_declaration name: (type_identifier) @name.definition.class) @definition.class + +(call_expression + function: (identifier) @func_name + arguments: (arguments + (string) @name + [(arrow_function) (function_expression)]) @definition.test) + (#match? @func_name "^(describe|test|it)$") + +(assignment_expression + left: (member_expression + object: (identifier) @obj + property: (property_identifier) @prop) + right: [(arrow_function) (function_expression)]) @definition.test + (#eq? @obj "exports") + (#eq? @prop "test") `