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_imports → import_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.
tools/languages/javascript.py:436andtools/languages/typescript.py:413Import handling starts with:
import_clauseis an unnamed child ofimport_statement, not a field, so this always returnsNoneand 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 againstidentifier/named_imports/namespace_import, which are children ofimport_clause, not the clause itself.Reproduction
One row for the module.
useState, the aliasus, anduseEffectare 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-2177builds:With
alias=Noneand a relative specifier like./components/Button, the key becomes"/components/Button"— splitting on.cuts the path, not a module chain. So the identifierButtonnever maps to its import, and no call to a named ES import can be resolved cross-file. Affects.js,.tsand.tsx— the largest language group in most indexed repos.Suggested fix
Walk to
import_clauseas an unnamed child, then read its children (identifierfor default,named_imports→import_specifierwith optionalalias,namespace_import) to emit one row per binding.Environment
c0e0bed(main)Reproduced with the snippet above.