rbtr-lang-javascript 2026.9.0.dev1__tar.gz
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.
- rbtr_lang_javascript-2026.9.0.dev1/LICENSE +21 -0
- rbtr_lang_javascript-2026.9.0.dev1/PKG-INFO +74 -0
- rbtr_lang_javascript-2026.9.0.dev1/README.md +46 -0
- rbtr_lang_javascript-2026.9.0.dev1/pyproject.toml +68 -0
- rbtr_lang_javascript-2026.9.0.dev1/pyproject.toml.orig +70 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/__init__.py +1 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/javascript.scm +4 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/plugin.py +190 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/py.typed +0 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/shared.scm +29 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/__init__.py +0 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/__snapshots__/test_samples/test_edges_match_snapshot[javascript].json +4 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/__snapshots__/test_samples/test_edges_match_snapshot[tsx].json +3 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/__snapshots__/test_samples/test_edges_match_snapshot[typescript].json +6 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/__snapshots__/test_samples/test_extraction_matches_snapshot[javascript].json +420 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/__snapshots__/test_samples/test_extraction_matches_snapshot[tsx].json +211 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/__snapshots__/test_samples/test_extraction_matches_snapshot[typescript].json +610 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/cases_docstrings.py +225 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/cases_extraction.py +429 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/samples/javascript/config.js +2 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/samples/javascript/javascript.js +46 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/samples/javascript/styles.css +3 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/samples/tsx/labels.ts +2 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/samples/tsx/tsx.tsx +33 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/samples/typescript/config.ts +2 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/samples/typescript/types.ts +2 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/samples/typescript/typescript.ts +68 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/test_docstrings.py +51 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/test_extraction.py +80 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/tests/test_samples.py +95 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/typescript.scm +36 -0
- rbtr_lang_javascript-2026.9.0.dev1/src/rbtr_lang_javascript/variables.scm +54 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alejandro Giacometti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rbtr-lang-javascript
|
|
3
|
+
Version: 2026.9.0.dev1
|
|
4
|
+
Summary: rbtr — JavaScript / TypeScript / TSX language plugin
|
|
5
|
+
Keywords: code-search,code-index,tree-sitter,static-analysis,semantic-search,developer-tools,javascript,typescript
|
|
6
|
+
Author: Alejandro Giacometti
|
|
7
|
+
Author-email: Alejandro Giacometti <alejandro.giacometti@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: JavaScript
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Dist: rbtr==2026.9.0.dev1
|
|
19
|
+
Requires-Dist: tree-sitter-javascript
|
|
20
|
+
Requires-Dist: tree-sitter-typescript
|
|
21
|
+
Requires-Python: >=3.13
|
|
22
|
+
Project-URL: Homepage, https://github.com/janrito/rbtr
|
|
23
|
+
Project-URL: Repository, https://github.com/janrito/rbtr
|
|
24
|
+
Project-URL: Documentation, https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-javascript#readme
|
|
25
|
+
Project-URL: Issues, https://github.com/janrito/rbtr/issues
|
|
26
|
+
Project-URL: Changelog, https://github.com/janrito/rbtr/releases
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# rbtr-lang-javascript
|
|
30
|
+
|
|
31
|
+
JavaScript, TypeScript, and TSX support for [rbtr]. A **default**
|
|
32
|
+
plugin — installed with rbtr itself (`pip install rbtr`).
|
|
33
|
+
|
|
34
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
35
|
+
|
|
36
|
+
## What it ingests
|
|
37
|
+
|
|
38
|
+
One plugin, three ids across two grammars: `javascript` (`.js` / `.mjs` /
|
|
39
|
+
`.jsx`), `typescript` (`.ts`), and `tsx` (`.tsx`). A symbol's leading JSDoc is
|
|
40
|
+
folded into its chunk content.
|
|
41
|
+
|
|
42
|
+
- **Functions** — declarations, generators, and arrow functions bound to a
|
|
43
|
+
const; class/object methods (class members scoped to their class).
|
|
44
|
+
- **Classes** — classes, and TypeScript interfaces, enums, type aliases, and
|
|
45
|
+
namespaces (a namespace also scopes its members).
|
|
46
|
+
- **Variables** — module-level `const` / `let` (including destructuring).
|
|
47
|
+
- **Re-exports** — `export * from "./c"` and `export { x } from "./b"` read
|
|
48
|
+
from another module, so they resolve as imports do. A consumer reaches a
|
|
49
|
+
symbol through them without ever naming the file that defines it.
|
|
50
|
+
- **Imports** — `import`, `import type`, namespace, default, and side-effect
|
|
51
|
+
imports → import chunks with resolved module + names, for cross-file edges.
|
|
52
|
+
|
|
53
|
+
## Chunks produced
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
function greet(name) { … } // function "greet"
|
|
57
|
+
const add = (a, b) => a + b; // function "add"
|
|
58
|
+
class Button { render() {} } // class "Button"; method "render" scope "Button"
|
|
59
|
+
export const MAX = 100; // variable "MAX"
|
|
60
|
+
import { x } from "./x"; // import, metadata {module: "./x", names: "x"}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Embedded / injected chunks
|
|
64
|
+
|
|
65
|
+
None of its own — JavaScript/TypeScript are embedded *by* the HTML, Markdown,
|
|
66
|
+
and SFC (Vue/Svelte) plugins, which delegate `<script>` blocks and fenced code
|
|
67
|
+
here.
|
|
68
|
+
|
|
69
|
+
## Grammar & dependencies
|
|
70
|
+
|
|
71
|
+
Uses the `tree-sitter-javascript` and `tree-sitter-typescript` grammars. No
|
|
72
|
+
runtime dependency on other language plugins; the test suite dev-depends on
|
|
73
|
+
`rbtr-lang-css` so the sample's `styles.css` extracts and the cross-file edges
|
|
74
|
+
snapshot.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# rbtr-lang-javascript
|
|
2
|
+
|
|
3
|
+
JavaScript, TypeScript, and TSX support for [rbtr]. A **default**
|
|
4
|
+
plugin — installed with rbtr itself (`pip install rbtr`).
|
|
5
|
+
|
|
6
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
7
|
+
|
|
8
|
+
## What it ingests
|
|
9
|
+
|
|
10
|
+
One plugin, three ids across two grammars: `javascript` (`.js` / `.mjs` /
|
|
11
|
+
`.jsx`), `typescript` (`.ts`), and `tsx` (`.tsx`). A symbol's leading JSDoc is
|
|
12
|
+
folded into its chunk content.
|
|
13
|
+
|
|
14
|
+
- **Functions** — declarations, generators, and arrow functions bound to a
|
|
15
|
+
const; class/object methods (class members scoped to their class).
|
|
16
|
+
- **Classes** — classes, and TypeScript interfaces, enums, type aliases, and
|
|
17
|
+
namespaces (a namespace also scopes its members).
|
|
18
|
+
- **Variables** — module-level `const` / `let` (including destructuring).
|
|
19
|
+
- **Re-exports** — `export * from "./c"` and `export { x } from "./b"` read
|
|
20
|
+
from another module, so they resolve as imports do. A consumer reaches a
|
|
21
|
+
symbol through them without ever naming the file that defines it.
|
|
22
|
+
- **Imports** — `import`, `import type`, namespace, default, and side-effect
|
|
23
|
+
imports → import chunks with resolved module + names, for cross-file edges.
|
|
24
|
+
|
|
25
|
+
## Chunks produced
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
function greet(name) { … } // function "greet"
|
|
29
|
+
const add = (a, b) => a + b; // function "add"
|
|
30
|
+
class Button { render() {} } // class "Button"; method "render" scope "Button"
|
|
31
|
+
export const MAX = 100; // variable "MAX"
|
|
32
|
+
import { x } from "./x"; // import, metadata {module: "./x", names: "x"}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Embedded / injected chunks
|
|
36
|
+
|
|
37
|
+
None of its own — JavaScript/TypeScript are embedded *by* the HTML, Markdown,
|
|
38
|
+
and SFC (Vue/Svelte) plugins, which delegate `<script>` blocks and fenced code
|
|
39
|
+
here.
|
|
40
|
+
|
|
41
|
+
## Grammar & dependencies
|
|
42
|
+
|
|
43
|
+
Uses the `tree-sitter-javascript` and `tree-sitter-typescript` grammars. No
|
|
44
|
+
runtime dependency on other language plugins; the test suite dev-depends on
|
|
45
|
+
`rbtr-lang-css` so the sample's `styles.css` extracts and the cross-file edges
|
|
46
|
+
snapshot.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.11.26,<1"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[tool.uv.build-backend]
|
|
6
|
+
module-name = "rbtr_lang_javascript"
|
|
7
|
+
|
|
8
|
+
[tool.uv.sources.rbtr]
|
|
9
|
+
workspace = true
|
|
10
|
+
|
|
11
|
+
[tool.uv.sources.rbtr-lang-css]
|
|
12
|
+
workspace = true
|
|
13
|
+
|
|
14
|
+
[project]
|
|
15
|
+
name = "rbtr-lang-javascript"
|
|
16
|
+
version = "2026.9.0-dev1"
|
|
17
|
+
description = "rbtr — JavaScript / TypeScript / TSX language plugin"
|
|
18
|
+
readme = "README.md"
|
|
19
|
+
license = "MIT"
|
|
20
|
+
license-files = ["LICENSE"]
|
|
21
|
+
keywords = [
|
|
22
|
+
"code-search",
|
|
23
|
+
"code-index",
|
|
24
|
+
"tree-sitter",
|
|
25
|
+
"static-analysis",
|
|
26
|
+
"semantic-search",
|
|
27
|
+
"developer-tools",
|
|
28
|
+
"javascript",
|
|
29
|
+
"typescript",
|
|
30
|
+
]
|
|
31
|
+
classifiers = [
|
|
32
|
+
"Development Status :: 4 - Beta",
|
|
33
|
+
"Intended Audience :: Developers",
|
|
34
|
+
"Programming Language :: JavaScript",
|
|
35
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
36
|
+
"Programming Language :: Python :: 3.13",
|
|
37
|
+
"Topic :: Software Development :: Libraries",
|
|
38
|
+
"Topic :: Text Processing :: Indexing",
|
|
39
|
+
"Typing :: Typed",
|
|
40
|
+
]
|
|
41
|
+
requires-python = ">=3.13"
|
|
42
|
+
dependencies = [
|
|
43
|
+
"rbtr==2026.9.0-dev1",
|
|
44
|
+
"tree-sitter-javascript",
|
|
45
|
+
"tree-sitter-typescript",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[[project.authors]]
|
|
49
|
+
name = "Alejandro Giacometti"
|
|
50
|
+
email = "alejandro.giacometti@gmail.com"
|
|
51
|
+
|
|
52
|
+
[project.urls]
|
|
53
|
+
Homepage = "https://github.com/janrito/rbtr"
|
|
54
|
+
Repository = "https://github.com/janrito/rbtr"
|
|
55
|
+
Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-javascript#readme"
|
|
56
|
+
Issues = "https://github.com/janrito/rbtr/issues"
|
|
57
|
+
Changelog = "https://github.com/janrito/rbtr/releases"
|
|
58
|
+
|
|
59
|
+
[project.entry-points."rbtr.languages"]
|
|
60
|
+
javascript = "rbtr_lang_javascript.plugin:javascript"
|
|
61
|
+
typescript = "rbtr_lang_javascript.plugin:typescript"
|
|
62
|
+
tsx = "rbtr_lang_javascript.plugin:tsx"
|
|
63
|
+
|
|
64
|
+
[dependency-groups]
|
|
65
|
+
dev = [
|
|
66
|
+
"rbtr[test]",
|
|
67
|
+
"rbtr-lang-css",
|
|
68
|
+
]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.11.26,<1"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[tool.uv.build-backend]
|
|
6
|
+
module-name = "rbtr_lang_javascript"
|
|
7
|
+
# No source-exclude: the plugin's tests, samples, and snapshots ship
|
|
8
|
+
# with the wheel (they are the language's golden record), and the .scm
|
|
9
|
+
# queries ship as package data.
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "rbtr-lang-javascript"
|
|
13
|
+
version = "2026.9.0-dev1"
|
|
14
|
+
description = "rbtr — JavaScript / TypeScript / TSX language plugin"
|
|
15
|
+
readme = "README.md"
|
|
16
|
+
license = "MIT"
|
|
17
|
+
license-files = ["LICENSE"]
|
|
18
|
+
authors = [
|
|
19
|
+
{ name = "Alejandro Giacometti", email = "alejandro.giacometti@gmail.com" },
|
|
20
|
+
]
|
|
21
|
+
keywords = [
|
|
22
|
+
"code-search",
|
|
23
|
+
"code-index",
|
|
24
|
+
"tree-sitter",
|
|
25
|
+
"static-analysis",
|
|
26
|
+
"semantic-search",
|
|
27
|
+
"developer-tools",
|
|
28
|
+
"javascript",
|
|
29
|
+
"typescript",
|
|
30
|
+
]
|
|
31
|
+
classifiers = [
|
|
32
|
+
"Development Status :: 4 - Beta",
|
|
33
|
+
"Intended Audience :: Developers",
|
|
34
|
+
"Programming Language :: JavaScript",
|
|
35
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
36
|
+
"Programming Language :: Python :: 3.13",
|
|
37
|
+
"Topic :: Software Development :: Libraries",
|
|
38
|
+
"Topic :: Text Processing :: Indexing",
|
|
39
|
+
"Typing :: Typed",
|
|
40
|
+
]
|
|
41
|
+
requires-python = ">=3.13"
|
|
42
|
+
dependencies = [
|
|
43
|
+
"rbtr==2026.9.0-dev1",
|
|
44
|
+
"tree-sitter-javascript",
|
|
45
|
+
"tree-sitter-typescript",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Homepage = "https://github.com/janrito/rbtr"
|
|
50
|
+
Repository = "https://github.com/janrito/rbtr"
|
|
51
|
+
Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-javascript#readme"
|
|
52
|
+
Issues = "https://github.com/janrito/rbtr/issues"
|
|
53
|
+
Changelog = "https://github.com/janrito/rbtr/releases"
|
|
54
|
+
|
|
55
|
+
[project.entry-points."rbtr.languages"]
|
|
56
|
+
# Each value resolves to the language's `LanguageRegistration` (named by its
|
|
57
|
+
# id) — see the rbtr ARCHITECTURE "External plugins" note. One package, three
|
|
58
|
+
# ids across two grammars.
|
|
59
|
+
javascript = "rbtr_lang_javascript.plugin:javascript"
|
|
60
|
+
typescript = "rbtr_lang_javascript.plugin:typescript"
|
|
61
|
+
tsx = "rbtr_lang_javascript.plugin:tsx"
|
|
62
|
+
|
|
63
|
+
[tool.uv.sources]
|
|
64
|
+
rbtr = { workspace = true }
|
|
65
|
+
# The javascript sample project includes a styles.css, so the sample test
|
|
66
|
+
# needs the css plugin available to extract it and snapshot the cross edges.
|
|
67
|
+
rbtr-lang-css = { workspace = true }
|
|
68
|
+
|
|
69
|
+
[dependency-groups]
|
|
70
|
+
dev = ["rbtr[test]", "rbtr-lang-css"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""JavaScript and TypeScript language plugin package."""
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"""JavaScript and TypeScript language plugins.
|
|
2
|
+
|
|
3
|
+
Registers three languages (one per tree-sitter grammar) sharing a
|
|
4
|
+
common import extractor and a shared core query (classes, functions,
|
|
5
|
+
generators, variables, imports, and methods — class/object members
|
|
6
|
+
including get/set accessors). TS additionally captures interfaces,
|
|
7
|
+
enums, type aliases, abstract classes, and interface/abstract method
|
|
8
|
+
signatures.
|
|
9
|
+
|
|
10
|
+
Extracted chunks::
|
|
11
|
+
|
|
12
|
+
function greet() {} → function "greet", scope ""
|
|
13
|
+
const add = (a, b) => a + b; → function "add", scope ""
|
|
14
|
+
class Service {} → class "Service", scope ""
|
|
15
|
+
|
|
16
|
+
import { foo } from './models'
|
|
17
|
+
→ import, metadata {module: "models", names: "foo", dots: "1"}
|
|
18
|
+
import React from 'react'
|
|
19
|
+
→ import, metadata {module: "react", names: "React"}
|
|
20
|
+
import './styles.css'
|
|
21
|
+
→ import, metadata {module: "styles", dots: "1"}
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from pathlib import PurePosixPath
|
|
27
|
+
from typing import TYPE_CHECKING
|
|
28
|
+
|
|
29
|
+
from rbtr.domain.models import ImportMeta
|
|
30
|
+
from rbtr.languages.registration import (
|
|
31
|
+
ImportResolver,
|
|
32
|
+
LanguageRegistration,
|
|
33
|
+
QueryExtraction,
|
|
34
|
+
load_query,
|
|
35
|
+
parse_path_relative,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
if TYPE_CHECKING:
|
|
39
|
+
from tree_sitter import Node
|
|
40
|
+
|
|
41
|
+
_SHARED_QUERIES = load_query(__package__, "shared") + load_query(__package__, "variables")
|
|
42
|
+
_JS_QUERY = load_query(__package__, "javascript") + _SHARED_QUERIES
|
|
43
|
+
_TS_QUERY = load_query(__package__, "typescript") + _SHARED_QUERIES
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# ── Import extractor (shared by JS and TS) ───────────────────────────
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def extract_import_meta(
|
|
50
|
+
resolver: ImportResolver, node: Node, captures: dict[str, list[Node]]
|
|
51
|
+
) -> ImportMeta:
|
|
52
|
+
"""Extract import data from a JS/TS `import_statement` node.
|
|
53
|
+
|
|
54
|
+
Reads `@_import_module` from captures, then walks the node
|
|
55
|
+
for import names (which the query can't capture because
|
|
56
|
+
they're multi-valued). Applies `parse_path_relative` and
|
|
57
|
+
extension stripping to the module path.
|
|
58
|
+
|
|
59
|
+
Examples:
|
|
60
|
+
|
|
61
|
+
`import { foo } from './models'`:
|
|
62
|
+
module="models", names="foo", dots="1"
|
|
63
|
+
|
|
64
|
+
`import React from 'react'`:
|
|
65
|
+
module="react", names="React"
|
|
66
|
+
|
|
67
|
+
`import * as utils from '../utils'`:
|
|
68
|
+
module="utils", names="utils", dots="2"
|
|
69
|
+
|
|
70
|
+
`import './styles.css'`:
|
|
71
|
+
module="styles", dots="1"
|
|
72
|
+
"""
|
|
73
|
+
meta = resolver(node, captures)
|
|
74
|
+
names: list[str] = []
|
|
75
|
+
|
|
76
|
+
# Module comes from @_import_module capture (string_fragment).
|
|
77
|
+
# Still need to parse relative paths and strip extensions.
|
|
78
|
+
raw_module = meta.module
|
|
79
|
+
|
|
80
|
+
# Import clause (no named fields — child iteration needed).
|
|
81
|
+
for child in node.children:
|
|
82
|
+
if child.type != "import_clause":
|
|
83
|
+
continue
|
|
84
|
+
for ic in child.children:
|
|
85
|
+
match ic.type:
|
|
86
|
+
case "identifier":
|
|
87
|
+
if ic.text:
|
|
88
|
+
names.append(ic.text.decode())
|
|
89
|
+
case "named_imports":
|
|
90
|
+
for spec in ic.children:
|
|
91
|
+
if spec.type == "import_specifier":
|
|
92
|
+
sid = spec.child_by_field_name("name")
|
|
93
|
+
if sid and sid.text:
|
|
94
|
+
names.append(sid.text.decode())
|
|
95
|
+
case "namespace_import":
|
|
96
|
+
for ns in ic.children:
|
|
97
|
+
if ns.type == "identifier" and ns.text:
|
|
98
|
+
names.append(ns.text.decode())
|
|
99
|
+
break
|
|
100
|
+
|
|
101
|
+
if raw_module:
|
|
102
|
+
dots, cleaned = parse_path_relative(raw_module)
|
|
103
|
+
if dots:
|
|
104
|
+
meta.dots = str(dots)
|
|
105
|
+
# Strip file extensions so edges.py can match without guessing.
|
|
106
|
+
cleaned = str(PurePosixPath(cleaned).with_suffix("")) or cleaned
|
|
107
|
+
meta.module = cleaned
|
|
108
|
+
|
|
109
|
+
if names:
|
|
110
|
+
meta.names = ",".join(names)
|
|
111
|
+
return meta
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# ── Plugin ───────────────────────────────────────────────────────────
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
javascript = LanguageRegistration(
|
|
118
|
+
id="javascript",
|
|
119
|
+
extensions=frozenset({".js", ".jsx", ".mjs"}),
|
|
120
|
+
grammar_module="tree_sitter_javascript",
|
|
121
|
+
extraction=QueryExtraction(
|
|
122
|
+
query=_JS_QUERY,
|
|
123
|
+
scope_types=frozenset({"class_declaration", "function_declaration"}),
|
|
124
|
+
class_scope_types=frozenset({"class_declaration"}),
|
|
125
|
+
# Both `/** */` JSDoc and `//` comments land in
|
|
126
|
+
# the grammar as a single `comment` node type.
|
|
127
|
+
),
|
|
128
|
+
index_files=frozenset({"index.js"}),
|
|
129
|
+
import_targets=frozenset({"javascript", "css"}),
|
|
130
|
+
source_roots=("", "src"),
|
|
131
|
+
extraction_serial=6,
|
|
132
|
+
)
|
|
133
|
+
typescript = LanguageRegistration(
|
|
134
|
+
id="typescript",
|
|
135
|
+
extensions=frozenset({".ts"}),
|
|
136
|
+
grammar_module="tree_sitter_typescript",
|
|
137
|
+
grammar_entry="language_typescript",
|
|
138
|
+
extraction=QueryExtraction(
|
|
139
|
+
query=_TS_QUERY,
|
|
140
|
+
scope_types=frozenset(
|
|
141
|
+
{
|
|
142
|
+
"class_declaration",
|
|
143
|
+
"abstract_class_declaration",
|
|
144
|
+
"interface_declaration",
|
|
145
|
+
"function_declaration",
|
|
146
|
+
"internal_module",
|
|
147
|
+
"module",
|
|
148
|
+
"enum_declaration",
|
|
149
|
+
}
|
|
150
|
+
),
|
|
151
|
+
class_scope_types=frozenset(
|
|
152
|
+
{"class_declaration", "abstract_class_declaration", "interface_declaration"}
|
|
153
|
+
),
|
|
154
|
+
),
|
|
155
|
+
index_files=frozenset({"index.ts", "index.js"}),
|
|
156
|
+
import_targets=frozenset({"typescript", "tsx", "javascript", "css"}),
|
|
157
|
+
source_roots=("", "src"),
|
|
158
|
+
extraction_serial=6,
|
|
159
|
+
)
|
|
160
|
+
tsx = LanguageRegistration(
|
|
161
|
+
id="tsx",
|
|
162
|
+
extensions=frozenset({".tsx"}),
|
|
163
|
+
grammar_module="tree_sitter_typescript",
|
|
164
|
+
grammar_entry="language_tsx",
|
|
165
|
+
extraction=QueryExtraction(
|
|
166
|
+
query=_TS_QUERY,
|
|
167
|
+
scope_types=frozenset(
|
|
168
|
+
{
|
|
169
|
+
"class_declaration",
|
|
170
|
+
"abstract_class_declaration",
|
|
171
|
+
"interface_declaration",
|
|
172
|
+
"function_declaration",
|
|
173
|
+
"internal_module",
|
|
174
|
+
"module",
|
|
175
|
+
"enum_declaration",
|
|
176
|
+
}
|
|
177
|
+
),
|
|
178
|
+
class_scope_types=frozenset(
|
|
179
|
+
{"class_declaration", "abstract_class_declaration", "interface_declaration"}
|
|
180
|
+
),
|
|
181
|
+
),
|
|
182
|
+
index_files=frozenset({"index.tsx", "index.ts", "index.js"}),
|
|
183
|
+
import_targets=frozenset({"tsx", "typescript", "javascript", "css"}),
|
|
184
|
+
source_roots=("", "src"),
|
|
185
|
+
extraction_serial=3,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
javascript.import_extractor(extract_import_meta)
|
|
189
|
+
typescript.import_extractor(extract_import_meta)
|
|
190
|
+
tsx.import_extractor(extract_import_meta)
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
; Shared patterns — identical across the JS and TS grammars.
|
|
2
|
+
; Comments (JS/TS: single `comment` type for `//` and `/* */`, incl. JSDoc).
|
|
3
|
+
(comment) @comment
|
|
4
|
+
|
|
5
|
+
; method_definition covers class and object-literal members, generators,
|
|
6
|
+
; and get/set accessors; inside a class it promotes to a method scoped to
|
|
7
|
+
; the class, elsewhere it is a scope-less method.
|
|
8
|
+
(function_declaration
|
|
9
|
+
name: (identifier) @_fn_name) @function
|
|
10
|
+
|
|
11
|
+
(generator_function_declaration
|
|
12
|
+
name: (identifier) @_fn_name) @function
|
|
13
|
+
|
|
14
|
+
(import_statement
|
|
15
|
+
source: (string (string_fragment) @_import_module)) @import
|
|
16
|
+
|
|
17
|
+
(lexical_declaration
|
|
18
|
+
(variable_declarator
|
|
19
|
+
name: (identifier) @_fn_name
|
|
20
|
+
value: (arrow_function))) @function
|
|
21
|
+
|
|
22
|
+
(method_definition
|
|
23
|
+
name: (property_identifier) @_method_name) @method
|
|
24
|
+
|
|
25
|
+
; A re-export reads from another module, so it resolves as an import, and
|
|
26
|
+
; it is how a symbol reaches a consumer that never names its defining
|
|
27
|
+
; file.
|
|
28
|
+
(export_statement
|
|
29
|
+
source: (string (string_fragment) @_import_module)) @import
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
[
|
|
2
|
+
"typescript.ts::export * from \"./config\"; -> config.ts::LOCALE [imports]",
|
|
3
|
+
"typescript.ts::export { Locale } from \"./types\"; -> types.ts::Formatter [imports]",
|
|
4
|
+
"typescript.ts::import type { Formatter } from \"./types\"; -> types.ts::Formatter [imports]",
|
|
5
|
+
"typescript.ts::import { LOCALE } from \"./config\"; -> config.ts::LOCALE [imports]"
|
|
6
|
+
]
|