Treat .mts/.cts (TypeScript module extensions) as TypeScript#1607
Closed
ashmitg wants to merge 1 commit into
Closed
Treat .mts/.cts (TypeScript module extensions) as TypeScript#1607ashmitg wants to merge 1 commit into
ashmitg wants to merge 1 commit into
Conversation
`.mts` (ESM) and `.cts` (CommonJS) are the TypeScript counterparts of the already-supported `.mjs`/`.cjs`, but graphify handled them in neither the code-extension detection nor the TypeScript grammar path — so they were either skipped entirely (classified as non-code) or, once detected, parsed with the plain JavaScript grammar, which silently drops every `type`/`interface`/type-alias declaration. Detection — add `.mts`/`.cts` alongside their siblings in: - detect.CODE_EXTENSIONS (the code / non-code gate) - analyze._LANG_FAMILY (cross-language edge family → "js") - extract._JS_RESOLVE_EXTS (import target resolution) - extract._JS_CACHE_BYPASS_SUFFIXES - build.py per-node language map (→ "js") TypeScript grammar — route `.mts`/`.cts` to the plain TypeScript grammar (like `.ts`; neither is JSX), so their TS-only syntax is captured: - extract_js() (grammar selector: .mts/.cts → _TS_CONFIG) - extract._DISPATCH (.mts/.cts → extract_js) - the use_ts tree-sitter selector - the typescript_member_calls resolver frozenset Result: a `.mts`/`.cts` file now extracts identically to the equivalent `.ts`. Verified on a real 47 KB `.mts` source — 36 nodes for `.mts`/`.cts`, matching `.ts` exactly (was 22 with the JS grammar; the 14 dropped nodes were TS type/interface declarations). No new dependency — same tree-sitter-typescript grammar as `.ts`. Tests: tests/test_typescript_module_extensions.py — membership regression locks for the extension sets, dispatch routing, and end-to-end parity asserting `.mts`/`.cts` capture the TS `type`/`interface` nodes and match the `.ts` node set. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8702b07 to
0c64a3a
Compare
safishamsi
added a commit
that referenced
this pull request
Jul 2, 2026
Collaborator
|
Merged into |
safishamsi
added a commit
that referenced
this pull request
Jul 4, 2026
The "What files it handles" code row omitted several extensions that reuse existing tree-sitter grammars (so the grammar count is unchanged): `.mts`/`.cts` (TypeScript, #1607, new in 0.9.6), `.cc`/`.cxx` (C++), `.kts` (Kotlin), `.psd1` (PowerShell), `.toc` (Lua). Apex (`.cls`/`.trigger`) and Terraform already have their own rows. `.r`/`.ejs`/`.ets` are intentionally left out — they are in CODE_EXTENSIONS but have no registered extractor. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
.mts(ESM) and.cts(CommonJS) — the TypeScript counterparts of the already-supported.mjs/.cjs— were handled in neither graphify's code-extension detection nor its TypeScript grammar path. Two compounding effects:CODE_EXTENSIONS, so.mts/.ctsfiles were classified as non-code and never extracted..ts/.tsx, so.mts/.ctsfell back to the plain JavaScript grammar, which silently drops everytype/interface/ type-alias.Real impact: on a TypeScript repo whose tooling/config layer is
.mts(files run undertsx/ts-node), those files were dropped from the graph — and where detected, their type surface vanished.Fix — treat
.mts/.ctsas TypeScript everywhere.tsis handledDetection (add alongside
.mjs/.cjs/.ts):detect.pyCODE_EXTENSIONS— the code/non-code gateanalyze.py_LANG_FAMILY→"js"extract.py_JS_RESOLVE_EXTS,_JS_CACHE_BYPASS_SUFFIXESbuild.py"js"TypeScript grammar (
.mts/.ctsare non-JSX → the plain TypeScript grammar, like.ts):extract_js()grammar selector.mts/.cts→_TS_CONFIG_DISPATCH.mts/.cts→extract_jsuse_tstree-sitter selector.mts/.ctstypescript_member_callsresolver.mts/.ctsSame
tree-sitter-typescriptgrammar as.ts→ no new dependency.Result (verified on a real 47 KB
.mtsfile).mts/.ctsnow extract identically to.ts— 36 nodes each, vs 22 under the JS grammar. The 14 recovered nodes are exactly the TStype/interface/type-alias declarations the JS grammar was dropping.Tests
tests/test_typescript_module_extensions.py:_DISPATCHrouting, and.mts/.ctssource with atypealias +interfacecaptures those TS-only nodes and produces the same node set as the equivalent.ts.Verified locally (Python 3.12,
uv run --frozen):ruffclean · new tests 6/6 ·skillgen --checkOK (134 artifacts) · broader JS/TS + detection + multilang suites 578 passed, 24 skipped, 0 regressions.Note
.cjsis in thebuild.py/analyze.pyJS maps but not indetect.CODE_EXTENSIONS(only.mjsis), so.cjs-only files may be detected as non-code too. Kept this PR scoped to.mts/.cts; happy to fold.cjsin if you'd like.🤖 Generated with Claude Code