gitnexus 1.6.4-rc.2 → 1.6.4-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/dist/_shared/index.d.ts +1 -1
- package/dist/_shared/index.d.ts.map +1 -1
- package/dist/_shared/index.js +1 -1
- package/dist/_shared/index.js.map +1 -1
- package/dist/_shared/scope-resolution/finalize-algorithm.d.ts +22 -14
- package/dist/_shared/scope-resolution/finalize-algorithm.d.ts.map +1 -1
- package/dist/_shared/scope-resolution/finalize-algorithm.js +298 -37
- package/dist/_shared/scope-resolution/finalize-algorithm.js.map +1 -1
- package/dist/_shared/scope-resolution/scope-tree.d.ts +23 -1
- package/dist/_shared/scope-resolution/scope-tree.d.ts.map +1 -1
- package/dist/_shared/scope-resolution/scope-tree.js +36 -2
- package/dist/_shared/scope-resolution/scope-tree.js.map +1 -1
- package/dist/_shared/scope-resolution/types.d.ts +47 -3
- package/dist/_shared/scope-resolution/types.d.ts.map +1 -1
- package/dist/_shared/scope-resolution/types.js +10 -2
- package/dist/_shared/scope-resolution/types.js.map +1 -1
- package/dist/cli/analyze.d.ts +6 -0
- package/dist/cli/analyze.js +35 -0
- package/dist/cli/doctor.d.ts +1 -0
- package/dist/cli/doctor.js +31 -0
- package/dist/cli/index.js +13 -0
- package/dist/cli/setup.js +2 -2
- package/dist/core/embeddings/config.d.ts +2 -0
- package/dist/core/embeddings/config.js +36 -0
- package/dist/core/embeddings/embedder.js +11 -6
- package/dist/core/embeddings/embedding-pipeline.d.ts +7 -1
- package/dist/core/embeddings/embedding-pipeline.js +93 -29
- package/dist/core/embeddings/exact-search.d.ts +15 -0
- package/dist/core/embeddings/exact-search.js +27 -0
- package/dist/core/embeddings/types.d.ts +4 -0
- package/dist/core/embeddings/types.js +2 -0
- package/dist/core/group/config-parser.js +2 -0
- package/dist/core/group/matching.d.ts +3 -3
- package/dist/core/group/matching.js +46 -6
- package/dist/core/group/storage.js +2 -0
- package/dist/core/group/sync.js +1 -1
- package/dist/core/group/types.d.ts +18 -0
- package/dist/core/ingestion/call-processor.d.ts +3 -3
- package/dist/core/ingestion/call-processor.js +58 -65
- package/dist/core/ingestion/constants.d.ts +4 -3
- package/dist/core/ingestion/constants.js +8 -3
- package/dist/core/ingestion/finalize-orchestrator.js +6 -3
- package/dist/core/ingestion/heritage-processor.js +2 -2
- package/dist/core/ingestion/import-processor.js +1 -1
- package/dist/core/ingestion/language-provider.d.ts +8 -0
- package/dist/core/ingestion/languages/csharp/captures.js +4 -1
- package/dist/core/ingestion/languages/csharp/namespace-siblings.d.ts +14 -13
- package/dist/core/ingestion/languages/csharp/namespace-siblings.js +62 -50
- package/dist/core/ingestion/languages/python/captures.js +9 -1
- package/dist/core/ingestion/languages/python/index.d.ts +1 -1
- package/dist/core/ingestion/languages/python/index.js +1 -1
- package/dist/core/ingestion/languages/python/simple-hooks.d.ts +3 -1
- package/dist/core/ingestion/languages/python/simple-hooks.js +8 -0
- package/dist/core/ingestion/languages/python.js +28 -1
- package/dist/core/ingestion/languages/swift.js +14 -0
- package/dist/core/ingestion/languages/typescript/arity-metadata.d.ts +59 -0
- package/dist/core/ingestion/languages/typescript/arity-metadata.js +103 -0
- package/dist/core/ingestion/languages/typescript/arity.d.ts +37 -0
- package/dist/core/ingestion/languages/typescript/arity.js +54 -0
- package/dist/core/ingestion/languages/typescript/cache-stats.d.ts +17 -0
- package/dist/core/ingestion/languages/typescript/cache-stats.js +28 -0
- package/dist/core/ingestion/languages/typescript/captures.d.ts +28 -0
- package/dist/core/ingestion/languages/typescript/captures.js +451 -0
- package/dist/core/ingestion/languages/typescript/import-decomposer.d.ts +49 -0
- package/dist/core/ingestion/languages/typescript/import-decomposer.js +371 -0
- package/dist/core/ingestion/languages/typescript/import-target.d.ts +50 -0
- package/dist/core/ingestion/languages/typescript/import-target.js +61 -0
- package/dist/core/ingestion/languages/typescript/index.d.ts +94 -0
- package/dist/core/ingestion/languages/typescript/index.js +94 -0
- package/dist/core/ingestion/languages/typescript/interpret.d.ts +35 -0
- package/dist/core/ingestion/languages/typescript/interpret.js +317 -0
- package/dist/core/ingestion/languages/typescript/merge-bindings.d.ts +62 -0
- package/dist/core/ingestion/languages/typescript/merge-bindings.js +158 -0
- package/dist/core/ingestion/languages/typescript/query.d.ts +77 -0
- package/dist/core/ingestion/languages/typescript/query.js +778 -0
- package/dist/core/ingestion/languages/typescript/receiver-binding.d.ts +59 -0
- package/dist/core/ingestion/languages/typescript/receiver-binding.js +171 -0
- package/dist/core/ingestion/languages/typescript/scope-resolver.d.ts +16 -0
- package/dist/core/ingestion/languages/typescript/scope-resolver.js +113 -0
- package/dist/core/ingestion/languages/typescript/simple-hooks.d.ts +71 -0
- package/dist/core/ingestion/languages/typescript/simple-hooks.js +131 -0
- package/dist/core/ingestion/languages/typescript.js +19 -0
- package/dist/core/ingestion/method-extractors/configs/swift.js +3 -4
- package/dist/core/ingestion/model/scope-resolution-indexes.d.ts +14 -1
- package/dist/core/ingestion/parsing-processor.js +20 -9
- package/dist/core/ingestion/pipeline-phases/processes.js +9 -4
- package/dist/core/ingestion/pipeline-phases/tools.d.ts +1 -0
- package/dist/core/ingestion/pipeline-phases/tools.js +10 -4
- package/dist/core/ingestion/registry-primary-flag.d.ts +3 -1
- package/dist/core/ingestion/registry-primary-flag.js +4 -1
- package/dist/core/ingestion/scope-extractor-bridge.d.ts +5 -2
- package/dist/core/ingestion/scope-extractor-bridge.js +7 -2
- package/dist/core/ingestion/scope-extractor.js +19 -18
- package/dist/core/ingestion/scope-resolution/contract/scope-resolver.d.ts +73 -11
- package/dist/core/ingestion/scope-resolution/contract/scope-resolver.js +48 -10
- package/dist/core/ingestion/scope-resolution/passes/compound-receiver.js +283 -14
- package/dist/core/ingestion/scope-resolution/passes/imported-return-types.d.ts +23 -2
- package/dist/core/ingestion/scope-resolution/passes/imported-return-types.js +109 -37
- package/dist/core/ingestion/scope-resolution/passes/mro.js +3 -1
- package/dist/core/ingestion/scope-resolution/passes/receiver-bound-calls.js +13 -5
- package/dist/core/ingestion/scope-resolution/pipeline/phase.js +11 -2
- package/dist/core/ingestion/scope-resolution/pipeline/registry.js +2 -0
- package/dist/core/ingestion/scope-resolution/pipeline/run.d.ts +8 -0
- package/dist/core/ingestion/scope-resolution/pipeline/run.js +21 -5
- package/dist/core/ingestion/scope-resolution/pipeline/validate-bindings-immutability.d.ts +39 -0
- package/dist/core/ingestion/scope-resolution/pipeline/validate-bindings-immutability.js +65 -0
- package/dist/core/ingestion/scope-resolution/scope/walkers.d.ts +54 -11
- package/dist/core/ingestion/scope-resolution/scope/walkers.js +105 -30
- package/dist/core/ingestion/type-extractors/swift.js +7 -4
- package/dist/core/ingestion/utils/ast-helpers.d.ts +2 -0
- package/dist/core/ingestion/utils/ast-helpers.js +12 -0
- package/dist/core/ingestion/utils/env.d.ts +10 -0
- package/dist/core/ingestion/utils/env.js +14 -0
- package/dist/core/ingestion/workers/parse-worker.d.ts +1 -0
- package/dist/core/ingestion/workers/parse-worker.js +15 -9
- package/dist/core/ingestion/workers/worker-pool.d.ts +11 -4
- package/dist/core/ingestion/workers/worker-pool.js +244 -48
- package/dist/core/lbug/extension-loader.d.ts +86 -0
- package/dist/core/lbug/extension-loader.js +184 -0
- package/dist/core/lbug/lbug-adapter.d.ts +18 -17
- package/dist/core/lbug/lbug-adapter.js +45 -73
- package/dist/core/lbug/pool-adapter.js +10 -28
- package/dist/core/platform/capabilities.d.ts +24 -0
- package/dist/core/platform/capabilities.js +54 -0
- package/dist/core/run-analyze.js +36 -9
- package/dist/core/search/bm25-index.d.ts +0 -17
- package/dist/core/search/bm25-index.js +10 -118
- package/dist/core/search/fts-indexes.d.ts +1 -0
- package/dist/core/search/fts-indexes.js +7 -0
- package/dist/core/search/fts-schema.d.ts +6 -0
- package/dist/core/search/fts-schema.js +7 -0
- package/dist/mcp/core/embedder.js +11 -4
- package/dist/mcp/local/local-backend.js +50 -15
- package/dist/server/api.d.ts +5 -0
- package/dist/server/api.js +113 -0
- package/hooks/claude/gitnexus-hook.cjs +11 -1
- package/package.json +6 -5
- package/scripts/build-tree-sitter-dart.cjs +42 -0
- package/scripts/build-tree-sitter-proto.cjs +1 -1
- package/scripts/build.js +22 -2
- package/scripts/install-duckdb-extension.mjs +37 -0
- package/vendor/tree-sitter-dart/README.md +18 -0
- package/vendor/tree-sitter-dart/binding.gyp +31 -0
- package/vendor/tree-sitter-dart/bindings/node/binding.cc +20 -0
- package/vendor/tree-sitter-dart/bindings/node/index.d.ts +28 -0
- package/vendor/tree-sitter-dart/bindings/node/index.js +7 -0
- package/vendor/tree-sitter-dart/grammar.js +2895 -0
- package/vendor/tree-sitter-dart/package.json +18 -0
- package/vendor/tree-sitter-dart/queries/highlights.scm +246 -0
- package/vendor/tree-sitter-dart/queries/tags.scm +92 -0
- package/vendor/tree-sitter-dart/queries/test.scm +1 -0
- package/vendor/tree-sitter-dart/src/grammar.json +12459 -0
- package/vendor/tree-sitter-dart/src/node-types.json +15055 -0
- package/vendor/tree-sitter-dart/src/parser.c +196127 -0
- package/vendor/tree-sitter-dart/src/scanner.c +130 -0
- package/vendor/tree-sitter-dart/src/tree_sitter/alloc.h +54 -0
- package/vendor/tree-sitter-dart/src/tree_sitter/array.h +290 -0
- package/vendor/tree-sitter-dart/src/tree_sitter/parser.h +265 -0
- package/vendor/tree-sitter-swift/LICENSE +21 -0
- package/vendor/tree-sitter-swift/README.md +139 -0
- package/vendor/tree-sitter-swift/bindings/node/index.d.ts +28 -0
- package/vendor/tree-sitter-swift/bindings/node/index.js +7 -0
- package/vendor/tree-sitter-swift/package.json +28 -0
- package/vendor/tree-sitter-swift/prebuilds/darwin-arm64/tree-sitter-swift.node +0 -0
- package/vendor/tree-sitter-swift/prebuilds/darwin-x64/tree-sitter-swift.node +0 -0
- package/vendor/tree-sitter-swift/prebuilds/linux-arm64/tree-sitter-swift.node +0 -0
- package/vendor/tree-sitter-swift/prebuilds/linux-x64/tree-sitter-swift.node +0 -0
- package/vendor/tree-sitter-swift/prebuilds/win32-arm64/tree-sitter-swift.node +0 -0
- package/vendor/tree-sitter-swift/prebuilds/win32-x64/tree-sitter-swift.node +0 -0
- package/vendor/tree-sitter-swift/src/node-types.json +30694 -0
- package/web/assets/agent-DaprsFSX.js +597 -0
- package/web/assets/architecture-YZFGNWBL-S5CXDPWN-DEdGaPg2.js +1 -0
- package/web/assets/architectureDiagram-EMZXCZ2Q-Domyk_gO.js +36 -0
- package/web/assets/blockDiagram-IGV67L2C-B_2kD7tM.js +132 -0
- package/web/assets/c4Diagram-DFAF54RM-BhJJW8Gg.js +10 -0
- package/web/assets/chunk-3GS5O3IE-jlWIjPsl.js +231 -0
- package/web/assets/chunk-3YCYZ6SJ-Blq_IzZs.js +1 -0
- package/web/assets/chunk-6NTNNK5N-DyPc58pp.js +1 -0
- package/web/assets/chunk-7RZVMHOQ-BdIU-RGO.js +321 -0
- package/web/assets/chunk-A34GCYZU-BI2i_LdU.js +1 -0
- package/web/assets/chunk-AEOMTBSW-D7qjBMHW.js +1 -0
- package/web/assets/chunk-CilyBKbf.js +1 -0
- package/web/assets/chunk-DJ7UZH7F-i11ywiBl.js +1 -0
- package/web/assets/chunk-DKKBVRCY-1SffGI1N.js +4 -0
- package/web/assets/chunk-DU5LTGQ6-DaPeiwD5.js +1 -0
- package/web/assets/chunk-FXACKDTF-uhhi2PC2.js +159 -0
- package/web/assets/chunk-H3VCZNTA-IchcISDt.js +1 -0
- package/web/assets/chunk-HN6EAY2L-D7ZFMNrB.js +1 -0
- package/web/assets/chunk-KSICW3F5-C2tZmXwv.js +15 -0
- package/web/assets/chunk-O5ABG6QK-Bt-Km84H.js +1 -0
- package/web/assets/chunk-PK6DOVAG-ChlWY0BQ.js +206 -0
- package/web/assets/chunk-RNJOYNJ4-B724K7cW.js +1 -0
- package/web/assets/chunk-RWUO3TPN-DYn1XriD.js +1 -0
- package/web/assets/chunk-TBF5ZNIQ-DKtDz6ae.js +1 -0
- package/web/assets/chunk-TU3PZOEN-DE5Qhc0N.js +1 -0
- package/web/assets/chunk-TYMNRAUI-g1h33cq-.js +1 -0
- package/web/assets/chunk-VELTKBKT-C9dVN39o.js +1 -0
- package/web/assets/chunk-W7ZLLLMY-Du-Hb9yb.js +1 -0
- package/web/assets/chunk-WSB5WSVC-B123clsZ.js +1 -0
- package/web/assets/chunk-XGPFEOL4-BR7Eue38.js +1 -0
- package/web/assets/classDiagram-PPOCWD7C-BglfKSs_.js +1 -0
- package/web/assets/classDiagram-v2-23LJLIIU-BSzTM28O.js +1 -0
- package/web/assets/context-builder-CqQNhRj1.js +15 -0
- package/web/assets/cose-bilkent-PNC4W37J-DCfErU-A.js +1 -0
- package/web/assets/dagre-E77IOHMT-tDRRhDoN.js +4 -0
- package/web/assets/diagram-H7BISOXX-CUVHlmAh.js +43 -0
- package/web/assets/diagram-JC5VWROH-BoyOxulB.js +24 -0
- package/web/assets/diagram-LXUTUG65-osr9hb7N.js +10 -0
- package/web/assets/diagram-WEHSV5V5-d8nUqS39.js +24 -0
- package/web/assets/erDiagram-GCSMX5X6-b-IwOhPS.js +85 -0
- package/web/assets/flowDiagram-OTCZ4VVT-Ott2Q0AP.js +162 -0
- package/web/assets/ganttDiagram-MUNLMDZQ-BYtgN_5s.js +292 -0
- package/web/assets/gitGraph-7Q5UKJZL-54BCDZD5-CFyBIGZq.js +1 -0
- package/web/assets/gitGraphDiagram-3HKGZ4G3-CsVD2gn4.js +106 -0
- package/web/assets/index-BleGLU8S.css +2 -0
- package/web/assets/index-C_xK08EW.js +885 -0
- package/web/assets/info-OMHHGYJF-BF2H5H6G-yjAxKEzh.js +1 -0
- package/web/assets/infoDiagram-MN7RKWGX-DXK0Unn5.js +2 -0
- package/web/assets/ishikawaDiagram-YMYX4NHK-CXsnC2FA.js +70 -0
- package/web/assets/journeyDiagram-SO5T7YLQ-BzZ07B-X.js +139 -0
- package/web/assets/kanban-definition-LJHFXRCJ-C6_EpAd9.js +89 -0
- package/web/assets/katex-GD7MH7QM-CJiOjBBJ.js +261 -0
- package/web/assets/mindmap-definition-2EUWGEK5-CCYGWZ1m.js +96 -0
- package/web/assets/packet-4T2RLAQJ-EV4IVRXR-B8k4E3IT.js +1 -0
- package/web/assets/pie-ZZUOXDRM-N23DN5KN-DdvfY118.js +1 -0
- package/web/assets/pieDiagram-3IATQBI2-RyvRlQb4.js +30 -0
- package/web/assets/quadrantDiagram-E256RVCF-Bfb6sxCx.js +7 -0
- package/web/assets/radar-PYXPWWZC-P6TP7ZYP-1EEDC_yU.js +1 -0
- package/web/assets/requirementDiagram-M5DCFWZL-DjvHDyvN.js +84 -0
- package/web/assets/sankeyDiagram-L3NBLAOT-CBCbbl8s.js +10 -0
- package/web/assets/sequenceDiagram-ZOUHS735-BscU8TUR.js +157 -0
- package/web/assets/stateDiagram-MLPALWAM-CJusEK2D.js +1 -0
- package/web/assets/stateDiagram-v2-B5LQ5ZB2-DImJ3PXD.js +1 -0
- package/web/assets/timeline-definition-5SPVSISX-DigPA1X8.js +120 -0
- package/web/assets/treeView-SZITEDCU-5DXDK3XO-CzPDt3aG.js +1 -0
- package/web/assets/treemap-W4RFUUIX-WYLRDWKO-B9Iqiorr.js +1 -0
- package/web/assets/vennDiagram-IE5QUKF5-C91UkZIf.js +34 -0
- package/web/assets/wardley-RL74JXVD-BCRCBASE-x42Qw7hp.js +1 -0
- package/web/assets/wardleyDiagram-XU3VSMPF-DloBhI0U.js +20 -0
- package/web/assets/xychartDiagram-ZHJ5623Y-BGWJvgwI.js +7 -0
- package/web/index.html +21 -0
- package/scripts/patch-tree-sitter-swift.cjs +0 -78
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree-sitter query for TypeScript scope captures (RFC §5.1).
|
|
3
|
+
*
|
|
4
|
+
* Captures the structural skeleton the generic scope-resolution pipeline
|
|
5
|
+
* consumes: scopes (module/namespace/class/function), declarations (class-
|
|
6
|
+
* likes, method-likes, properties, variables), imports (one anchor per
|
|
7
|
+
* statement — decomposed in `import-decomposer.ts`), type bindings
|
|
8
|
+
* (parameter annotations, variable annotations, constructor inference,
|
|
9
|
+
* return types), and references (call sites, member writes).
|
|
10
|
+
*
|
|
11
|
+
* TypeScript specifics that shape this query:
|
|
12
|
+
*
|
|
13
|
+
* - **Namespaces** (`namespace Foo { }`) use `internal_module` with a
|
|
14
|
+
* `namespace` anon keyword + `identifier` or `nested_identifier` name +
|
|
15
|
+
* `statement_block` body. Verified via Unit 1 probe.
|
|
16
|
+
* - **`this` / `super`** are NAMED nodes `(this)` / `(super)` — unlike
|
|
17
|
+
* C#'s `this`/`base` which are anonymous tokens. `(_)` wildcard matches
|
|
18
|
+
* them as the receiver child of `member_expression`, so we don't need
|
|
19
|
+
* explicit string patterns.
|
|
20
|
+
* - **Optional chaining** (`obj?.m()`) still matches the regular
|
|
21
|
+
* `member_expression > object: (_) / property: (property_identifier)`
|
|
22
|
+
* pattern; the `(optional_chain)` child sits between them but doesn't
|
|
23
|
+
* occupy a named field. Same query handles both.
|
|
24
|
+
* - **Dynamic imports** (`import('./mod')`) are `call_expression` whose
|
|
25
|
+
* `function` field is a named `import` node (not a regular identifier).
|
|
26
|
+
* Captured via a dedicated pattern.
|
|
27
|
+
* - **Function overloads** — `function f(x:string); function f(x:number);
|
|
28
|
+
* function f(x) { … }` emits two `function_signature` nodes plus one
|
|
29
|
+
* `function_declaration`. All three emit `@declaration.function`;
|
|
30
|
+
* arity metadata synthesis merges parameterTypes.
|
|
31
|
+
* - **Parameter properties** (`constructor(public name: string)`) — each
|
|
32
|
+
* parameter emits `@declaration.property` on the enclosing class; the
|
|
33
|
+
* same identifier also binds as a parameter in the constructor scope
|
|
34
|
+
* via the normal `required_parameter` → `@type-binding.parameter` path.
|
|
35
|
+
* - **Enum** — dual type+value. Emits `@scope.class` (enum body contains
|
|
36
|
+
* member declarations) + `@declaration.enum`. Members are captured as
|
|
37
|
+
* `@declaration.property` via the generic property_identifier pattern
|
|
38
|
+
* inside enum_body.
|
|
39
|
+
*
|
|
40
|
+
* Node types pinned via `scripts/_probe_typescript_grammar.ts`:
|
|
41
|
+
* internal_module, namespace_export, namespace_import, import_specifier,
|
|
42
|
+
* export_specifier, enum_declaration, type_alias_declaration,
|
|
43
|
+
* abstract_class_declaration, abstract_method_signature, method_signature,
|
|
44
|
+
* generator_function_declaration, optional_parameter, rest_parameter,
|
|
45
|
+
* required_parameter, public_field_definition, private_property_identifier,
|
|
46
|
+
* new_expression (constructor field), call_expression with (import) fn.
|
|
47
|
+
*
|
|
48
|
+
* Grammar version: tree-sitter-typescript pinned in gitnexus/package.json.
|
|
49
|
+
*
|
|
50
|
+
* Exposes lazy `Parser` and `Query` singletons so callers don't pay tree-
|
|
51
|
+
* sitter init cost per file.
|
|
52
|
+
*/
|
|
53
|
+
import Parser from 'tree-sitter';
|
|
54
|
+
import TS from 'tree-sitter-typescript';
|
|
55
|
+
// tree-sitter-typescript exports both `typescript` and `tsx` grammars on
|
|
56
|
+
// the default export. The package's `.d.ts` types the default export
|
|
57
|
+
// loosely; we narrow at the use site. The two grammars are NOT
|
|
58
|
+
// interchangeable: feeding a `.tsx` source to the `typescript` grammar
|
|
59
|
+
// mis-parses JSX as a sequence of less-than/greater-than expressions
|
|
60
|
+
// and silently drops every capture inside JSX elements. We therefore
|
|
61
|
+
// pick the grammar by file extension.
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
+
const TS_GRAMMAR = TS.typescript;
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
const TSX_GRAMMAR = TS.tsx;
|
|
66
|
+
/** True when the file should be parsed with the TSX grammar. The TSX
|
|
67
|
+
* grammar is a superset of TypeScript that adds JSX productions; it
|
|
68
|
+
* parses plain `.ts` files correctly too, but we keep `.ts` on the
|
|
69
|
+
* `typescript` grammar so the parser cache stays small and so any
|
|
70
|
+
* subtle TSX-only mis-parses don't bleed into non-TSX files. */
|
|
71
|
+
function isTsxFile(filePath) {
|
|
72
|
+
return filePath.endsWith('.tsx');
|
|
73
|
+
}
|
|
74
|
+
const TYPESCRIPT_SCOPE_QUERY = `
|
|
75
|
+
;; Scopes — module / namespace / class-likes / function-likes
|
|
76
|
+
(program) @scope.module
|
|
77
|
+
|
|
78
|
+
(internal_module) @scope.namespace
|
|
79
|
+
|
|
80
|
+
(class_declaration) @scope.class
|
|
81
|
+
(abstract_class_declaration) @scope.class
|
|
82
|
+
(interface_declaration) @scope.class
|
|
83
|
+
(enum_declaration) @scope.class
|
|
84
|
+
|
|
85
|
+
(function_declaration) @scope.function
|
|
86
|
+
(generator_function_declaration) @scope.function
|
|
87
|
+
(function_signature) @scope.function
|
|
88
|
+
(method_definition) @scope.function
|
|
89
|
+
(method_signature) @scope.function
|
|
90
|
+
(abstract_method_signature) @scope.function
|
|
91
|
+
(arrow_function) @scope.function
|
|
92
|
+
(function_expression) @scope.function
|
|
93
|
+
|
|
94
|
+
;; Type aliases that contain an object_type are structurally class-like —
|
|
95
|
+
;; they define a shape with named members. Emit @scope.class so the
|
|
96
|
+
;; field-extractor's type-alias-with-object-type handling (in
|
|
97
|
+
;; field-extractors/typescript.ts) finds a scope for its members.
|
|
98
|
+
(type_alias_declaration
|
|
99
|
+
value: (object_type)) @scope.class
|
|
100
|
+
|
|
101
|
+
;; Declarations — types
|
|
102
|
+
(class_declaration
|
|
103
|
+
name: (type_identifier) @declaration.name) @declaration.class
|
|
104
|
+
|
|
105
|
+
(abstract_class_declaration
|
|
106
|
+
name: (type_identifier) @declaration.name) @declaration.class
|
|
107
|
+
|
|
108
|
+
(interface_declaration
|
|
109
|
+
name: (type_identifier) @declaration.name) @declaration.interface
|
|
110
|
+
|
|
111
|
+
(enum_declaration
|
|
112
|
+
name: (identifier) @declaration.name) @declaration.enum
|
|
113
|
+
|
|
114
|
+
(type_alias_declaration
|
|
115
|
+
name: (type_identifier) @declaration.name) @declaration.type
|
|
116
|
+
|
|
117
|
+
(internal_module
|
|
118
|
+
name: (identifier) @declaration.name) @declaration.namespace
|
|
119
|
+
|
|
120
|
+
;; Declarations — methods / functions / constructors
|
|
121
|
+
(function_declaration
|
|
122
|
+
name: (identifier) @declaration.name) @declaration.function
|
|
123
|
+
|
|
124
|
+
(generator_function_declaration
|
|
125
|
+
name: (identifier) @declaration.name) @declaration.function
|
|
126
|
+
|
|
127
|
+
;; Function overload signatures (declaration-only; body in a separate
|
|
128
|
+
;; function_declaration). Extractors dedup by (name, parameterTypes).
|
|
129
|
+
(function_signature
|
|
130
|
+
name: (identifier) @declaration.name) @declaration.function
|
|
131
|
+
|
|
132
|
+
;; Arrow/function-expression assigned to a const/let/var — named by the
|
|
133
|
+
;; variable_declarator. Covers \`const fn = () => {}\` and its export
|
|
134
|
+
;; variant. Matches the legacy TYPESCRIPT_QUERIES pattern.
|
|
135
|
+
(lexical_declaration
|
|
136
|
+
(variable_declarator
|
|
137
|
+
name: (identifier) @declaration.name
|
|
138
|
+
value: (arrow_function))) @declaration.function
|
|
139
|
+
|
|
140
|
+
(lexical_declaration
|
|
141
|
+
(variable_declarator
|
|
142
|
+
name: (identifier) @declaration.name
|
|
143
|
+
value: (function_expression))) @declaration.function
|
|
144
|
+
|
|
145
|
+
(variable_declaration
|
|
146
|
+
(variable_declarator
|
|
147
|
+
name: (identifier) @declaration.name
|
|
148
|
+
value: (arrow_function))) @declaration.function
|
|
149
|
+
|
|
150
|
+
(variable_declaration
|
|
151
|
+
(variable_declarator
|
|
152
|
+
name: (identifier) @declaration.name
|
|
153
|
+
value: (function_expression))) @declaration.function
|
|
154
|
+
|
|
155
|
+
;; Method definitions — regular + private (#field) methods.
|
|
156
|
+
(method_definition
|
|
157
|
+
name: (property_identifier) @declaration.name) @declaration.method
|
|
158
|
+
|
|
159
|
+
(method_definition
|
|
160
|
+
name: (private_property_identifier) @declaration.name) @declaration.method
|
|
161
|
+
|
|
162
|
+
;; Abstract method signatures in abstract classes.
|
|
163
|
+
(abstract_method_signature
|
|
164
|
+
name: (property_identifier) @declaration.name) @declaration.method
|
|
165
|
+
|
|
166
|
+
;; Interface method signatures.
|
|
167
|
+
(method_signature
|
|
168
|
+
name: (property_identifier) @declaration.name) @declaration.method
|
|
169
|
+
|
|
170
|
+
;; Declarations — class fields
|
|
171
|
+
(public_field_definition
|
|
172
|
+
name: (property_identifier) @declaration.name) @declaration.property
|
|
173
|
+
|
|
174
|
+
(public_field_definition
|
|
175
|
+
name: (private_property_identifier) @declaration.name) @declaration.property
|
|
176
|
+
|
|
177
|
+
;; Declarations — parameter properties: \`constructor(public name: string)\`.
|
|
178
|
+
;; The accessibility_modifier presence distinguishes these from regular
|
|
179
|
+
;; parameters. The identifier is also bound as a parameter in the
|
|
180
|
+
;; constructor's scope via @type-binding.parameter below (dual binding).
|
|
181
|
+
(required_parameter
|
|
182
|
+
(accessibility_modifier)
|
|
183
|
+
pattern: (identifier) @declaration.name) @declaration.property
|
|
184
|
+
|
|
185
|
+
;; Declarations — variables (let / const / var)
|
|
186
|
+
(lexical_declaration
|
|
187
|
+
(variable_declarator
|
|
188
|
+
name: (identifier) @declaration.name)) @declaration.variable
|
|
189
|
+
|
|
190
|
+
(variable_declaration
|
|
191
|
+
(variable_declarator
|
|
192
|
+
name: (identifier) @declaration.name)) @declaration.variable
|
|
193
|
+
|
|
194
|
+
;; Imports — single anchor per statement; decomposer emits per-specifier markers.
|
|
195
|
+
(import_statement) @import.statement
|
|
196
|
+
|
|
197
|
+
;; Re-exports: \`export { X } from './y'\` / \`export * from './y'\` /
|
|
198
|
+
;; \`export * as ns from './y'\` / \`export type { X } from './y'\`.
|
|
199
|
+
;; Only re-exports (those with a \`from\` clause) emit @import.statement;
|
|
200
|
+
;; local \`export { X }\` (no source) is just visibility metadata, not an
|
|
201
|
+
;; import. The decomposer filters by source presence.
|
|
202
|
+
(export_statement
|
|
203
|
+
source: (string)) @import.statement
|
|
204
|
+
|
|
205
|
+
;; Dynamic imports: \`import('./m')\` / \`await import(x)\`. tree-sitter-
|
|
206
|
+
;; typescript represents \`import\` as a named leaf node; the call_expression's
|
|
207
|
+
;; function field points at it.
|
|
208
|
+
(call_expression
|
|
209
|
+
function: (import)) @import.dynamic
|
|
210
|
+
|
|
211
|
+
;; Type bindings — parameter annotations: \`function f(u: User)\`
|
|
212
|
+
(required_parameter
|
|
213
|
+
pattern: (identifier) @type-binding.name
|
|
214
|
+
type: (type_annotation
|
|
215
|
+
(type_identifier) @type-binding.type)) @type-binding.parameter
|
|
216
|
+
|
|
217
|
+
(required_parameter
|
|
218
|
+
pattern: (identifier) @type-binding.name
|
|
219
|
+
type: (type_annotation
|
|
220
|
+
(generic_type) @type-binding.type)) @type-binding.parameter
|
|
221
|
+
|
|
222
|
+
(required_parameter
|
|
223
|
+
pattern: (identifier) @type-binding.name
|
|
224
|
+
type: (type_annotation
|
|
225
|
+
(predefined_type) @type-binding.type)) @type-binding.parameter
|
|
226
|
+
|
|
227
|
+
;; Parameter with union / array / readonly wrappers: \`users: readonly User[]\`,
|
|
228
|
+
;; \`x: User | null\`, \`xs: User[]\`. interpret strips wrappers to the
|
|
229
|
+
;; discriminating type.
|
|
230
|
+
(required_parameter
|
|
231
|
+
pattern: (identifier) @type-binding.name
|
|
232
|
+
type: (type_annotation
|
|
233
|
+
(union_type) @type-binding.type)) @type-binding.parameter
|
|
234
|
+
|
|
235
|
+
(required_parameter
|
|
236
|
+
pattern: (identifier) @type-binding.name
|
|
237
|
+
type: (type_annotation
|
|
238
|
+
(array_type) @type-binding.type)) @type-binding.parameter
|
|
239
|
+
|
|
240
|
+
(required_parameter
|
|
241
|
+
pattern: (identifier) @type-binding.name
|
|
242
|
+
type: (type_annotation
|
|
243
|
+
(readonly_type) @type-binding.type)) @type-binding.parameter
|
|
244
|
+
|
|
245
|
+
;; Type bindings — parameter properties:
|
|
246
|
+
;; \`constructor(public address: Address)\` — each parameter with an
|
|
247
|
+
;; accessibility modifier is ALSO a class field. We emit a second
|
|
248
|
+
;; capture so \`tsBindingScopeFor\` can hoist these to the Class scope,
|
|
249
|
+
;; enabling \`user.address\` field access resolution. The regular
|
|
250
|
+
;; @type-binding.parameter above still fires for the constructor
|
|
251
|
+
;; scope binding — both bindings coexist, which is correct.
|
|
252
|
+
(required_parameter
|
|
253
|
+
(accessibility_modifier)
|
|
254
|
+
pattern: (identifier) @type-binding.name
|
|
255
|
+
type: (type_annotation
|
|
256
|
+
(type_identifier) @type-binding.type)) @type-binding.parameter-property
|
|
257
|
+
|
|
258
|
+
(required_parameter
|
|
259
|
+
(accessibility_modifier)
|
|
260
|
+
pattern: (identifier) @type-binding.name
|
|
261
|
+
type: (type_annotation
|
|
262
|
+
(generic_type) @type-binding.type)) @type-binding.parameter-property
|
|
263
|
+
|
|
264
|
+
(required_parameter
|
|
265
|
+
(accessibility_modifier)
|
|
266
|
+
pattern: (identifier) @type-binding.name
|
|
267
|
+
type: (type_annotation
|
|
268
|
+
(predefined_type) @type-binding.type)) @type-binding.parameter-property
|
|
269
|
+
|
|
270
|
+
(required_parameter
|
|
271
|
+
(accessibility_modifier)
|
|
272
|
+
pattern: (identifier) @type-binding.name
|
|
273
|
+
type: (type_annotation
|
|
274
|
+
(union_type) @type-binding.type)) @type-binding.parameter-property
|
|
275
|
+
|
|
276
|
+
(required_parameter
|
|
277
|
+
(accessibility_modifier)
|
|
278
|
+
pattern: (identifier) @type-binding.name
|
|
279
|
+
type: (type_annotation
|
|
280
|
+
(array_type) @type-binding.type)) @type-binding.parameter-property
|
|
281
|
+
|
|
282
|
+
(required_parameter
|
|
283
|
+
(accessibility_modifier)
|
|
284
|
+
pattern: (identifier) @type-binding.name
|
|
285
|
+
type: (type_annotation
|
|
286
|
+
(readonly_type) @type-binding.type)) @type-binding.parameter-property
|
|
287
|
+
|
|
288
|
+
(optional_parameter
|
|
289
|
+
pattern: (identifier) @type-binding.name
|
|
290
|
+
type: (type_annotation
|
|
291
|
+
(type_identifier) @type-binding.type)) @type-binding.parameter
|
|
292
|
+
|
|
293
|
+
(optional_parameter
|
|
294
|
+
pattern: (identifier) @type-binding.name
|
|
295
|
+
type: (type_annotation
|
|
296
|
+
(generic_type) @type-binding.type)) @type-binding.parameter
|
|
297
|
+
|
|
298
|
+
;; Type bindings — variable annotations: \`let u: User = ...\` / \`const u: User\`.
|
|
299
|
+
(variable_declarator
|
|
300
|
+
name: (identifier) @type-binding.name
|
|
301
|
+
type: (type_annotation
|
|
302
|
+
(type_identifier) @type-binding.type)) @type-binding.annotation
|
|
303
|
+
|
|
304
|
+
(variable_declarator
|
|
305
|
+
name: (identifier) @type-binding.name
|
|
306
|
+
type: (type_annotation
|
|
307
|
+
(generic_type) @type-binding.type)) @type-binding.annotation
|
|
308
|
+
|
|
309
|
+
(variable_declarator
|
|
310
|
+
name: (identifier) @type-binding.name
|
|
311
|
+
type: (type_annotation
|
|
312
|
+
(predefined_type) @type-binding.type)) @type-binding.annotation
|
|
313
|
+
|
|
314
|
+
;; Union types like \`User | null\` / \`User | undefined\` — interpret's
|
|
315
|
+
;; stripNullableUnion collapses to the discriminating arm.
|
|
316
|
+
(variable_declarator
|
|
317
|
+
name: (identifier) @type-binding.name
|
|
318
|
+
type: (type_annotation
|
|
319
|
+
(union_type) @type-binding.type)) @type-binding.annotation
|
|
320
|
+
|
|
321
|
+
;; Array types: \`User[]\` / \`readonly User[]\` — stripArraySuffix unwraps.
|
|
322
|
+
(variable_declarator
|
|
323
|
+
name: (identifier) @type-binding.name
|
|
324
|
+
type: (type_annotation
|
|
325
|
+
(array_type) @type-binding.type)) @type-binding.annotation
|
|
326
|
+
|
|
327
|
+
(variable_declarator
|
|
328
|
+
name: (identifier) @type-binding.name
|
|
329
|
+
type: (type_annotation
|
|
330
|
+
(readonly_type) @type-binding.type)) @type-binding.annotation
|
|
331
|
+
|
|
332
|
+
;; Type bindings — constructor-inferred: \`const u = new User()\`.
|
|
333
|
+
;; The variable_declarator's \`value\` field carries the new_expression; its
|
|
334
|
+
;; \`constructor\` field is the type identifier. Covers both typed (\`:User = \`)
|
|
335
|
+
;; and untyped declarations — the annotation pattern above wins if both
|
|
336
|
+
;; fire, via the scope-extractor's source-strength tie-break in
|
|
337
|
+
;; pass4CollectTypeBindings.
|
|
338
|
+
(variable_declarator
|
|
339
|
+
name: (identifier) @type-binding.name
|
|
340
|
+
value: (new_expression
|
|
341
|
+
constructor: (identifier) @type-binding.type)) @type-binding.constructor
|
|
342
|
+
|
|
343
|
+
;; Qualified constructor: \`const u = new models.User()\`. Captures the
|
|
344
|
+
;; member_expression's text as the type — resolver's QualifiedNameIndex
|
|
345
|
+
;; handles the dotted lookup.
|
|
346
|
+
(variable_declarator
|
|
347
|
+
name: (identifier) @type-binding.name
|
|
348
|
+
value: (new_expression
|
|
349
|
+
constructor: (member_expression) @type-binding.type)) @type-binding.constructor
|
|
350
|
+
|
|
351
|
+
;; Cast-wrapped constructor: \`const u = new User() as any\` /
|
|
352
|
+
;; \`const u = new User()!\`. The \`as T\` pattern also captures T itself
|
|
353
|
+
;; via the assertion clause above, but T is usually a non-discriminating
|
|
354
|
+
;; type (\`any\`, \`unknown\`) in these idioms; interpretTsTypeBinding
|
|
355
|
+
;; drops those so the constructor-inferred binding survives.
|
|
356
|
+
(variable_declarator
|
|
357
|
+
name: (identifier) @type-binding.name
|
|
358
|
+
value: (as_expression
|
|
359
|
+
(new_expression
|
|
360
|
+
constructor: (identifier) @type-binding.type))) @type-binding.constructor
|
|
361
|
+
|
|
362
|
+
(variable_declarator
|
|
363
|
+
name: (identifier) @type-binding.name
|
|
364
|
+
value: (non_null_expression
|
|
365
|
+
(new_expression
|
|
366
|
+
constructor: (identifier) @type-binding.type))) @type-binding.constructor
|
|
367
|
+
|
|
368
|
+
;; Double-cast: \`const u = new User() as unknown as any\` — as_expression
|
|
369
|
+
;; nested inside as_expression, with new_expression at the core.
|
|
370
|
+
(variable_declarator
|
|
371
|
+
name: (identifier) @type-binding.name
|
|
372
|
+
value: (as_expression
|
|
373
|
+
(as_expression
|
|
374
|
+
(new_expression
|
|
375
|
+
constructor: (identifier) @type-binding.type)))) @type-binding.constructor
|
|
376
|
+
|
|
377
|
+
;; Type bindings — call-result alias: \`const u = find()\`. Chain-follow
|
|
378
|
+
;; walks \`find\`'s return type via propagateImportedReturnTypes for cross-
|
|
379
|
+
;; file; same-file covered by explicit return annotations.
|
|
380
|
+
(variable_declarator
|
|
381
|
+
name: (identifier) @type-binding.name
|
|
382
|
+
value: (call_expression
|
|
383
|
+
function: (identifier) @type-binding.type)) @type-binding.alias
|
|
384
|
+
|
|
385
|
+
;; Type bindings — member-call alias: \`const u = svc.getUser()\`. The
|
|
386
|
+
;; callee is captured as a full \`member_expression\` text (\`svc.getUser\`)
|
|
387
|
+
;; so compound-receiver can resolve the receiver object before looking up
|
|
388
|
+
;; the method's hoisted return-type binding.
|
|
389
|
+
(variable_declarator
|
|
390
|
+
name: (identifier) @type-binding.name
|
|
391
|
+
value: (call_expression
|
|
392
|
+
function: (member_expression) @type-binding.type)) @type-binding.alias
|
|
393
|
+
|
|
394
|
+
;; Type bindings — await chain: \`const u = await find()\` / \`await svc.m()\`.
|
|
395
|
+
(variable_declarator
|
|
396
|
+
name: (identifier) @type-binding.name
|
|
397
|
+
value: (await_expression
|
|
398
|
+
(call_expression
|
|
399
|
+
function: (identifier) @type-binding.type))) @type-binding.alias
|
|
400
|
+
|
|
401
|
+
(variable_declarator
|
|
402
|
+
name: (identifier) @type-binding.name
|
|
403
|
+
value: (await_expression
|
|
404
|
+
(call_expression
|
|
405
|
+
function: (member_expression) @type-binding.type))) @type-binding.alias
|
|
406
|
+
|
|
407
|
+
;; Awaited generic calls re-associate: \`await fn<T>(...)\` parses as
|
|
408
|
+
;; \`call_expression(function: await_expression(identifier), type_arguments, arguments)\`
|
|
409
|
+
;; — NOT as an await_expression wrapping a call_expression. Handle both
|
|
410
|
+
;; free and member forms so the chain-follow picks up the inner callee.
|
|
411
|
+
(variable_declarator
|
|
412
|
+
name: (identifier) @type-binding.name
|
|
413
|
+
value: (call_expression
|
|
414
|
+
function: (await_expression
|
|
415
|
+
(identifier) @type-binding.type))) @type-binding.alias
|
|
416
|
+
|
|
417
|
+
(variable_declarator
|
|
418
|
+
name: (identifier) @type-binding.name
|
|
419
|
+
value: (call_expression
|
|
420
|
+
function: (await_expression
|
|
421
|
+
(member_expression) @type-binding.type))) @type-binding.alias
|
|
422
|
+
|
|
423
|
+
;; Type bindings — member-access alias: \`const addr = user.address\`.
|
|
424
|
+
;; Full \`member_expression\` text feeds compound-receiver Case 3b.
|
|
425
|
+
(variable_declarator
|
|
426
|
+
name: (identifier) @type-binding.name
|
|
427
|
+
value: (member_expression) @type-binding.type) @type-binding.member-alias
|
|
428
|
+
|
|
429
|
+
;; Type bindings — identifier alias: \`const alias = user\`. Chain-follow
|
|
430
|
+
;; resolves alias via user's binding.
|
|
431
|
+
(variable_declarator
|
|
432
|
+
name: (identifier) @type-binding.name
|
|
433
|
+
value: (identifier) @type-binding.type) @type-binding.alias
|
|
434
|
+
|
|
435
|
+
;; Type bindings — \`as\` assertion: \`const u = x as User\`. Prefer
|
|
436
|
+
;; the assertion's target type over RHS inference. as_expression's right
|
|
437
|
+
;; child is the target type (positional; no field name).
|
|
438
|
+
(variable_declarator
|
|
439
|
+
name: (identifier) @type-binding.name
|
|
440
|
+
value: (as_expression
|
|
441
|
+
(_)
|
|
442
|
+
(type_identifier) @type-binding.type)) @type-binding.assertion
|
|
443
|
+
|
|
444
|
+
(variable_declarator
|
|
445
|
+
name: (identifier) @type-binding.name
|
|
446
|
+
value: (as_expression
|
|
447
|
+
(_)
|
|
448
|
+
(generic_type) @type-binding.type)) @type-binding.assertion
|
|
449
|
+
|
|
450
|
+
;; Type bindings — non-null assertion: \`const u = find()!\`. Unwrap to the
|
|
451
|
+
;; underlying call's function identifier (matches the call-alias pattern).
|
|
452
|
+
(variable_declarator
|
|
453
|
+
name: (identifier) @type-binding.name
|
|
454
|
+
value: (non_null_expression
|
|
455
|
+
(call_expression
|
|
456
|
+
function: (identifier) @type-binding.type))) @type-binding.alias
|
|
457
|
+
|
|
458
|
+
;; Type bindings — for-of element: \`for (const u of users)\` — bind u to
|
|
459
|
+
;; users (chain-follow unwraps to element type via stripGeneric).
|
|
460
|
+
(for_in_statement
|
|
461
|
+
left: (identifier) @type-binding.name
|
|
462
|
+
right: (identifier) @type-binding.type) @type-binding.alias
|
|
463
|
+
|
|
464
|
+
;; Type bindings — for-of call iterable: \`for (const u of getUsers())\`.
|
|
465
|
+
(for_in_statement
|
|
466
|
+
left: (identifier) @type-binding.name
|
|
467
|
+
right: (call_expression
|
|
468
|
+
function: (identifier) @type-binding.type)) @type-binding.alias
|
|
469
|
+
|
|
470
|
+
;; Type bindings — for-of member-call iterable: \`for (const u of svc.getUsers())\`.
|
|
471
|
+
(for_in_statement
|
|
472
|
+
left: (identifier) @type-binding.name
|
|
473
|
+
right: (call_expression
|
|
474
|
+
function: (member_expression) @type-binding.type)) @type-binding.alias
|
|
475
|
+
|
|
476
|
+
;; Type bindings — for-of member-access iterable: \`for (const u of this.users)\`.
|
|
477
|
+
;; Bind u to \`users\` (the attribute name); chain-follow resolves users
|
|
478
|
+
;; via the enclosing class's field binding.
|
|
479
|
+
(for_in_statement
|
|
480
|
+
left: (identifier) @type-binding.name
|
|
481
|
+
right: (member_expression
|
|
482
|
+
property: (property_identifier) @type-binding.type)) @type-binding.alias
|
|
483
|
+
|
|
484
|
+
;; Type bindings — class field annotation: \`private city: City\`.
|
|
485
|
+
(public_field_definition
|
|
486
|
+
name: (property_identifier) @type-binding.name
|
|
487
|
+
type: (type_annotation
|
|
488
|
+
(type_identifier) @type-binding.type)) @type-binding.annotation
|
|
489
|
+
|
|
490
|
+
(public_field_definition
|
|
491
|
+
name: (property_identifier) @type-binding.name
|
|
492
|
+
type: (type_annotation
|
|
493
|
+
(generic_type) @type-binding.type)) @type-binding.annotation
|
|
494
|
+
|
|
495
|
+
(public_field_definition
|
|
496
|
+
name: (property_identifier) @type-binding.name
|
|
497
|
+
type: (type_annotation
|
|
498
|
+
(predefined_type) @type-binding.type)) @type-binding.annotation
|
|
499
|
+
|
|
500
|
+
;; Class field with union / array / readonly wrappers:
|
|
501
|
+
;; \`private users: User[]\`, \`private repos: readonly Repo[]\`,
|
|
502
|
+
;; \`private x: City | null\`. interpret strips wrappers to the
|
|
503
|
+
;; discriminating type so chain-follow unwraps to the element.
|
|
504
|
+
(public_field_definition
|
|
505
|
+
name: (property_identifier) @type-binding.name
|
|
506
|
+
type: (type_annotation
|
|
507
|
+
(union_type) @type-binding.type)) @type-binding.annotation
|
|
508
|
+
|
|
509
|
+
(public_field_definition
|
|
510
|
+
name: (property_identifier) @type-binding.name
|
|
511
|
+
type: (type_annotation
|
|
512
|
+
(array_type) @type-binding.type)) @type-binding.annotation
|
|
513
|
+
|
|
514
|
+
(public_field_definition
|
|
515
|
+
name: (property_identifier) @type-binding.name
|
|
516
|
+
type: (type_annotation
|
|
517
|
+
(readonly_type) @type-binding.type)) @type-binding.annotation
|
|
518
|
+
|
|
519
|
+
;; Private class field annotation: \`#city: City\`.
|
|
520
|
+
(public_field_definition
|
|
521
|
+
name: (private_property_identifier) @type-binding.name
|
|
522
|
+
type: (type_annotation
|
|
523
|
+
(type_identifier) @type-binding.type)) @type-binding.annotation
|
|
524
|
+
|
|
525
|
+
;; Type bindings — method return type: \`save(): User { … }\` / \`function f(): User { … }\`.
|
|
526
|
+
;; Function/method return-type is the type_annotation that is a direct
|
|
527
|
+
;; child of the function node (not the parameter's annotation). Anchor on
|
|
528
|
+
;; the function node so bindingScopeFor can hoist if the language requests
|
|
529
|
+
;; (TS keeps it on the method scope; we emit here and let the resolver
|
|
530
|
+
;; decide via hoistTypeBindingsToModule).
|
|
531
|
+
;;
|
|
532
|
+
;; Wrapper forms covered: plain \`User\`, generic \`Promise<User>\`,
|
|
533
|
+
;; array \`User[]\`, readonly \`readonly User[]\`, union \`User | null\`.
|
|
534
|
+
;; \`stripArraySuffix\` / \`stripReadonly\` / \`stripNullableUnion\` in
|
|
535
|
+
;; interpret reduce these to the discriminating element so chain-follow
|
|
536
|
+
;; can unwrap iterators returned from \`getUsers(): User[]\`.
|
|
537
|
+
(function_declaration
|
|
538
|
+
name: (identifier) @type-binding.name
|
|
539
|
+
return_type: (type_annotation
|
|
540
|
+
(type_identifier) @type-binding.type)) @type-binding.return
|
|
541
|
+
|
|
542
|
+
(function_declaration
|
|
543
|
+
name: (identifier) @type-binding.name
|
|
544
|
+
return_type: (type_annotation
|
|
545
|
+
(generic_type) @type-binding.type)) @type-binding.return
|
|
546
|
+
|
|
547
|
+
(function_declaration
|
|
548
|
+
name: (identifier) @type-binding.name
|
|
549
|
+
return_type: (type_annotation
|
|
550
|
+
(array_type) @type-binding.type)) @type-binding.return
|
|
551
|
+
|
|
552
|
+
(function_declaration
|
|
553
|
+
name: (identifier) @type-binding.name
|
|
554
|
+
return_type: (type_annotation
|
|
555
|
+
(readonly_type) @type-binding.type)) @type-binding.return
|
|
556
|
+
|
|
557
|
+
(function_declaration
|
|
558
|
+
name: (identifier) @type-binding.name
|
|
559
|
+
return_type: (type_annotation
|
|
560
|
+
(union_type) @type-binding.type)) @type-binding.return
|
|
561
|
+
|
|
562
|
+
(function_signature
|
|
563
|
+
name: (identifier) @type-binding.name
|
|
564
|
+
return_type: (type_annotation
|
|
565
|
+
(type_identifier) @type-binding.type)) @type-binding.return
|
|
566
|
+
|
|
567
|
+
(function_signature
|
|
568
|
+
name: (identifier) @type-binding.name
|
|
569
|
+
return_type: (type_annotation
|
|
570
|
+
(generic_type) @type-binding.type)) @type-binding.return
|
|
571
|
+
|
|
572
|
+
(function_signature
|
|
573
|
+
name: (identifier) @type-binding.name
|
|
574
|
+
return_type: (type_annotation
|
|
575
|
+
(array_type) @type-binding.type)) @type-binding.return
|
|
576
|
+
|
|
577
|
+
(function_signature
|
|
578
|
+
name: (identifier) @type-binding.name
|
|
579
|
+
return_type: (type_annotation
|
|
580
|
+
(readonly_type) @type-binding.type)) @type-binding.return
|
|
581
|
+
|
|
582
|
+
(function_signature
|
|
583
|
+
name: (identifier) @type-binding.name
|
|
584
|
+
return_type: (type_annotation
|
|
585
|
+
(union_type) @type-binding.type)) @type-binding.return
|
|
586
|
+
|
|
587
|
+
(method_definition
|
|
588
|
+
name: (property_identifier) @type-binding.name
|
|
589
|
+
return_type: (type_annotation
|
|
590
|
+
(type_identifier) @type-binding.type)) @type-binding.return
|
|
591
|
+
|
|
592
|
+
(method_definition
|
|
593
|
+
name: (property_identifier) @type-binding.name
|
|
594
|
+
return_type: (type_annotation
|
|
595
|
+
(generic_type) @type-binding.type)) @type-binding.return
|
|
596
|
+
|
|
597
|
+
(method_definition
|
|
598
|
+
name: (property_identifier) @type-binding.name
|
|
599
|
+
return_type: (type_annotation
|
|
600
|
+
(array_type) @type-binding.type)) @type-binding.return
|
|
601
|
+
|
|
602
|
+
(method_definition
|
|
603
|
+
name: (property_identifier) @type-binding.name
|
|
604
|
+
return_type: (type_annotation
|
|
605
|
+
(readonly_type) @type-binding.type)) @type-binding.return
|
|
606
|
+
|
|
607
|
+
(method_definition
|
|
608
|
+
name: (property_identifier) @type-binding.name
|
|
609
|
+
return_type: (type_annotation
|
|
610
|
+
(union_type) @type-binding.type)) @type-binding.return
|
|
611
|
+
|
|
612
|
+
(method_signature
|
|
613
|
+
name: (property_identifier) @type-binding.name
|
|
614
|
+
return_type: (type_annotation
|
|
615
|
+
(type_identifier) @type-binding.type)) @type-binding.return
|
|
616
|
+
|
|
617
|
+
(method_signature
|
|
618
|
+
name: (property_identifier) @type-binding.name
|
|
619
|
+
return_type: (type_annotation
|
|
620
|
+
(generic_type) @type-binding.type)) @type-binding.return
|
|
621
|
+
|
|
622
|
+
(method_signature
|
|
623
|
+
name: (property_identifier) @type-binding.name
|
|
624
|
+
return_type: (type_annotation
|
|
625
|
+
(array_type) @type-binding.type)) @type-binding.return
|
|
626
|
+
|
|
627
|
+
(method_signature
|
|
628
|
+
name: (property_identifier) @type-binding.name
|
|
629
|
+
return_type: (type_annotation
|
|
630
|
+
(readonly_type) @type-binding.type)) @type-binding.return
|
|
631
|
+
|
|
632
|
+
(method_signature
|
|
633
|
+
name: (property_identifier) @type-binding.name
|
|
634
|
+
return_type: (type_annotation
|
|
635
|
+
(union_type) @type-binding.type)) @type-binding.return
|
|
636
|
+
|
|
637
|
+
(abstract_method_signature
|
|
638
|
+
name: (property_identifier) @type-binding.name
|
|
639
|
+
return_type: (type_annotation
|
|
640
|
+
(type_identifier) @type-binding.type)) @type-binding.return
|
|
641
|
+
|
|
642
|
+
(abstract_method_signature
|
|
643
|
+
name: (property_identifier) @type-binding.name
|
|
644
|
+
return_type: (type_annotation
|
|
645
|
+
(generic_type) @type-binding.type)) @type-binding.return
|
|
646
|
+
|
|
647
|
+
;; Type bindings — assignment rebind: \`u = new User()\` (no \`const\`).
|
|
648
|
+
(assignment_expression
|
|
649
|
+
left: (identifier) @type-binding.name
|
|
650
|
+
right: (new_expression
|
|
651
|
+
constructor: (identifier) @type-binding.type)) @type-binding.constructor
|
|
652
|
+
|
|
653
|
+
(assignment_expression
|
|
654
|
+
left: (identifier) @type-binding.name
|
|
655
|
+
right: (call_expression
|
|
656
|
+
function: (identifier) @type-binding.type)) @type-binding.alias
|
|
657
|
+
|
|
658
|
+
(assignment_expression
|
|
659
|
+
left: (identifier) @type-binding.name
|
|
660
|
+
right: (identifier) @type-binding.type) @type-binding.alias
|
|
661
|
+
|
|
662
|
+
;; References — free calls: \`fn(args)\`. Exclude the dynamic-import form,
|
|
663
|
+
;; which would otherwise double-classify as a call to a built-in \`import\`.
|
|
664
|
+
;; tree-sitter can't negate (import) with #not-eq?; the captures.ts layer
|
|
665
|
+
;; filters dynamic-imports BEFORE the free-call is consumed.
|
|
666
|
+
(call_expression
|
|
667
|
+
function: (identifier) @reference.name) @reference.call.free
|
|
668
|
+
|
|
669
|
+
;; Awaited free call with generics: \`await fn<T>(...)\` — re-associated
|
|
670
|
+
;; by tree-sitter as \`call_expression(function: await_expression(identifier))\`.
|
|
671
|
+
(call_expression
|
|
672
|
+
function: (await_expression
|
|
673
|
+
(identifier) @reference.name)) @reference.call.free
|
|
674
|
+
|
|
675
|
+
;; References — member calls: \`obj.method()\` (includes optional chain).
|
|
676
|
+
;; The (_) wildcard matches any named receiver including \`this\` /
|
|
677
|
+
;; \`super\` (both are named nodes in tree-sitter-typescript, unlike C#'s
|
|
678
|
+
;; anonymous tokens).
|
|
679
|
+
(call_expression
|
|
680
|
+
function: (member_expression
|
|
681
|
+
object: (_) @reference.receiver
|
|
682
|
+
property: (property_identifier) @reference.name)) @reference.call.member
|
|
683
|
+
|
|
684
|
+
;; Awaited member call with generics: \`await svc.m<T>(...)\` — re-associated
|
|
685
|
+
;; as \`call_expression(function: await_expression(member_expression))\`.
|
|
686
|
+
(call_expression
|
|
687
|
+
function: (await_expression
|
|
688
|
+
(member_expression
|
|
689
|
+
object: (_) @reference.receiver
|
|
690
|
+
property: (property_identifier) @reference.name))) @reference.call.member
|
|
691
|
+
|
|
692
|
+
;; References — constructor calls: \`new User()\` / \`new ns.User()\`.
|
|
693
|
+
(new_expression
|
|
694
|
+
constructor: (identifier) @reference.name) @reference.call.constructor
|
|
695
|
+
|
|
696
|
+
(new_expression
|
|
697
|
+
constructor: (member_expression) @reference.call.constructor.qualified) @reference.call.constructor
|
|
698
|
+
|
|
699
|
+
;; References — write access: \`obj.field = value\`.
|
|
700
|
+
(assignment_expression
|
|
701
|
+
left: (member_expression
|
|
702
|
+
object: (_) @reference.receiver
|
|
703
|
+
property: (property_identifier) @reference.name)) @reference.write.member
|
|
704
|
+
|
|
705
|
+
(augmented_assignment_expression
|
|
706
|
+
left: (member_expression
|
|
707
|
+
object: (_) @reference.receiver
|
|
708
|
+
property: (property_identifier) @reference.name)) @reference.write.member
|
|
709
|
+
|
|
710
|
+
;; References — read access: \`obj.field\` used in a read context.
|
|
711
|
+
;; Fires on EVERY member_expression; \`emitTsScopeCaptures\` filters out
|
|
712
|
+
;; contexts that shouldn't emit a read ACCESSES edge (LHS of assignment,
|
|
713
|
+
;; the \`function:\` of a call_expression, property_identifier inside a
|
|
714
|
+
;; computed member name, etc.). Keeping the filter on the emit side lets
|
|
715
|
+
;; tree-sitter's pattern stay simple and we don't replicate AST-context
|
|
716
|
+
;; predicates in the query itself.
|
|
717
|
+
(member_expression
|
|
718
|
+
object: (_) @reference.receiver
|
|
719
|
+
property: (property_identifier) @reference.name) @reference.read.member
|
|
720
|
+
`;
|
|
721
|
+
let _tsParser = null;
|
|
722
|
+
let _tsxParser = null;
|
|
723
|
+
let _tsQuery = null;
|
|
724
|
+
let _tsxQuery = null;
|
|
725
|
+
/**
|
|
726
|
+
* Return the right tree-sitter parser for `filePath` (or the TS parser
|
|
727
|
+
* when no path is given — the legacy callsite shape).
|
|
728
|
+
*/
|
|
729
|
+
export function getTsParser(filePath) {
|
|
730
|
+
if (filePath !== undefined && isTsxFile(filePath)) {
|
|
731
|
+
if (_tsxParser === null) {
|
|
732
|
+
_tsxParser = new Parser();
|
|
733
|
+
_tsxParser.setLanguage(TSX_GRAMMAR);
|
|
734
|
+
}
|
|
735
|
+
return _tsxParser;
|
|
736
|
+
}
|
|
737
|
+
if (_tsParser === null) {
|
|
738
|
+
_tsParser = new Parser();
|
|
739
|
+
_tsParser.setLanguage(TS_GRAMMAR);
|
|
740
|
+
}
|
|
741
|
+
return _tsParser;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Return the right tree-sitter Query (compiled against the same grammar
|
|
745
|
+
* as the parser). A Query bound to the `typescript` grammar can NOT be
|
|
746
|
+
* executed against a Tree produced by the `tsx` grammar — tree-sitter
|
|
747
|
+
* matches by node-type id, and the two grammars have separate id
|
|
748
|
+
* spaces.
|
|
749
|
+
*/
|
|
750
|
+
export function getTsScopeQuery(filePath) {
|
|
751
|
+
if (filePath !== undefined && isTsxFile(filePath)) {
|
|
752
|
+
if (_tsxQuery === null) {
|
|
753
|
+
_tsxQuery = new Parser.Query(TSX_GRAMMAR, TYPESCRIPT_SCOPE_QUERY);
|
|
754
|
+
}
|
|
755
|
+
return _tsxQuery;
|
|
756
|
+
}
|
|
757
|
+
if (_tsQuery === null) {
|
|
758
|
+
_tsQuery = new Parser.Query(TS_GRAMMAR, TYPESCRIPT_SCOPE_QUERY);
|
|
759
|
+
}
|
|
760
|
+
return _tsQuery;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Validate that a cached `Tree` was produced by the grammar matching
|
|
764
|
+
* `filePath` (TSX vs TypeScript). The runtime tree-sitter `Tree` exposes
|
|
765
|
+
* `getLanguage()` (returning the grammar object the parser was bound
|
|
766
|
+
* to); the .d.ts is incomplete, so we reach via a cast. Identity
|
|
767
|
+
* comparison against `TSX_GRAMMAR` / `TS_GRAMMAR` is exact: the same
|
|
768
|
+
* module instance produces both. If `getLanguage` is unavailable for
|
|
769
|
+
* any reason, return true to keep behavior backwards-compatible (the
|
|
770
|
+
* original code never validated grammar at all).
|
|
771
|
+
*/
|
|
772
|
+
export function tsCachedTreeMatchesGrammar(tree, filePath) {
|
|
773
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
774
|
+
const lang = tree?.getLanguage?.();
|
|
775
|
+
if (lang === undefined || lang === null)
|
|
776
|
+
return true;
|
|
777
|
+
return isTsxFile(filePath) ? lang === TSX_GRAMMAR : lang === TS_GRAMMAR;
|
|
778
|
+
}
|