Skip to content

API Reference parrot.knowledge.wiki.languages.javascript

github-actions[bot] edited this page Nov 5, 2026 · 4 revisions

parrot.knowledge.wiki.languages.javascript

View source

JavaScript/TypeScript plugin for the wiki repo scanner.

A single scanner claims every JS/TS suffix (.js/.jsx/.mjs/ .ts/.tsx, FEAT-394) plus .svelte (FEAT-396): an API outline (exported and non-exported classes, functions, consts, interfaces, type aliases, with their JSDoc first line) via tree-sitter when the optional ai-parrot[wiki-languages] extra is installed, or a bounded, line-anchored regex heuristic otherwise.

Import extraction keeps every specifier as written; deciding what is resolvable happens in :meth:JavaScriptScanner.resolve_import, which alone has the per-scan alias map (FEAT-396). Relative specifiers (./, ../) resolve against the importing file's directory via extension guessing (.ts/.tsx/.js/.jsx/.mjs, then /index.*). Non-relative ones are matched against the repository's alias map — $lib/… and tsconfig.json/jsconfig.json paths — using the same guessing once the prefix is expanded. Anything still unresolved (an npm package such as react, or a SvelteKit virtual module such as $app/environment) yields None and the edge is dropped rather than left dangling.

Svelte components are handled by extraction, not by a separate scanner: :func:_extract_script_blocks pulls the <script> bodies out before parsing (the markup is not valid JS/TS and would break the tree), and the grammar is chosen from the block's declared lang rather than the file suffix. Only the <script> block is analysed — markup semantics (component usage, {#if}/{#each}, slots) are out of scope.

Class JavaScriptScanner

Deep extractor for JavaScript/TypeScript files.

Attributes:

Attribute Type Description
name str
suffixes frozenset[str]
mode str "tree-sitter" only when both selectable grammars load. This scanner picks between the TypeScript and JavaScript grammars per file, so reporting "tree-sitter" while either one is missing overstates what the outlines are worth: the files routed to the absent grammar silently took the regex path. Requiring both was the correction made in FEAT-396 — until then the check was an or, and since the JavaScript grammar always loaded, TypeScript and Svelte files were reported as tree-sitter while being parsed by regex.

Method JavaScriptScanner.outline

Extract summary, API outline, and raw imports from JS/TS source.

outline(source: str, rel_path: str) -> LanguageOutline

Parameter Type Default Description
source str Raw JS/TS source text.
rel_path str POSIX-style path relative to the repository root (unused by this scanner — kept for interface parity).

Returns: LanguageOutline — The extracted :class:LanguageOutline. Any extraction failure degrades to an empty outline rather than raising.

Method JavaScriptScanner.build_reference_index

Build the repo file set plus its import-alias map.

Alias configuration is read here — once per scan — rather than per file: this method is called a single time per scanner per scan, over every scanned path.

build_reference_index(rel_paths: Iterable[str]) -> Any

Parameter Type Default Description
rel_paths Iterable[str] POSIX-style relative paths of every scanned file.

Returns: Any — An opaque :class:JsIndex.

Method JavaScriptScanner.resolve_import

Resolve one import specifier to a repository file.

Relative specifiers (./x, ../x) resolve against the importing file's directory. Non-relative ones are matched against the repository's alias map, every matching prefix being tried longest-first until one lands on a real file — a more specific alias that expands to nothing must not shadow a broader one that would have resolved, which is also how TypeScript's own paths resolution behaves. Anything left over — an npm package, or a SvelteKit virtual module such as $app/environment — has no file here and yields None, so the edge is dropped rather than left dangling.

resolve_import(spec: str, from_file: str, index: Any) -> str | None

Parameter Type Default Description
spec str A raw import specifier.
from_file str POSIX-relative path of the importing file.
index Any The :class:JsIndex from :meth:build_reference_index.

Returns: str | None — The resolved rel path, or None when unresolved.

Class JsIndex

Scanned file set plus the repository's import-alias prefix map.

Replaces the bare frozenset[str] this scanner used to return. The alias map is a sorted tuple rather than a dict so longest-prefix matching is a plain ordered scan and the object stays hashable and immutable, exactly like the frozenset it supersedes.

Parameter Type Default Description
files frozenset[str]
aliases tuple[tuple[str, str], ...] ()

Fields:

Field Type Default Description
files frozenset[str] Every scanned repository file, POSIX relative paths.
aliases tuple[tuple[str, str], ...] () (prefix, target) pairs such as ("$lib/", "src/lib/"), ordered longest prefix first. Both sides always end in /, which is also what keeps Svelte 5 runes ($state, $derived) from ever matching.

Alias LanguageOutline

Re-exported from parrot.knowledge.wiki.languages.base.LanguageOutline.

Alias LanguageScanner

Re-exported from parrot.knowledge.wiki.languages.base.LanguageScanner.

Alias StructuralOutline

Re-exported from parrot.knowledge.wiki.symbols.StructuralOutline.

Alias SymbolKind

Re-exported from parrot.knowledge.wiki.symbols.SymbolKind.

Alias SymbolRecord

Re-exported from parrot.knowledge.wiki.symbols.SymbolRecord.

Alias SymbolRef

Re-exported from parrot.knowledge.wiki.symbols.SymbolRef.

Alias astgrep

Re-exported from parrot.knowledge.wiki.languages.astgrep.

Attribute logger

Alias render_outline

Re-exported from parrot.knowledge.wiki.languages.render.render_outline.

Alias sha1_of_text

Re-exported from parrot.knowledge.wiki.symbols.sha1_of_text.

Alias structural_enabled

Re-exported from parrot.knowledge.wiki.languages.render.structural_enabled.

Alias treesitter

Re-exported from parrot.knowledge.wiki.languages.treesitter.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally