Description
The smart-explore / smart-file-read parser uses a single "jsts" tree-sitter query for JavaScript, TypeScript, and TSX files. This query includes three TypeScript-only node types that don't exist in the tree-sitter-javascript grammar:
interface_declaration
type_alias_declaration
enum_declaration
Source: src/services/smart-file-read/parser.ts lines 322–333 (query definition) and 490–495 (getQueryKey() mapping all three languages to "jsts")
Current Behavior
When parsing .js files, the full jsts query (including TS-only patterns) is compiled against tree-sitter-javascript. Tree-sitter currently silently ignores unmatched patterns, so this works in practice — JS files parse fine and the valid patterns (functions, classes, methods, imports, exports) match correctly.
Why This Is a Problem
- Fragile: Relies on tree-sitter silently ignoring invalid patterns. If tree-sitter changes to fail on unrecognized node types, all
.js file parsing breaks.
- Silent failure: The
runBatchQuery error handler catches all exceptions and returns an empty Map, so a compilation failure would silently return zero results with no logging.
- Confusing: The shared query name
"jsts" doesn't document why TypeScript-only patterns are included for a grammar that can't match them.
Proposed Fix
Split the query into separate js and ts entries:
- Create a
"js" query with only JavaScript-valid patterns (function, class, method, const-func, import, export)
- Keep the current query as
"ts" with all patterns including interface, type alias, and enum
- Update
getQueryKey() to map "javascript" → "js" and "typescript" / "tsx" → "ts"
Originally Flagged By
CodeRabbit automated review on PR #1491 (final review pass, outside-diff comment on mcp-server.cjs).
Description
The
smart-explore/smart-file-readparser uses a single"jsts"tree-sitter query for JavaScript, TypeScript, and TSX files. This query includes three TypeScript-only node types that don't exist in thetree-sitter-javascriptgrammar:interface_declarationtype_alias_declarationenum_declarationSource:
src/services/smart-file-read/parser.tslines 322–333 (query definition) and 490–495 (getQueryKey()mapping all three languages to"jsts")Current Behavior
When parsing
.jsfiles, the fulljstsquery (including TS-only patterns) is compiled againsttree-sitter-javascript. Tree-sitter currently silently ignores unmatched patterns, so this works in practice — JS files parse fine and the valid patterns (functions, classes, methods, imports, exports) match correctly.Why This Is a Problem
.jsfile parsing breaks.runBatchQueryerror handler catches all exceptions and returns an emptyMap, so a compilation failure would silently return zero results with no logging."jsts"doesn't document why TypeScript-only patterns are included for a grammar that can't match them.Proposed Fix
Split the query into separate
jsandtsentries:"js"query with only JavaScript-valid patterns (function, class, method, const-func, import, export)"ts"with all patterns including interface, type alias, and enumgetQueryKey()to map"javascript"→"js"and"typescript"/"tsx"→"ts"Originally Flagged By
CodeRabbit automated review on PR #1491 (final review pass, outside-diff comment on
mcp-server.cjs).