@reponova/lang-javascript
v0.3.0
Published
JavaScript language support for RepoNova (.js, .mjs, .cjs, .jsx via tree-sitter-javascript)
Maintainers
Readme
@reponova/lang-javascript
JavaScript language support for RepoNova. Parses .js, .mjs, .cjs, and .jsx files via the official tree-sitter-javascript WASM grammar (which has native JSX support inline) and produces graph-ready symbols, imports, and references.
This plugin is the JavaScript sibling of @reponova/lang-typescript and @reponova/lang-tsx. All three share the same extractor implementation and emit identical FileExtraction shapes, so a graph that mixes .js / .ts / .jsx / .tsx files is fully homogeneous — every code-flow analysis written against one applies to the others without translation.
Install
reponova lang add @reponova/lang-javascriptWhat it extracts
- Symbols:
functiondeclarations and arrow-function constants (const App = () => …) hoisted as functions — captures most React-style functional componentsclassdeclarations withextendsmethoddefinitions on classes, includingconstructor- Class fields (
public_field_definition/class_static_block) asvariablesymbols hung under the class, preservingstaticas a decorator - Getters and setters as separate symbols, tagged with
getter/setterdecorators - Top-level
UPPER_SNAKE_CASEconstants - Any exported
const/let/varbinding (export const handler = …) as aconstantsymbol - CommonJS
module.exports = …andexports.foo = …are recorded as exports (no separate symbol unless the assigned expression is itself a function / class declaration)
- Modifier markers (prepended to
decorators):async,generator,getter,setter, plusstaticfor class fields - Edges:
extendsfrom each class to its base classcallsfrom each function / method to every called identifier or member expression in its body. Hooks (useState,useEffect, …) and JSX component calls (<Card />→Card) both surface ascalls.
- Imports: ES module
import(default, named, namespace, side-effect, dynamicimport('…')), and CommonJSrequire('…')— both produce identical edges. - Re-exports:
export … from '…'(flagged withisExport: true). - Docstrings: the leading
/** … */JSDoc block at file start (module docstring), at every top-level declaration, and at every class member. - Decorators: TC39 stage-3 decorators on classes, methods, and class fields (
@Logger,@loggable) where the JS dialect supports them. - File node kind:
module.
Extensions
.js, .mjs, .cjs, .jsx
A single tree-sitter-javascript grammar handles all four: there is no separate tree-sitter-jsx grammar (unlike TS, where .tsx has its own grammar — handled by @reponova/lang-tsx). Mixing JSX and non-JSX JavaScript files in the same codebase is the common case and is supported transparently by this single plugin.
Configuration
In reponova.yml:
plugins:
javascript:
enabled: true # default: true
# patterns: [] # override global patterns for JS files
# exclude: [] # override global exclude for JS files| Property | Type | Default | Description |
|----------|------|---------|-------------|
| enabled | boolean | true | Enable/disable JavaScript file detection and extraction |
| patterns | string[] | [] | Glob patterns to override global file matching for this plugin |
| exclude | string[] | [] | Glob patterns to override global exclusions for this plugin |
Resolution semantics
- Relative (
./,../) and absolute (/) imports resolve against the file system, trying.js,.mjs,.cjs,.jsx(in that order), thenindex.js/index.mjs/index.cjs/index.jsxfor directory imports. The order matches the Node module-resolution preference: a sibling.jsnext to a.jsxof the same name wins. - Bare specifiers (
react,next/image,@org/pkg) resolve to[]and are treated as external by the host. Package-manager-specific resolution (exportsfield, conditional exports) is not applied at this layer; the host RepoNova resolver is expected to handle that. - Default exports appear in
exportsas the literal string"default"; if the export has a binding (export default function App() {}), that name is also included. - Both ES module
importand CommonJSrequire()produce identicalImportedges, so aFileExtractionfrom a.cjsand a.mjsare graph-compatible. - Call references are recorded by name only. JSX usage
<Card title="…" />is captured as acallsedge from the enclosing function toCard. No prop-flow tracking, no generic instantiation tracking.
License
MIT — see LICENSE.
