fix(extraction): visit anonymous function bodies#581
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 933ab1e09a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const body = this.extractor.resolveBody?.(node, this.extractor.bodyField) | ||
| ?? getChildByField(node, this.extractor.bodyField); | ||
| if (body) { | ||
| this.visitFunctionBody(body, ''); |
There was a problem hiding this comment.
Visit variable-assigned callbacks in anonymous module bodies
For anonymous AMD/CommonJS wrappers that define handlers as const handler = () => {} or var handler = function () {}, this branch still drops the handler node: visitFunctionBody only calls extractFunction for nested functions whose extractName is already non-anonymous, and extractName intentionally returns <anonymous> for arrows/function expressions before the parent variable_declarator inference in extractFunction can run. As a result, a common module-scope callback style remains absent from the graph even though function declarations in the new test pass.
Useful? React with 👍 / 👎.
933ab1e to
a380a6d
Compare
|
Updated in a380a6d to address the automated review feedback: visitFunctionBody now delegates nested function nodes to extractFunction, so true anonymous callbacks still have their bodies traversed without creating nodes, while variable-assigned arrow/function-expression callbacks can use the existing parent variable_declarator name inference. I also expanded the AMD/CommonJS regression test to cover const arrow and var function-expression callbacks. |
Summary
Fixes #528.
Root Cause
extractFunction()returned immediately for anonymousfunction_expression/ arrow functions. That avoided noisy<anonymous>symbols, but it also skipped the callback body. For AMD/CommonJS loader callbacks, that meant named functions and calls inside the callback never reached the graph.Testing
npx -y -p node@22 -p npm@10 npm exec -- vitest run __tests__/extraction.test.ts -t 'anonymous AMD'npx -y -p node@22 -p npm@10 npm exec -- vitest run __tests__/extraction.test.tsnpx -y -p node@22 -p npm@10 npm run buildgit diff --check