fix(languages): add .mts/.cts extensions and *.spec.tsx test glob to the TypeScript config#455
fix(languages): add .mts/.cts extensions and *.spec.tsx test glob to the TypeScript config#455tirth8205 wants to merge 2 commits into
Conversation
…the TypeScript config The TypeScript LanguageConfig omitted the first-class .mts/.cts module extensions, so those files resolved to null and were skipped by the tree-sitter pipeline. It also listed *.test.tsx but not *.spec.tsx, miscategorizing spec-named TSX test files as regular source. Add .mts/.cts to extensions and *.spec.tsx to the test glob, mirroring the JavaScript config's .mjs/.cjs and test/spec parity. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
thejesh23
left a comment
There was a problem hiding this comment.
A few concerns before this lands.
1. .d.ts (and .d.mts / .d.cts) still skipped. Declaration files are the most common TS-extension outside .ts/.tsx, and getForFile("foo.d.ts") matches on .ts so they already resolve — but the extractor then sees a pure-types file (no runtime exports, no call edges). Worth either explicitly listing .d.ts / .d.mts / .d.cts and gating them out of call-graph extraction, or adding a short comment in the config explaining that .d.ts is intentionally not separated. Otherwise the next person doing this audit lands a third PR.
2. .mts / .cts now route to the plain TS grammar — confirm that's intended. tree-sitter-plugin.ts lines 111-118 hard-code ext === ".tsx" ? "tsx" and falls through to _extensionToLang.get(ext) for everything else. So .mts and .cts will use tree-sitter-typescript.wasm, which is correct (they don't carry JSX). Worth a one-line code comment on that special-case so a future reader doesn't add .mts to the TSX branch by analogy with the .mjs-treated-as-JS pattern.
3. Test glob shape only covers root-level patterns. *.test.tsx / *.spec.tsx are bare globs (no **/ prefix and no __tests__/*.tsx). Vitest's default include is **/*.{test,spec}.?(c|m)[jt]s?(x) and most repos colocate under src/**/__tests__/. Depending on how filePatterns.tests is consumed (couldn't find a hot caller in src/ besides the new test) this may already not match packages/foo/src/__tests__/bar.test.tsx. Worth confirming the matcher is suffix-based, or extending to **/__tests__/*.{ts,tsx} for parity with how the layer-detector already treats __tests__ as a test dir (analyzer/layer-detector.ts:58).
Nit: while you're here, JS config's tests is missing *.test.jsx / *.spec.jsx — same asymmetry you just fixed on the TS side, one config over.
…test patterns - typescript config: comment that .d.ts/.d.mts/.d.cts intentionally fall through to .ts/.mts/.cts as types-only files (no call-graph gating) - tree-sitter-plugin: comment that only .tsx needs the TSX grammar and .mts/.cts deliberately use the plain TS grammar - javascript config: add *.test.jsx / *.spec.jsx for parity with the TS side Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
1. 2. 3. Test glob shape — Not extending the globs. Nit (JS Full core suite green (694 passed); |
Problem
extensions: [".ts", ".tsx"]but omits.mtsand.cts, the first-class TypeScript module file extensions (TS 4.7+, used in ESM/nodenext projects — which this repo itself targets, see PR Fix TypeScript runtime .js import resolution #405/fix(extract-import-map): apply NodeNext .js→.ts rewrite (#294) #359). The JavaScript config correctly includes the analogous.mjsand.cjs. Because LanguageRegistry derives its extension map directly fromconfig.extensions, and TreeSitterPlugin (tree-sitter-plugin.ts lines 66-72) builds_extensionToLangthe same way, a.mtsor.ctsfile resolves to NULL: it is not detected as TypeScript bygetByExtension/getForFileand is skipped entirely by the tree-sitter extraction pipeline. Verified at runtime:getByExtension('.mts')-> NULL,getByExtension('.cts')-> NULL, whilegetByExtension('.mjs')-> 'javascript' andgetByExtension('.cjs')-> 'javascript'. The tree-sitter-typescript grammar parses…tests: ["*.test.ts", "*.spec.ts", "*.test.tsx"]. It covers.test.tsx(the React component test convention) but inconsistently omits*.spec.tsx, even though it covers both.test/.specfor plain.ts. The JavaScript config consistently lists both*.test.jsand*.spec.js. The dashboard package is React + TypeScript and uses.tsxfiles, soComponent.spec.tsxtest files (a common naming style) are not recognized as tests by the file-pattern classifier, while the equivalentComponent.test.tsxis. This causes spec-named TSX test files to be miscategorized as regular source.Fix
Testing
Adds unit test(s) that fail before the change and pass after. The full core test suite,
eslint, andtsc --noEmitall pass locally on this branch.Found via a static correctness audit of the TypeScript language config.
🤖 Generated with Claude Code