Skip to content

fix(extraction): index const-bound functions inside a body as symbols - #1679

Open
danusha2345 wants to merge 1 commit into
colbymchenry:mainfrom
danusha2345:fix/1669-declarator-bound-nested-functions
Open

fix(extraction): index const-bound functions inside a body as symbols#1679
danusha2345 wants to merge 1 commit into
colbymchenry:mainfrom
danusha2345:fix/1669-declarator-bound-nested-functions

Conversation

@danusha2345

Copy link
Copy Markdown
Contributor

Fixes #1669.

Problem

const handleClear = () => {…} inside a component — every React handler written without useCallback — was never a symbol. The body walker names nested function declarations and hook-bound arrows (const x = useCallback(…)), but a plain declarator-bound arrow or function expression fell through, so the handler was absent from callers / callees / impact ("Symbol not found", which reads exactly like "no callers") and its calls attributed to the component. The same declaration at module scope already names a function.

Change

  • Body walker (wasm) and kernel: an anonymous arrow_function / function_expression that is the whole value of a variable_declarator with a plain identifier name is extracted as a function, contained by the enclosing one, with its own calls. extractFunction already resolves the name from the declarator. A destructuring binding, an inline JSX arrow and a non-function value stay as they were. JS family only.
  • torture.tsx gains the shape so kernel-tsjs-parity pins both arms.

Graph shape

A navigation such a handler makes is now the handler's own navigates edge, and the handler is a hop in the Screens via chain — the shape a useCallback handler already has (see the Next.js test's navs(sym('handleSubmit')) and push.via). The react-router and expo-router expectations are updated to that convention; the screen still reaches the handler through its onSubmit={…} reference and the links resolve as before, with the trigger now visible in Steps.

Verification

  • New __tests__/nested-declarator-functions.test.ts: arrow, function expression and let-bound arrow become Widget::name functions with their own calls and containment; a value, a destructuring and an inline arrow do not; Python is untouched.
  • npm run build:kernel && npm run build, full suite with CODEGRAPH_KERNEL_EXPECT=1: 237 files, 4233 passed, 9 skipped.

Re-index after upgrading to pick up the new symbols.

🤖 Generated with Claude Code

…colbymchenry#1669)

`const handleClear = () => {…}` inside a component — every React handler
that skips useCallback — was never a symbol: the body walker only named
nested function declarations and hook-bound arrows, so the handler was
absent from callers/impact ("Symbol not found", indistinguishable from
"no callers") and its calls attributed to the component. Bind the arrow
or function expression to its declarator the way module scope already
does, in both the wasm walker and the kernel.

A navigation such a handler makes is now the handler's own edge and a hop
in the Screens `via` chain — the shape a useCallback handler already has —
so the react-router and expo-router expectations follow that convention.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Function-valued consts inside a function body are never indexed (React handlers invisible to callers/impact)

1 participant