Skip to content

feat: add TypeScript and JavaScript support via a single language plugin - #21

Merged
MCR-3 merged 1 commit into
mainfrom
18-typescript-javascript
Sep 22, 2026
Merged

MCR-3 merged 1 commit into
mainfrom
18-typescript-javascript

Conversation

@MCR-3

@MCR-3 MCR-3 commented Sep 22, 2026

Copy link
Copy Markdown
Member

Summary

Adds TypeScript and JavaScript reading via one language plugin, backend/languages/typescript.py (tree-sitter based). TS and JS share syntax and routinely import each other, so one plugin reads both - splitting them would silently drop every call edge crossing a .ts/.js boundary, since the dispatcher only hands a plugin its own extensions. Each file and function still keeps its own Language (typescript or javascript), stamped by extension, which drives its badge and highlighting; the dispatcher now lets a plugin set this per file instead of only per plugin (backend/analyzer.py, backend/languages/base.py).

"Untyped" is not a separate mode: a missing annotation is just a None annotation, exactly as an untyped TypeScript parameter already has, and the card omits the return arrow for JS/TS instead of claiming → None.

Closes #18.

What the plugin resolves

  • Functions: declarations; class methods, constructors, static/getter/setter methods, field arrows; named function/arrow expressions; object-literal methods; anonymous default exports (named <file>.default, so two files' defaults stay distinct). Overload/abstract/interface signatures (no body) are skipped.
  • Imports: ESM (relative, named, default, namespace, re-exports, export *) and basic CommonJS (require, module.exports, exports.x). A relative specifier resolves the usual ways (extension-less, directory index, .js finding .ts); anything else resolves only on a unique path-suffix match, since no tsconfig/package.json is read.
  • Calls: plain references, this.m(), Class.staticM(), namespace access, and variable.m() when the variable's class is known (parameter annotation, const x: Foo, new Foo()).
  • Docs: a leading /** */ block becomes the docstring; JSDoc types are not read.

What's intentionally out of reach is documented in the plugin's own docstring: dynamic calls, JSX elements, inheritance, and member chains deeper than one hop. Three follow-up issues are filed for gaps found during implementation: #19 (JSX-as-calls), #20 (one more member-chain hop for injected fields), and a pre-existing Rust crate-root bug surfaced by nesting a src/-less project under a folder (not filed yet - flagging here in case you'd rather I open it too).

Also in this PR

  • SKIP_DIRS gains dist/build; .d.ts and minified files are skipped in both the picker (localFiles.ts) and the plugin.
  • CONTEXT.md: a new Language term, and Language plugin widened to cover a family of related languages that import each other.
  • sample_typescript_project/: a mixed .ts/.tsx/.js/.jsx fixture with imports crossing the TS/JS boundary, used for manual verification.
  • README and CLAUDE.md updated (supported-languages table, verification command, the SKIP_DIRS/skip-file duplication note).

Verification

Done by hand slice-by-slice while implementing (no test suite in this repo):

  • python -m backend.analyzer on sample_project and sample_rust_project: output byte-identical to pre-change (16 functions / 17 edges, 8 / 6).
  • python -m backend.analyzer on sample_typescript_project: 16 functions, 16 edges, no parse errors; cross-language edges (.ts → .js, .js → .ts, .tsx → .jsx) resolve.
  • npm run build and npm run lint in frontend/: both pass.
  • Backend started with uvicorn; GET /api/health and POST /api/analyze exercised directly.
  • FunctionNode rendered through Vite SSR to confirm the → None omission and JSX/TSX Prism highlighting, since a picker-based UI flow can't be automated here.

TS and JS share syntax and routinely import each other, so one Language
plugin (backend/languages/typescript.py) reads both, using tree-sitter-
typescript. Each file and function keeps its own Language, typescript or
javascript, stamped by extension, which drives its badge and highlighting;
the dispatcher now lets a plugin set this per file instead of only per
plugin. Splitting them into two plugins would have silently dropped every
call edge crossing a .ts/.js boundary, since the dispatcher only hands a
plugin its own extensions.

The plugin extracts function declarations, class members (methods,
constructors, static methods, getters/setters, field arrows), named
function/arrow expressions, object-literal methods, and anonymous default
exports (named <file>.default so two files' defaults stay distinct). It
resolves ESM and basic CommonJS imports/exports, and calls through plain
references, this.m(), Class.staticM(), namespace access, and typed
variables/constructors - documented in the plugin's own docstring, along
with what stays out of reach (dynamic calls, JSX, inheritance, deep member
chains).

"Untyped" is not a separate mode: a missing annotation is just a None
annotation, exactly as it already is for an untyped TypeScript parameter,
and the card omits the return arrow for JS/TS rather than claiming None.

Also: SKIP_DIRS gains dist/build, .d.ts and minified files are skipped in
both the picker and the plugin, and CONTEXT.md gets a Language term plus a
widened Language plugin definition to cover a family of related languages.

Closes #18
@MCR-3
MCR-3 merged commit db59c18 into main Sep 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add TypeScript and JavaScript support via a single language plugin

1 participant