Skip to content

bug(indexer): every JS/TS ES import collapses to a bare module row — named, default and namespace bindings are all lost #1526

Description

@Shashankss1205

tools/languages/javascript.py:436 and tools/languages/typescript.py:413

Import handling starts with:

node.child_by_field_name('import')

import_clause is an unnamed child of import_statement, not a field, so this always returns None and every ES import falls into the bare-module fallback (js :437-440, ts :414-417).

The entire named-import block below it (js :456-465, ts :428-437) is therefore dead code — and would still not work if the lookup were fixed, because it tests the clause against identifier / named_imports / namespace_import, which are children of import_clause, not the clause itself.

Reproduction

$ .venv/bin/python -c "
from codegraphcontext.tools.tree_sitter_parser import TreeSitterParser
from codegraphcontext.tools.languages.javascript import JavascriptTreeSitterParser
import tempfile, pathlib
p = pathlib.Path(tempfile.mkdtemp())/'a.js'
p.write_text(\"import { useState as us, useEffect } from 'react';\n\")
print(JavascriptTreeSitterParser(TreeSitterParser('javascript')).parse(str(p))['imports'])
"
[{'name': 'react', 'source': 'react', 'alias': None, ...}]

One row for the module. useState, the alias us, and useEffect are all lost. Default and namespace (import * as X) imports collapse the same way.

Impact

Beyond the missing binding data, this actively corrupts call resolution. resolution/calls.py:2173-2177 builds:

local_imports = {
    imp.get("alias") or (imp.get("name") or "").split(".")[-1]: imp.get("name")
    ...
}

With alias=None and a relative specifier like ./components/Button, the key becomes "/components/Button" — splitting on . cuts the path, not a module chain. So the identifier Button never maps to its import, and no call to a named ES import can be resolved cross-file. Affects .js, .ts and .tsx — the largest language group in most indexed repos.

Suggested fix

Walk to import_clause as an unnamed child, then read its children (identifier for default, named_importsimport_specifier with optional alias, namespace_import) to emit one row per binding.


Environment
Commit c0e0bed (main)
Python 3.12.3, Linux

Reproduced with the snippet above.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: indexerParsing, discovery, resolution, persistencebugSomething isn't workingseverity: highWrong graph content, data loss, or a broken workflow with no clear signal

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions