rbtr-lang-javascript 2026.9.0.dev0__py3-none-any.whl
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/__init__.py +1 -0
- rbtr_lang_javascript/javascript.scm +4 -0
- rbtr_lang_javascript/plugin.py +190 -0
- rbtr_lang_javascript/py.typed +0 -0
- rbtr_lang_javascript/shared.scm +29 -0
- rbtr_lang_javascript/tests/__init__.py +0 -0
- rbtr_lang_javascript/tests/__snapshots__/test_samples/test_edges_match_snapshot[javascript].json +4 -0
- rbtr_lang_javascript/tests/__snapshots__/test_samples/test_edges_match_snapshot[tsx].json +3 -0
- rbtr_lang_javascript/tests/__snapshots__/test_samples/test_edges_match_snapshot[typescript].json +6 -0
- rbtr_lang_javascript/tests/__snapshots__/test_samples/test_extraction_matches_snapshot[javascript].json +420 -0
- rbtr_lang_javascript/tests/__snapshots__/test_samples/test_extraction_matches_snapshot[tsx].json +211 -0
- rbtr_lang_javascript/tests/__snapshots__/test_samples/test_extraction_matches_snapshot[typescript].json +610 -0
- rbtr_lang_javascript/tests/cases_docstrings.py +225 -0
- rbtr_lang_javascript/tests/cases_extraction.py +429 -0
- rbtr_lang_javascript/tests/samples/javascript/config.js +2 -0
- rbtr_lang_javascript/tests/samples/javascript/javascript.js +46 -0
- rbtr_lang_javascript/tests/samples/javascript/styles.css +3 -0
- rbtr_lang_javascript/tests/samples/tsx/labels.ts +2 -0
- rbtr_lang_javascript/tests/samples/tsx/tsx.tsx +33 -0
- rbtr_lang_javascript/tests/samples/typescript/config.ts +2 -0
- rbtr_lang_javascript/tests/samples/typescript/types.ts +2 -0
- rbtr_lang_javascript/tests/samples/typescript/typescript.ts +68 -0
- rbtr_lang_javascript/tests/test_docstrings.py +51 -0
- rbtr_lang_javascript/tests/test_extraction.py +80 -0
- rbtr_lang_javascript/tests/test_samples.py +95 -0
- rbtr_lang_javascript/typescript.scm +36 -0
- rbtr_lang_javascript/variables.scm +54 -0
- rbtr_lang_javascript-2026.9.0.dev0.dist-info/METADATA +74 -0
- rbtr_lang_javascript-2026.9.0.dev0.dist-info/RECORD +32 -0
- rbtr_lang_javascript-2026.9.0.dev0.dist-info/WHEEL +4 -0
- rbtr_lang_javascript-2026.9.0.dev0.dist-info/entry_points.txt +5 -0
- rbtr_lang_javascript-2026.9.0.dev0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Counter — a small React component rendering a clickable count.
|
|
2
|
+
//
|
|
3
|
+
// The tsx plugin uses the `language_tsx` grammar, not
|
|
4
|
+
// `language_typescript`, which cannot parse JSX (a `.tsx` file parses
|
|
5
|
+
// with errors under the plain TypeScript grammar). It runs the same
|
|
6
|
+
// query as the typescript plugin against the JSX-aware grammar, so it
|
|
7
|
+
// extracts function declarations, arrow-function consts, module
|
|
8
|
+
// variables, imports, and interfaces (as classes — the CounterProps
|
|
9
|
+
// interface below).
|
|
10
|
+
|
|
11
|
+
import { useState } from "react";
|
|
12
|
+
import type { ReactNode } from "react";
|
|
13
|
+
import { INITIAL_LABEL } from "./labels";
|
|
14
|
+
|
|
15
|
+
export const INITIAL_COUNT: number = 0;
|
|
16
|
+
|
|
17
|
+
/** Props for the Counter component. */
|
|
18
|
+
interface CounterProps {
|
|
19
|
+
label: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A button that increments a counter on each click. */
|
|
23
|
+
export function Counter({ label }: CounterProps): ReactNode {
|
|
24
|
+
const [count, setCount] = useState(INITIAL_COUNT);
|
|
25
|
+
return (
|
|
26
|
+
<button onClick={() => setCount(count + 1)}>
|
|
27
|
+
{label}: {count}
|
|
28
|
+
</button>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Render a static badge as a span. */
|
|
33
|
+
const Badge = (text: string): ReactNode => <span className="badge">{text}</span>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Greeter — format greetings for named recipients.
|
|
2
|
+
//
|
|
3
|
+
// The TypeScript plugin extracts function declarations, arrow functions
|
|
4
|
+
// bound to consts, classes, module variables, and imports, with
|
|
5
|
+
// namespaces forming a scope. It also captures interfaces, enums, type
|
|
6
|
+
// aliases, and abstract classes (all as classes), and class/interface
|
|
7
|
+
// members as methods, including get/set accessors and abstract method
|
|
8
|
+
// signatures.
|
|
9
|
+
|
|
10
|
+
import { LOCALE } from "./config";
|
|
11
|
+
import type { Formatter } from "./types";
|
|
12
|
+
|
|
13
|
+
export const DEFAULT_GREETING: string = "Hello";
|
|
14
|
+
|
|
15
|
+
/** Tone of a greeting. */
|
|
16
|
+
export enum Tone {
|
|
17
|
+
Formal,
|
|
18
|
+
Casual,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A function that formats a greeting for a name. */
|
|
22
|
+
export type GreetingFn = (name: string) => string;
|
|
23
|
+
|
|
24
|
+
/** Format a greeting for a name. */
|
|
25
|
+
export function formatGreeting(name: string): string {
|
|
26
|
+
return `${DEFAULT_GREETING}, ${name} (${LOCALE})`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const cachedDefault = (): string => DEFAULT_GREETING;
|
|
30
|
+
|
|
31
|
+
/** A greeting formatter contract. */
|
|
32
|
+
export interface Greeting {
|
|
33
|
+
text: string;
|
|
34
|
+
format: Formatter;
|
|
35
|
+
render(name: string): string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Base greeter defining the prefix contract. */
|
|
39
|
+
abstract class AbstractGreeter {
|
|
40
|
+
protected x: string = DEFAULT_GREETING;
|
|
41
|
+
|
|
42
|
+
abstract greet(name: string): string;
|
|
43
|
+
|
|
44
|
+
get prefix(): string {
|
|
45
|
+
return this.x;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
set prefix(value: string) {
|
|
49
|
+
this.x = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Stateful greeter holding a prefix. */
|
|
54
|
+
export class Greeter extends AbstractGreeter {
|
|
55
|
+
greet(name: string): string {
|
|
56
|
+
return `${this.x}, ${name}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
namespace util {
|
|
61
|
+
export function trim(value: string): string {
|
|
62
|
+
return value.trim();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Re-exported so a consumer reaches these without naming their file.
|
|
67
|
+
export { Locale } from "./types";
|
|
68
|
+
export * from "./config";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""JavaScript / TypeScript JSDoc extraction.
|
|
2
|
+
|
|
3
|
+
rbtr folds a symbol's leading JSDoc into its chunk content. JS/TS are
|
|
4
|
+
exterior-doc languages (the doc is a leading comment attached by the
|
|
5
|
+
sibling walk), so suppressing that walk drops the doc and shifts
|
|
6
|
+
`line_start`. Data lives in `cases_docstrings.py`, sliced by tag.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from pytest_cases import parametrize_with_cases
|
|
12
|
+
|
|
13
|
+
from rbtr.git import FileEntry
|
|
14
|
+
from rbtr.languages.extract import extract_file
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@parametrize_with_cases(
|
|
18
|
+
"lang, source, name, snippet", cases=".cases_docstrings", has_tag="documented"
|
|
19
|
+
)
|
|
20
|
+
def test_documented_chunk_includes_doc_text(
|
|
21
|
+
lang: str, source: str, name: str, snippet: str
|
|
22
|
+
) -> None:
|
|
23
|
+
"""By default the chunk content carries the symbol's docs."""
|
|
24
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
25
|
+
chunk = next(c for c in chunks if c.name == name)
|
|
26
|
+
assert snippet in chunk.content, (
|
|
27
|
+
f"expected {snippet!r} in {lang}.{name} content; got:\n{chunk.content!r}"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@parametrize_with_cases(
|
|
32
|
+
"lang, source, name, snippet", cases=".cases_docstrings", has_tag="undocumented"
|
|
33
|
+
)
|
|
34
|
+
def test_no_phantom_documentation(lang: str, source: str, name: str, snippet: str) -> None:
|
|
35
|
+
"""Symbols without documentation do not gain any in content."""
|
|
36
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
37
|
+
chunk = next(c for c in chunks if c.name == name)
|
|
38
|
+
assert snippet not in chunk.content, (
|
|
39
|
+
f"unexpected {snippet!r} in {lang}.{name} content; got:\n{chunk.content!r}"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@parametrize_with_cases(
|
|
44
|
+
"lang, source, name, snippet", cases=".cases_docstrings", has_tag="exterior_doc"
|
|
45
|
+
)
|
|
46
|
+
def test_leading_doc_folds_into_symbol(lang: str, source: str, name: str, snippet: str) -> None:
|
|
47
|
+
"""A leading comment block folds into its symbol's chunk content."""
|
|
48
|
+
chunk = next(
|
|
49
|
+
c for c in extract_file(FileEntry("input", "sha1", source.encode()), lang) if c.name == name
|
|
50
|
+
)
|
|
51
|
+
assert snippet in chunk.content
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""JavaScript / TypeScript / TSX extraction tests.
|
|
2
|
+
|
|
3
|
+
Symbol, import, and mixed cases (`cases_extraction.py`) drive the shared
|
|
4
|
+
checks via pytest-cases.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pytest_cases import parametrize_with_cases
|
|
10
|
+
|
|
11
|
+
from rbtr.domain.models import ChunkKind, ImportMeta
|
|
12
|
+
from rbtr.git import FileEntry
|
|
13
|
+
from rbtr.languages.extract import extract_file
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@parametrize_with_cases("lang, source, expected", cases=".cases_extraction", has_tag="symbol")
|
|
17
|
+
def test_extracts_expected_symbols(lang: str, source: str, expected: list) -> None:
|
|
18
|
+
"""Each expected (kind, name, scope) tuple appears in the output."""
|
|
19
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
20
|
+
symbols = [(c.kind, c.name, c.scope) for c in chunks]
|
|
21
|
+
for exp in expected:
|
|
22
|
+
assert exp in symbols, f"expected {exp} not found in {symbols}"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@parametrize_with_cases(
|
|
26
|
+
"lang, source, expected_kinds, expected_methods", cases=".cases_extraction", has_tag="mixed"
|
|
27
|
+
)
|
|
28
|
+
def test_extracts_all_expected_kinds(
|
|
29
|
+
lang: str,
|
|
30
|
+
source: str,
|
|
31
|
+
expected_kinds: set[str],
|
|
32
|
+
expected_methods: list[tuple[str, str]],
|
|
33
|
+
) -> None:
|
|
34
|
+
"""Realistic source produces all expected chunk kinds and method scoping."""
|
|
35
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
36
|
+
kinds = {c.kind for c in chunks}
|
|
37
|
+
for kind in expected_kinds:
|
|
38
|
+
assert kind in kinds, f"expected kind {kind!r} not in {kinds}"
|
|
39
|
+
methods = [(c.name, c.scope) for c in chunks if c.kind == ChunkKind.METHOD]
|
|
40
|
+
for name, scope in expected_methods:
|
|
41
|
+
assert (name, scope) in methods, f"expected method ({name}, {scope}) not in {methods}"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@parametrize_with_cases("lang, source, expected", cases=".cases_extraction", has_tag="import")
|
|
45
|
+
def test_extracts_import_metadata(lang: str, source: str, expected: dict) -> None:
|
|
46
|
+
"""First import chunk has the expected metadata."""
|
|
47
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
48
|
+
imports = [c for c in chunks if c.kind == ChunkKind.IMPORT]
|
|
49
|
+
assert len(imports) >= 1, f"no import chunks extracted from {source!r}"
|
|
50
|
+
assert imports[0].metadata == ImportMeta(**expected)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@parametrize_with_cases(
|
|
54
|
+
"lang, source, count, metadata_list", cases=".cases_extraction", has_tag="multi_import"
|
|
55
|
+
)
|
|
56
|
+
def test_extracts_multi_import(
|
|
57
|
+
lang: str, source: str, count: int, metadata_list: list[dict]
|
|
58
|
+
) -> None:
|
|
59
|
+
"""Multiple imports have correct count and per-import metadata."""
|
|
60
|
+
chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
|
|
61
|
+
imports = [c for c in chunks if c.kind == ChunkKind.IMPORT]
|
|
62
|
+
assert len(imports) == count
|
|
63
|
+
for imp, expected in zip(imports, metadata_list, strict=True):
|
|
64
|
+
assert imp.metadata == ImportMeta(**expected)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_re_export_is_an_import_carrying_its_module() -> None:
|
|
68
|
+
"""A re-export reads from another module, so it resolves like an import.
|
|
69
|
+
|
|
70
|
+
It is also how a symbol reaches a consumer that never names the file
|
|
71
|
+
defining it, so the edge matters as much as the text.
|
|
72
|
+
"""
|
|
73
|
+
src = """\
|
|
74
|
+
export * from "./c";
|
|
75
|
+
export { helper } from "./b";
|
|
76
|
+
"""
|
|
77
|
+
chunks = list(extract_file(FileEntry("input.ts", "sha1", src.encode()), "typescript"))
|
|
78
|
+
imports = [(c.metadata.module, c.content) for c in chunks if c.kind == ChunkKind.IMPORT]
|
|
79
|
+
assert ("c", 'export * from "./c";') in imports
|
|
80
|
+
assert ("b", 'export { helper } from "./b";') in imports
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""JS / TS / TSX sample extraction through the real pipeline.
|
|
2
|
+
|
|
3
|
+
Parametrised over the package's three ids. The `javascript` sample includes a
|
|
4
|
+
`styles.css`, extracted via the css plugin (a dev dependency), so the edge
|
|
5
|
+
snapshot captures the cross-file links.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import TYPE_CHECKING
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
from tree_sitter import Parser
|
|
15
|
+
|
|
16
|
+
from rbtr.domain.models import Chunk, ChunkKind, Edge
|
|
17
|
+
from rbtr.git import FileEntry
|
|
18
|
+
from rbtr.languages.edges import build_resolution_map, infer_import_edges
|
|
19
|
+
from rbtr.languages.extract import extract_file
|
|
20
|
+
from rbtr.languages.manager import get_manager
|
|
21
|
+
from rbtr.testing import render_edges
|
|
22
|
+
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
from syrupy.assertion import SnapshotAssertion
|
|
25
|
+
|
|
26
|
+
_IDS = ["javascript", "typescript", "tsx"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.fixture(params=_IDS)
|
|
30
|
+
def lang(request: pytest.FixtureRequest) -> str:
|
|
31
|
+
"""Each of the package's three language ids in turn."""
|
|
32
|
+
return str(request.param)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.fixture
|
|
36
|
+
def project(lang: str) -> list[tuple[str, str]]:
|
|
37
|
+
"""The `(relative path, text)` files of the `samples/<lang>/` project."""
|
|
38
|
+
root = Path(__file__).parent / "samples" / lang
|
|
39
|
+
return [
|
|
40
|
+
(str(p.relative_to(root)), p.read_text()) for p in sorted(root.rglob("*")) if p.is_file()
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@pytest.fixture
|
|
45
|
+
def chunks(lang: str, project: list[tuple[str, str]]) -> list[Chunk]:
|
|
46
|
+
"""Chunks from every project file, each via the real `extract_file`.
|
|
47
|
+
|
|
48
|
+
A file is extracted as *its own* detected language (the javascript sample
|
|
49
|
+
spans js + css), so a project may mix languages.
|
|
50
|
+
"""
|
|
51
|
+
manager = get_manager()
|
|
52
|
+
out: list[Chunk] = []
|
|
53
|
+
for path, text in project:
|
|
54
|
+
file_lang = manager.detect_language(path) or lang
|
|
55
|
+
out.extend(extract_file(FileEntry(path, "sha1", text.encode()), file_lang))
|
|
56
|
+
return out
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.fixture
|
|
60
|
+
def edges(project: list[tuple[str, str]], chunks: list[Chunk]) -> list[Edge]:
|
|
61
|
+
"""Import edges inferred across the project's files."""
|
|
62
|
+
manager = get_manager()
|
|
63
|
+
repo_files = {path for path, _ in project}
|
|
64
|
+
return infer_import_edges(chunks, repo_files, build_resolution_map(manager))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_emits_expected_kinds(chunks: list[Chunk]) -> None:
|
|
68
|
+
"""Each sample exercises function, class, variable, and import chunks."""
|
|
69
|
+
kinds = {c.kind for c in chunks}
|
|
70
|
+
assert {
|
|
71
|
+
ChunkKind.FUNCTION,
|
|
72
|
+
ChunkKind.CLASS,
|
|
73
|
+
ChunkKind.VARIABLE,
|
|
74
|
+
ChunkKind.IMPORT,
|
|
75
|
+
ChunkKind.COMMENT,
|
|
76
|
+
} <= kinds
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_parses_cleanly(lang: str, project: list[tuple[str, str]]) -> None:
|
|
80
|
+
"""Every project file is valid source — no tree-sitter ERROR/MISSING nodes."""
|
|
81
|
+
manager = get_manager()
|
|
82
|
+
for path, text in project:
|
|
83
|
+
grammar = manager.grammar(manager.detect_language(path) or lang)
|
|
84
|
+
assert grammar is not None
|
|
85
|
+
assert not Parser(grammar).parse(text.encode()).root_node.has_error, path
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_extraction_matches_snapshot(chunks: list[Chunk], snapshot_json: SnapshotAssertion) -> None:
|
|
89
|
+
assert chunks == snapshot_json
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_edges_match_snapshot(
|
|
93
|
+
chunks: list[Chunk], edges: list[Edge], snapshot_json: SnapshotAssertion
|
|
94
|
+
) -> None:
|
|
95
|
+
assert render_edges(edges, chunks) == snapshot_json
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
; TypeScript adds type-level declarations (interface, enum, type alias,
|
|
2
|
+
; abstract class) as classes, and class/interface members as methods.
|
|
3
|
+
(class_declaration
|
|
4
|
+
name: (type_identifier) @_cls_name) @class
|
|
5
|
+
|
|
6
|
+
(abstract_class_declaration
|
|
7
|
+
name: (type_identifier) @_cls_name) @class
|
|
8
|
+
|
|
9
|
+
(interface_declaration
|
|
10
|
+
name: (type_identifier) @_cls_name) @class
|
|
11
|
+
|
|
12
|
+
(enum_declaration
|
|
13
|
+
name: (identifier) @_cls_name) @class
|
|
14
|
+
|
|
15
|
+
(enum_body
|
|
16
|
+
(property_identifier) @_var_name @variable)
|
|
17
|
+
|
|
18
|
+
(enum_body
|
|
19
|
+
(enum_assignment
|
|
20
|
+
name: (property_identifier) @_var_name) @variable)
|
|
21
|
+
|
|
22
|
+
(type_alias_declaration
|
|
23
|
+
name: (type_identifier) @_cls_name) @class
|
|
24
|
+
|
|
25
|
+
(internal_module
|
|
26
|
+
name: (identifier) @_cls_name) @class
|
|
27
|
+
|
|
28
|
+
(module
|
|
29
|
+
name: (identifier) @_cls_name) @class
|
|
30
|
+
|
|
31
|
+
(method_signature
|
|
32
|
+
name: (property_identifier) @_method_name) @method
|
|
33
|
+
|
|
34
|
+
(abstract_method_signature
|
|
35
|
+
name: (property_identifier) @_method_name) @method
|
|
36
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
; Module-level const/let bindings with a non-function value become
|
|
2
|
+
; variables. The value allowlist excludes arrow/function expressions,
|
|
3
|
+
; which shared.scm already captures as functions. Flat destructuring
|
|
4
|
+
; targets are captured; nested patterns are not (no query-only recursion).
|
|
5
|
+
|
|
6
|
+
(program
|
|
7
|
+
(lexical_declaration
|
|
8
|
+
(variable_declarator
|
|
9
|
+
name: (identifier) @_var_name
|
|
10
|
+
value: [(number) (string) (template_string) (true) (false) (null)
|
|
11
|
+
(object) (array) (identifier) (member_expression)
|
|
12
|
+
(call_expression) (new_expression) (binary_expression) (unary_expression)]) @variable))
|
|
13
|
+
|
|
14
|
+
(program
|
|
15
|
+
(export_statement
|
|
16
|
+
declaration: (lexical_declaration
|
|
17
|
+
(variable_declarator
|
|
18
|
+
name: (identifier) @_var_name
|
|
19
|
+
value: [(number) (string) (template_string) (true) (false) (null)
|
|
20
|
+
(object) (array) (identifier) (member_expression)
|
|
21
|
+
(call_expression) (new_expression) (binary_expression) (unary_expression)]) @variable)))
|
|
22
|
+
|
|
23
|
+
(program
|
|
24
|
+
(lexical_declaration
|
|
25
|
+
(variable_declarator
|
|
26
|
+
name: [
|
|
27
|
+
(object_pattern [
|
|
28
|
+
(shorthand_property_identifier_pattern) @_var_name
|
|
29
|
+
(pair_pattern value: (identifier) @_var_name)
|
|
30
|
+
(object_assignment_pattern left: (shorthand_property_identifier_pattern) @_var_name)
|
|
31
|
+
(rest_pattern (identifier) @_var_name)
|
|
32
|
+
])
|
|
33
|
+
(array_pattern [
|
|
34
|
+
(identifier) @_var_name
|
|
35
|
+
(rest_pattern (identifier) @_var_name)
|
|
36
|
+
])
|
|
37
|
+
]) @variable))
|
|
38
|
+
|
|
39
|
+
(program
|
|
40
|
+
(export_statement
|
|
41
|
+
declaration: (lexical_declaration
|
|
42
|
+
(variable_declarator
|
|
43
|
+
name: [
|
|
44
|
+
(object_pattern [
|
|
45
|
+
(shorthand_property_identifier_pattern) @_var_name
|
|
46
|
+
(pair_pattern value: (identifier) @_var_name)
|
|
47
|
+
(object_assignment_pattern left: (shorthand_property_identifier_pattern) @_var_name)
|
|
48
|
+
(rest_pattern (identifier) @_var_name)
|
|
49
|
+
])
|
|
50
|
+
(array_pattern [
|
|
51
|
+
(identifier) @_var_name
|
|
52
|
+
(rest_pattern (identifier) @_var_name)
|
|
53
|
+
])
|
|
54
|
+
]) @variable)))
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rbtr-lang-javascript
|
|
3
|
+
Version: 2026.9.0.dev0
|
|
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.dev0
|
|
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,32 @@
|
|
|
1
|
+
rbtr_lang_javascript/__init__.py,sha256=MVvtpOJhi6EumrhscVBk_ZVu2NhnJCpVrz05rZ0VNDA,57
|
|
2
|
+
rbtr_lang_javascript/javascript.scm,sha256=WFiuYFb4VMAY-lQ6rpgHTvx-1oHdM9QwJLPo7OtjE9Y,128
|
|
3
|
+
rbtr_lang_javascript/plugin.py,sha256=UawaEZc4SXjem12NRJVE-i0YMMdzD8UX8aL2sBnpWNM,6637
|
|
4
|
+
rbtr_lang_javascript/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
rbtr_lang_javascript/shared.scm,sha256=OBhWio7gGWaaEMQTkAiHylm09K8PUBaKWtwNohVmCMw,1001
|
|
6
|
+
rbtr_lang_javascript/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
rbtr_lang_javascript/tests/__snapshots__/test_samples/test_edges_match_snapshot[javascript].json,sha256=nUpKBwkloBbLZ9EC1FQNw4KgWFozkuGxXWcsp3X8zMM,173
|
|
8
|
+
rbtr_lang_javascript/tests/__snapshots__/test_samples/test_edges_match_snapshot[tsx].json,sha256=jWNwkJgtiEgIreRPDWtA7_gCdkUThA_y2esXlrnro-4,99
|
|
9
|
+
rbtr_lang_javascript/tests/__snapshots__/test_samples/test_edges_match_snapshot[typescript].json,sha256=fOdIT1RNY0twV1eczI_4ZDWb0lD7--kpnlple6YJj0Q,356
|
|
10
|
+
rbtr_lang_javascript/tests/__snapshots__/test_samples/test_extraction_matches_snapshot[javascript].json,sha256=ajjvFWvq-OJkyBPUIy4yMyNaiZN4yFxY6nsJxhsqBLY,10193
|
|
11
|
+
rbtr_lang_javascript/tests/__snapshots__/test_samples/test_extraction_matches_snapshot[tsx].json,sha256=V21r1vETIS28AKnPSciQwobMM8nyPcZPN39YYgUZOGc,5445
|
|
12
|
+
rbtr_lang_javascript/tests/__snapshots__/test_samples/test_extraction_matches_snapshot[typescript].json,sha256=V0g7G56ENVTOaoT1v718oolQqIz1-1V9Jy27e0a1iXE,14846
|
|
13
|
+
rbtr_lang_javascript/tests/cases_docstrings.py,sha256=sdbSjZlPVW1P3mYaqMm8dUrS-0xppbp3J0_jYjramOU,6523
|
|
14
|
+
rbtr_lang_javascript/tests/cases_extraction.py,sha256=gf-JDPHu56eTb1T3XCMR7YGJtMN--t7CCfA5ceetnDo,11692
|
|
15
|
+
rbtr_lang_javascript/tests/samples/javascript/config.js,sha256=W8cvq8HqNlSdGFVoteUFYMsJRZV8umh0wKgKHaNAeTA,69
|
|
16
|
+
rbtr_lang_javascript/tests/samples/javascript/javascript.js,sha256=EAElFlV7ws-KGgV3w5H8_E13ugo7joHLfCyUgQxH3xA,1214
|
|
17
|
+
rbtr_lang_javascript/tests/samples/javascript/styles.css,sha256=8SA3GIIHSpPFdXHLF0mif0lUB8QvIr48kAfBPwNlA50,28
|
|
18
|
+
rbtr_lang_javascript/tests/samples/tsx/labels.ts,sha256=i6ZmJ3BBC20HlDMi2ReOlgFh4YH33PKbtXC-G2d7yrA,60
|
|
19
|
+
rbtr_lang_javascript/tests/samples/tsx/tsx.tsx,sha256=3CfXxVWrSkh7CQhmlhc-ASRDcSP7OigOCGWljmTnSjE,1137
|
|
20
|
+
rbtr_lang_javascript/tests/samples/typescript/config.ts,sha256=W8cvq8HqNlSdGFVoteUFYMsJRZV8umh0wKgKHaNAeTA,69
|
|
21
|
+
rbtr_lang_javascript/tests/samples/typescript/types.ts,sha256=u81iQU9zedE_uQnKBOOggn8CINvW6N9rmYlO2rJii2I,75
|
|
22
|
+
rbtr_lang_javascript/tests/samples/typescript/typescript.ts,sha256=JoxTpB8QoXjjUIpGHBMkgIPSEhYpMdFhcd-oCerR-zo,1730
|
|
23
|
+
rbtr_lang_javascript/tests/test_docstrings.py,sha256=aY6AbIW5iyroZ0nG1FA7M3bJgyBcLtFiubwKDPVwDwQ,2012
|
|
24
|
+
rbtr_lang_javascript/tests/test_extraction.py,sha256=dqugn2nJb3dpFhawe_DP7JSdVuIrYPpDglijMMBON04,3409
|
|
25
|
+
rbtr_lang_javascript/tests/test_samples.py,sha256=KWF2CFsPGyWGPpy8c5ZvNDtAzBcqPNecsNHUFW72vlY,3213
|
|
26
|
+
rbtr_lang_javascript/typescript.scm,sha256=X-v0yaAIGn7WNj2Dj4esSdinMyWDa5BYnEjoz1On3ug,883
|
|
27
|
+
rbtr_lang_javascript/variables.scm,sha256=NuCZPIcZHqJoJxUijTXi8vQhWGDs8aIp-pKRIb57yaI,1863
|
|
28
|
+
rbtr_lang_javascript-2026.9.0.dev0.dist-info/licenses/LICENSE,sha256=3LvNTMhogXUXkHsDvTWaXdtGd9C-uuoIVD1ey8w9ITs,1077
|
|
29
|
+
rbtr_lang_javascript-2026.9.0.dev0.dist-info/WHEEL,sha256=-i9oRNYVXXZJUIYl5zclLIg6onEb0NLibTX34uln84w,81
|
|
30
|
+
rbtr_lang_javascript-2026.9.0.dev0.dist-info/entry_points.txt,sha256=NjGoszxHyf4Fc_TrO-HcJORjhaZFqguPtqqjBDoM31E,160
|
|
31
|
+
rbtr_lang_javascript-2026.9.0.dev0.dist-info/METADATA,sha256=biBHDrSjilj4Lh2v9a9Nc_cmNul2ToiyTlD5LWXQ-U0,3271
|
|
32
|
+
rbtr_lang_javascript-2026.9.0.dev0.dist-info/RECORD,,
|
|
@@ -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.
|