Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(call-resolver): JS/TS bare call no longer binds to a same-file class method (#4412) (#4518)
Amana64065385fed
diff --git a/packages/core/src/repowise/core/ingestion/call_resolver.py b/packages/core/src/repowise/core/ingestion/call_resolver.pyindex 406115bbe..cb531549c 100644--- a/packages/core/src/repowise/core/ingestion/call_resolver.py+++ b/packages/core/src/repowise/core/ingestion/call_resolver.py@@ -122,6 +122,13 @@ log = structlog.get_logger(__name__)# bare call there is a free function and this tier would resolve it wrongly._IMPLICIT_RECEIVER_LANGUAGES = frozenset({"java", "csharp", "cpp", "kotlin", "apex"})+# JS/TS (and the single-file components parsed as TypeScript): a member is only+# reachable as ``this.foo()`` or ``obj.foo()``, so a bare ``foo()`` inside a+# class method never means a member of that class, whatever the file declares.+_BARE_CALL_SKIPS_MEMBERS_LANGUAGES = frozenset(+ {"javascript", "typescript", "svelte", "vue", "astro"}+)+# Languages where a call the caller's own class cannot answer is looked for on# its ancestors, for an explicit ``self``/``this`` receiver and an implicit one.#@@ -1494,7 +1501,15 @@ class CallResolver(own = self._enclosing_class_method(file_path, call, caller_id)if self._is_anonymous_id(own):return True, _own_member_call(caller_id, own, call)- callee_id = self._file_symbols.get(file_path, {}).get(call.target_name)+ # ``_file_symbols`` is flat and holds class members, but a JS/TS bare+ # call can only name a top-level binding: a same-named method must not+ # shadow an import (or hide a top-level function declared before it).+ table = (+ self._file_top_level+ if self._language_of(file_path) in _BARE_CALL_SKIPS_MEMBERS_LANGUAGES+ else self._file_symbols+ )+ callee_id = table.get(file_path, {}).get(call.target_name)if callee_id is None:return False, Noneif own is not None and own != callee_id and _rivals_a_class_method(callee_id):diff --git a/tests/unit/ingestion/test_call_resolver_strategies.py b/tests/unit/ingestion/test_call_resolver_strategies.pyindex 2e0dba100..aa9dfcb8a 100644--- a/tests/unit/ingestion/test_call_resolver_strategies.py+++ b/tests/unit/ingestion/test_call_resolver_strategies.py@@ -2435,3 +2435,136 @@ class TestPythonNameAliasAssignment:assert len(attributes_symbols) == 2assert len({symbol.id for symbol in attributes_symbols}) == 2+++_JS_TS = [("javascript", "js"), ("typescript", "ts")]+++class TestJsBareCallSkipsClassMembers:+ """A JS/TS bare ``foo()`` never names a class method: that needs ``this.``.++ ``_file_symbols`` is flat and holds class members, so Tier 1 used to bind a+ bare call to a same-named method ahead of the import tier.+ """++ @pytest.mark.parametrize(("lang", "ext"), _JS_TS)+ def test_an_imported_name_beats_a_same_named_method(+ self, tmp_path: Path, lang: str, ext: str+ ) -> None:+ lib, caller = f"a.{ext}", f"b.{ext}"+ parsed = _parse_all(+ tmp_path,+ {+ lib: (lang, "export function getSettings() { return 1; }\n"),+ caller: (+ lang,+ "import { getSettings } from './a';\n"+ "class C {\n"+ " getSettings() { return 2; }\n"+ " load() { return getSettings(); }\n"+ "}\n",+ ),+ },+ )+ _link_imports(parsed, {caller: {imp.module_path: lib for imp in parsed[caller].imports}})+ edges = [+ (callee, origin)+ for src, callee, _, origin in _edges(parsed, tmp_path, {caller: {lib}, lib: set()})+ if src == f"{caller}::C::load"+ ]+ assert edges == [(f"{lib}::getSettings", "import_scoped")]++ @pytest.mark.parametrize(("lang", "ext"), _JS_TS)+ def test_a_method_alone_is_not_a_same_file_bare_call_target(+ self, tmp_path: Path, lang: str, ext: str+ ) -> None:+ """Tier 1 declines; a later tier may still guess, but never as ``same_file``."""+ caller = f"b.{ext}"+ parsed = _parse_all(+ tmp_path,+ {+ caller: (+ lang,+ "class C {\n"+ " getSettings() { return 2; }\n"+ " load() { return getSettings(); }\n"+ "}\n",+ ),+ },+ )+ assert not [+ e+ for e in _edges(parsed, tmp_path)+ if e[1] == f"{caller}::C::getSettings" and e[3] == "same_file"+ ]++ @pytest.mark.parametrize(("lang", "ext"), _JS_TS)+ def test_a_top_level_function_still_resolves_same_file(+ self, tmp_path: Path, lang: str, ext: str+ ) -> None:+ caller = f"b.{ext}"+ parsed = _parse_all(+ tmp_path,+ {+ caller: (+ lang,+ "function helper() { return 1; }\n"+ "class C {\n"+ " load() { return helper(); }\n"+ "}\n",+ ),+ },+ )+ assert (f"{caller}::C::load", f"{caller}::helper", 0.95, "same_file") in _edges(+ parsed, tmp_path+ )++ @pytest.mark.parametrize(("lang", "ext"), _JS_TS)+ def test_a_top_level_function_beats_a_later_same_named_method(+ self, tmp_path: Path, lang: str, ext: str+ ) -> None:+ """The flat index is last-wins; a bare call must still find the top level."""+ caller = f"b.{ext}"+ parsed = _parse_all(+ tmp_path,+ {+ caller: (+ lang,+ "function helper() { return 1; }\n"+ "class C {\n"+ " load() { return helper(); }\n"+ "}\n"+ "class D {\n"+ " helper() { return 3; }\n"+ "}\n",+ ),+ },+ )+ callees = {+ callee for src, callee, _, _ in _edges(parsed, tmp_path) if src == f"{caller}::C::load"+ }+ assert callees == {f"{caller}::helper"}++ @pytest.mark.parametrize(("lang", "ext"), _JS_TS)+ def test_this_call_still_reaches_the_method(+ self, tmp_path: Path, lang: str, ext: str+ ) -> None:+ caller = f"b.{ext}"+ parsed = _parse_all(+ tmp_path,+ {+ caller: (+ lang,+ "class C {\n"+ " getSettings() { return 2; }\n"+ " load() { return this.getSettings(); }\n"+ "}\n",+ ),+ },+ )+ assert (+ f"{caller}::C::load",+ f"{caller}::C::getSettings",+ 0.95,+ "self_scope",+ ) in _edges(parsed, tmp_path)