From 389eb8b8d38605309b4cd72d9b40de24b3eb882b Mon Sep 17 00:00:00 2001 From: dakshcodez Date: Sat, 15 Aug 2026 19:01:55 +0530 Subject: [PATCH 1/3] Capture arrow functions and function expressions as chunks 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. --- packages/core/src/parsing/extract.ts | 18 ++++++++++++++---- packages/core/src/parsing/queries.ts | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/core/src/parsing/extract.ts b/packages/core/src/parsing/extract.ts index 94decb7..099e1f0 100644 --- a/packages/core/src/parsing/extract.ts +++ b/packages/core/src/parsing/extract.ts @@ -40,11 +40,21 @@ function findEnclosingClassName(node: Node, classNodeType: string): string | nul } function getChunkContainer(declNode: Node): Node { - const parent = declNode.parent; - if (parent && parent.type === 'export_statement') { - return parent; + let container = declNode; + + // `const foo = () => {}` captures the `variable_declarator`, but the + // declaration keyword (and any `export`) lives one or two levels up. + const parent = container.parent; + if (parent && (parent.type === 'lexical_declaration' || parent.type === 'variable_declaration')) { + container = parent; + } + + const grandparent = container.parent; + if (grandparent && grandparent.type === 'export_statement') { + container = grandparent; } - return declNode; + + return container; } function extractSignature(container: Node): string { diff --git a/packages/core/src/parsing/queries.ts b/packages/core/src/parsing/queries.ts index 9da64bc..22ec102 100644 --- a/packages/core/src/parsing/queries.ts +++ b/packages/core/src/parsing/queries.ts @@ -2,6 +2,8 @@ export const JS_FAMILY_QUERY = ` (function_declaration) @chunk (class_declaration) @chunk (method_definition) @chunk +(variable_declarator value: (arrow_function)) @chunk +(variable_declarator value: (function_expression)) @chunk `; export const PYTHON_QUERY = ` From 9d0b30850ff45ea52880b55890273e8e81372793 Mon Sep 17 00:00:00 2001 From: dakshcodez Date: Sat, 15 Aug 2026 19:05:06 +0530 Subject: [PATCH 2/3] Rebuild Action bundle with the arrow-function chunk fix --- packages/action/dist/index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/action/dist/index.js b/packages/action/dist/index.js index 5b6a255..3ad84fc 100644 --- a/packages/action/dist/index.js +++ b/packages/action/dist/index.js @@ -203644,6 +203644,8 @@ var JS_FAMILY_QUERY = ` (function_declaration) @chunk (class_declaration) @chunk (method_definition) @chunk +(variable_declarator value: (arrow_function)) @chunk +(variable_declarator value: (function_expression)) @chunk `; var PYTHON_QUERY = ` (function_definition) @chunk @@ -203686,11 +203688,16 @@ function findEnclosingClassName(node, classNodeType) { return null; } function getChunkContainer(declNode) { - const parent = declNode.parent; - if (parent && parent.type === "export_statement") { - return parent; + let container = declNode; + const parent = container.parent; + if (parent && (parent.type === "lexical_declaration" || parent.type === "variable_declaration")) { + container = parent; } - return declNode; + const grandparent = container.parent; + if (grandparent && grandparent.type === "export_statement") { + container = grandparent; + } + return container; } function extractSignature(container) { const text = container.text; From b239703a24fd63ae22144a001531c69466b7ec1b Mon Sep 17 00:00:00 2001 From: dakshcodez Date: Sat, 15 Aug 2026 19:16:13 +0530 Subject: [PATCH 3/3] Fix findings from subagent review: sibling-declarator leakage and destructuring 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. --- packages/action/dist/index.js | 4 ++-- packages/core/src/parsing/extract.ts | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/action/dist/index.js b/packages/action/dist/index.js index 3ad84fc..0e64167 100644 --- a/packages/action/dist/index.js +++ b/packages/action/dist/index.js @@ -203690,7 +203690,7 @@ function findEnclosingClassName(node, classNodeType) { function getChunkContainer(declNode) { let container = declNode; const parent = container.parent; - if (parent && (parent.type === "lexical_declaration" || parent.type === "variable_declaration")) { + if (parent && (parent.type === "lexical_declaration" || parent.type === "variable_declaration") && parent.namedChildCount === 1) { container = parent; } const grandparent = container.parent; @@ -203741,7 +203741,7 @@ async function extractChunksFromSource(source, filePath, grammar) { continue; const declNode = capture.node; const nameNode = declNode.childForFieldName("name"); - if (!nameNode) + if (!nameNode || nameNode.type !== "identifier") continue; const kind = resolveKind(declNode, grammar); const className = kind === "method" ? findEnclosingClassName(declNode, classNodeType) : null; diff --git a/packages/core/src/parsing/extract.ts b/packages/core/src/parsing/extract.ts index 099e1f0..ea66fb7 100644 --- a/packages/core/src/parsing/extract.ts +++ b/packages/core/src/parsing/extract.ts @@ -44,8 +44,16 @@ function getChunkContainer(declNode: Node): Node { // `const foo = () => {}` captures the `variable_declarator`, but the // declaration keyword (and any `export`) lives one or two levels up. + // Skip the widen when siblings share the statement (`const a = 1, b = () => {}`) + // - otherwise every declarator on the line would get an identical + // body/signature, causing false-positive staleness on unrelated siblings + // and indistinguishable embedding text. const parent = container.parent; - if (parent && (parent.type === 'lexical_declaration' || parent.type === 'variable_declaration')) { + if ( + parent && + (parent.type === 'lexical_declaration' || parent.type === 'variable_declaration') && + parent.namedChildCount === 1 + ) { container = parent; } @@ -107,7 +115,9 @@ export async function extractChunksFromSource( if (capture.name !== 'chunk') continue; const declNode = capture.node; const nameNode = declNode.childForFieldName('name'); - if (!nameNode) continue; + // `variable_declarator`'s name field can be a destructuring pattern + // (`const { a, b } = () => {}`) - not a real declaration name, skip it. + if (!nameNode || nameNode.type !== 'identifier') continue; const kind = resolveKind(declNode, grammar); const className = kind === 'method' ? findEnclosingClassName(declNode, classNodeType) : null;