Skip to content

bug: shared jsts tree-sitter query includes TypeScript-only node types, fragile for .js files #1654

@rymalia

Description

@rymalia

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

  1. Fragile: Relies on tree-sitter silently ignoring invalid patterns. If tree-sitter changes to fail on unrecognized node types, all .js file parsing breaks.
  2. 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.
  3. 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:

  1. Create a "js" query with only JavaScript-valid patterns (function, class, method, const-func, import, export)
  2. Keep the current query as "ts" with all patterns including interface, type alias, and enum
  3. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions