fix(extraction): index TS/JS generator function declarations and expressions (#1741) (#1743)

Tree-sitter kinds generator_function_declaration / generator_function were
missing from both the wasm and native kernel function-type lists, so
function* / async function* (and const g = function* () {}) produced no
nodes. Add the kinds on both paths and cover TS+JS declaration/expression
forms in extraction tests.

Co-authored-by: Colby McHenry <colbymchenry@users.noreply.github.com>
This commit is contained in:
Colby Mchenry
2026-09-07 23:43:33 -05:00
committed by GitHub
co-authored by Colby McHenry
parent 72869f2d9e
commit df435d50d1
6 changed files with 67 additions and 10 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ import type { LanguageExtractor } from '../tree-sitter-types';
import { classifyTsClassMember } from './typescript';
export const javascriptExtractor: LanguageExtractor = {
functionTypes: ['function_declaration', 'arrow_function', 'function_expression'],
functionTypes: ['function_declaration', 'generator_function_declaration', 'arrow_function', 'function_expression', 'generator_function'],
classTypes: ['class_declaration'],
methodTypes: ['method_definition', 'field_definition'],
// JS `field_definition` ≙ TS `public_field_definition`: plain fields are
+1 -1
View File
@@ -39,7 +39,7 @@ export function classifyTsClassMember(node: SyntaxNode): 'method' | 'property' {
}
export const typescriptExtractor: LanguageExtractor = {
functionTypes: ['function_declaration', 'arrow_function', 'function_expression'],
functionTypes: ['function_declaration', 'generator_function_declaration', 'arrow_function', 'function_expression', 'generator_function'],
classTypes: ['class_declaration', 'abstract_class_declaration'],
methodTypes: ['method_definition', 'public_field_definition'],
classifyMethodNode: classifyTsClassMember,
+3 -3
View File
@@ -171,7 +171,7 @@ function extractNameRaw(node: SyntaxNode, source: string, extractor: LanguageExt
// not from identifiers in their body. Without this, single-expression arrow
// functions like `const fn = () => someIdentifier` get named "someIdentifier"
// instead of "fn", because the fallback below finds the body identifier.
if (node.type === 'arrow_function' || node.type === 'function_expression') {
if (node.type === 'arrow_function' || node.type === 'function_expression' || node.type === 'generator_function') {
return '<anonymous>';
}
@@ -1556,7 +1556,7 @@ export class TreeSitterExtractor {
if (
!nameOverride &&
name === '<anonymous>' &&
(node.type === 'arrow_function' || node.type === 'function_expression')
(node.type === 'arrow_function' || node.type === 'function_expression' || node.type === 'generator_function')
) {
const parent = node.parent;
if (parent?.type === 'variable_declarator') {
@@ -2623,7 +2623,7 @@ export class TreeSitterExtractor {
}
const name = getNodeText(nameNode, this.source);
// Arrow functions / function expressions: extract as function instead of variable
if (valueNode && (valueNode.type === 'arrow_function' || valueNode.type === 'function_expression')) {
if (valueNode && (valueNode.type === 'arrow_function' || valueNode.type === 'function_expression' || valueNode.type === 'generator_function')) {
this.extractFunction(valueNode);
continue;
}