Repository navigation
feat: add TypeScript and JavaScript support via a single language plugin - #21
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/.jsboundary, since the dispatcher only hands a plugin its own extensions. Each file and function still keeps its own Language (typescriptorjavascript), 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
Noneannotation, 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
<file>.default, so two files' defaults stay distinct). Overload/abstract/interface signatures (no body) are skipped.export *) and basic CommonJS (require,module.exports,exports.x). A relative specifier resolves the usual ways (extension-less, directoryindex,.jsfinding.ts); anything else resolves only on a unique path-suffix match, since notsconfig/package.jsonis read.this.m(),Class.staticM(), namespace access, andvariable.m()when the variable's class is known (parameter annotation,const x: Foo,new Foo())./** */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_DIRSgainsdist/build;.d.tsand 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/.jsxfixture with imports crossing the TS/JS boundary, used for manual verification.CLAUDE.mdupdated (supported-languages table, verification command, theSKIP_DIRS/skip-file duplication note).Verification
Done by hand slice-by-slice while implementing (no test suite in this repo):
python -m backend.analyzeronsample_projectandsample_rust_project: output byte-identical to pre-change (16 functions / 17 edges, 8 / 6).python -m backend.analyzeronsample_typescript_project: 16 functions, 16 edges, no parse errors; cross-language edges (.ts→.js,.js→.ts,.tsx→.jsx) resolve.npm run buildandnpm run lintinfrontend/: both pass.GET /api/healthandPOST /api/analyzeexercised directly.FunctionNoderendered through Vite SSR to confirm the→ Noneomission and JSX/TSX Prism highlighting, since a picker-based UI flow can't be automated here.