Просмотр исходного кода

feat: add test declarations support in typescript tree-sitter queries (#1899)

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 <[email protected]>
Co-authored-by: Eric Wheeler <[email protected]>
KJ7LNW 9 месяцев назад
Родитель
Сommit
187979af2b
1 измененных файлов с 15 добавлено и 0 удалено
  1. 15 0
      src/services/tree-sitter/queries/typescript.ts

+ 15 - 0
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")
 `