Repository navigation
feat(js): functions that call a method on an imported constant now appear as its callers - #523
Conversation
…pear as its callers
A member call through an import (`LIST.includes(x)` after
`import { LIST } from './constants'`, `store.get(k)`) linked only to a
function, method, class or component, or to a store through `getState`.
It now also links to an imported constant or variable, as upstream does,
so `callers` on a constant lists the functions that use it, not only the
files that import it.
A name a parameter or local hides, and a deeper chain such as
`config.api.fetch()`, still link nothing, and a receiver whose module never
resolves is still not guessed by its method's name.
The seven sync expectations that had moved away from upstream's move back,
four fork-policy expectations in the receiver, parity and resolution tests
now expect the link to the constant, and a new test covers a constant, a
variable, a shadowing parameter and local, and a deeper chain.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
[Medium impact] Changes how method calls on imported constants are resolved. Fix the false links from Svelte template locals before merging. Findings
Fix with agent prompt### Issue 1
codegraph-kernel/src/resolve/method_call.rs:1472-1476
With `import { count } from './stores'`, a `{count.set(1)}` expression inside `{#each rows as count}` uses the loop's `count`, not the import. Template locals have no binding rows, so `bound_receiver_claim` falls back to the script import. Accepting `constant` here creates a false `calls` edge, making callers and impact results misleading.
Account for template-local names before accepting the imported constant, and add a regression test for this case.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryThis PR makes member calls on imported JavaScript-family constants and variables link to those values.
Explicitly deferred by bompus: Static class-member targets, choosing Reviews (1) · Last reviewed commit: "feat(js): functions that call a method o..." · Reviewed by Greptile |
…n the script's import
Calls in Svelte markup have no binding rows, so a name declared by {#each … as x}, {#snippet f(x)}, {#await … then x} or {@const x} resolved to a script import of the same name. The template scan now tracks the names the enclosing blocks declare and skips calls rooted at them. This matters more now that an imported constant takes member calls.
callerson an imported constant now lists the functions that call a method on it.LIST.includes(x)afterimport { LIST } from './constants',store.get(k)through a default import anduseStore.setState()through an aliased one get acallsedge from the calling function to the constant, in JavaScript, TypeScript, Vue, Svelte and Astro. Before, the fork linked a call through an import only to a function, method, class or component (or to a store through itsgetState), so these calls were invisible tocallersandimpact: on supabase,callers safeLocalStoragelists 29 files and no functions in the fork, against 43 functions in upstreambaf19067.Change
One condition in
bound_receiver_claim(codegraph-kernel/src/resolve/method_call.rs, JavaScript/TypeScript branch) accepted a constant or variable only when the method wasgetState. It now accepts one for any method. The guards stay as they were:({ expect }) => expect.getState()) resolves to that binding, not the import, so it links nothing.{#each rows as count},{#snippet item(count)},{#await p then count},{@const count = row}) does not reach the script's import of that name. Markup has no binding rows, so the template scan insrc/extraction/svelte-extractor.tsnow tracks the names the enclosing blocks declare and skips calls rooted at them (found by the Greptile review; it applies to imported functions too). A call after the block closes still links.supabase.auth.signUp()) is refused before the kind check.The seven link expectations in
sync-import-member-retry.test.tsgo back to upstream's. Four more expectations injs-family-receiver-fixes,kernel-resolve-parityandresolutionwere written for the old rule and now expect the link to the constant (each stays unlinked to an unrelated same-named function or class method). A new test,imported-constant-member-calls.test.ts, covers a constant, a variable, a shadowing parameter and local, a deeper chain and the Svelte block forms above; it fails on the base kernel and passes here.Evidence
From a read-only study of the base fork (
5b5ac434) against upstreambaf19067on vite, vitest, svelte and supabase:~utilsaliases andexport *chains that upstream does not); a seeded sample of 49 of those read 49 correct.viandexpectaccount for 1,910 of vitest's links, and 1,217 of vite's land on one Playwrightpagevariable.Checks
On head
178cd22e:npm run build:kernel(clippy-D warnings)npx vitest run(full)kernel-golden-dumpswithUPDATE_GOLDEN=1.dumpchangedeval:precisionvite, vitest, sveltenpx tsc --noEmit,npm run check:agent-docs,readme-sync[]against the two expected links)Index time shows no clear change (vite 4.0 s either way; one run each).
README rows checked
Not covered
TestRunner.getCurrentTest(), all correct in the sample) still needpropertytargets and stay unlinked.referencesrather thancallsfor receivers that are not functions.rows.map((count) => count.set(1))) in Svelte and Astro still resolve to a script import of the same name; the gap already existed for imported functions.Summary by cubic
A member call on an imported constant or variable now links to that constant, so
callerson one lists the functions that use it, not only the files that import it.Before, a call through an import linked only to a function, method, class or component, or to a store through its
getState. NowLIST.includes(x)afterimport { LIST } from './constants',store.get(k)through a default import anduseStore.setState()through an aliased one give the calling function acallsedge to the constant, in JavaScript, TypeScript, Vue, Svelte and Astro.({ expect }) => expect.getState(),{#each rows as count}— a deeper chain likeconfig.api.fetch(), and a receiver whose module never resolves still link nothing.Written for commit 178cd22. Summary will update on new commits.