Capture arrow functions and function expressions as chunks - #17
Merged
Conversation
const Foo = () => {...} and const Foo = function() {...} are the
dominant function-declaration style in modern TS/JS/React codebases,
but JS_FAMILY_QUERY only matched function_declaration/class_declaration/
method_definition - so a repo written entirely in arrow functions would
parse to zero chunks and hit the "no parseable code" early return,
even though the language is fully supported.
- queries.ts: add (variable_declarator value: (arrow_function)) and
(variable_declarator value: (function_expression)) to JS_FAMILY_QUERY.
- extract.ts: getChunkContainer now unwraps the extra
variable_declarator -> lexical_declaration/variable_declaration hop
before checking for a wrapping export_statement, so exported arrow
functions get correct signature/body/doc-comment text and the
`export` keyword is preserved in the chunk body.
Verified via manual extraction against .ts/.tsx/.js fixtures (no test
runner exists yet in this repo): plain/exported/async arrow functions,
function expressions, class methods, and destructuring assignments all
resolve to the right kind/name; a non-function const and a destructured
assignment are correctly excluded. One known edge case: when multiple
declarators share one const/let (`const x = 1, fn = () => {}`), the
chunk's signature/body includes the whole shared declaration line -
acceptable since this pattern is uncommon for function definitions.
Class-field arrow functions (`class C { field = () => {} }`) remain
out of scope, same as before this change.
…tructuring patterns
Subagent review of the arrow-function chunk fix (this branch) found two
real issues beyond what the PR description disclosed:
1. Multi-declarator false-positive staleness + ambiguous embeddings.
For `const a = 1, b = () => {}`, widening the container to the whole
lexical_declaration meant every declarator on the line got an
identical body/signature. Verified consequences: diffFileChunks
reported byte-identical siblings as 'modified' whenever an unrelated
sibling changed (false-positive staleness sent to the LLM), and
chunkEmbeddingText produced indistinguishable vectors for distinct
chunks (ambiguous doc-section linking). Fixed by only widening the
container when the declaration has exactly one declarator
(parent.namedChildCount === 1) - siblings now keep isolated,
accurate bodies instead of bleeding into each other.
2. Destructuring patterns produced garbage chunk ids. `const { a, b }
= () => {}` is syntactically legal but never meaningful in practice;
variable_declarator's name field can be a destructuring pattern
(unlike function_declaration/class_declaration, which never had
this problem). Fixed with a nameNode.type !== 'identifier' guard.
Re-verified via manual extraction (no test runner in this repo yet)
against both new cases plus the full original fixture set - all still
resolve correctly, and packages/action/dist/index.js rebuilt to match.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan