Skip to content

fix(parser): index JavaScript and TypeScript generator functions - #1131

Merged
1 commit merged into
tirth8205:stagingfrom
Enesuygurs:fix/js-generator-functions
Nov 6, 2026
Merged

1 commit merged into
tirth8205:stagingfrom
Enesuygurs:fix/js-generator-functions

Conversation

@Enesuygurs

Copy link
Copy Markdown
Contributor

Linked issue

No issue. This is a small parser fix; the reproduction is below.

What & why

Generator functions in JavaScript, TypeScript and TSX never become graph nodes. Tree-sitter parses function* gen() {} and async function* gen() {} as generator_function_declaration, and parses const gen = function* () {} and obj.gen = function* () {} as generator_function. Neither node type is listed, so a generator gets no Function node and every call inside it is attributed to the file:

export function* ids(start) { yield nextId(start); }
  • before: no node for ids; CALLS a.ts -> nextId
  • after: Function ids, CONTAINS a.ts -> a.ts::ids, CALLS a.ts::ids -> nextId

That leaves sagas, iterators and async streams out of callers_of, impact radius, test gaps and dead code.

  • parser.py: add generator_function_declaration to _FUNCTION_TYPES for javascript, typescript and tsx.
  • parser.py: add generator_function to _JS_FUNC_VALUE_TYPES, which both the variable-assigned and member-assigned function handlers use.

refactor.py already lists both node types, so only the parser was missing them.

How it was tested

  • New TestJsGeneratorFunctions in tests/test_parser.py. It covers declarations in .js, .ts and .tsx, an async generator, and generator expressions assigned to a variable and to a member. All 6 tests fail on staging and pass with this change.
  • pytest tests/test_parser.py tests/test_parser_grammar_contract.py tests/test_multilang.py tests/test_typescript_node_extensions.py tests/test_typescript_declaration_gaps.py tests/test_js_module_resolution.py tests/test_storybook_dead_code.py tests/test_rename_imports.py tests/test_refactor.py. The grammar contract now also checks the new dispatch name. The only failures are the same 33 Windows path-separator failures that staging has without this change.
  • ruff check code_review_graph/: passes.
  • mypy code_review_graph/ --ignore-missing-imports --no-strict-optional: only the existing fcntl.flock errors in daemon.py (Windows).
  • bandit -r code_review_graph/ -c pyproject.toml: passes.

Environment: Windows 10, Python 3.11, dependencies installed with pip from pyproject.toml because uv isn't installed here. I didn't run the full suite.

Checklist

  • Tests added for new functionality
  • All tests pass: uv run pytest tests/ --tb=short -q (I ran targeted suites only; the remaining failures also occur on staging on Windows)
  • Linting passes: uv run ruff check code_review_graph/
  • Type checking passes: uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional (apart from the existing Windows-only daemon.py errors)
  • Lines are at most 100 characters
  • Docs updated where behavior changed (no docs describe the old behavior)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Generator handling skips non-function declarators in mixed declarations, losing the CALLS edge to setup; preserve their traversal and add a regression test.

1 open issue
What changed in this PR

This PR adds JavaScript, TypeScript and TSX generator functions to the code graph, allowing calls inside generators to be attributed to their function nodes.

Changes:

  • Recognizes generator declarations in all three languages.
  • Recognizes generator expressions through shared function-value handling.
  • Adds six regression cases covering declarations, async generators, and variable/member assignments.
File Description
tests/​test_parser.py Adds generator node and call-attribution regression tests.
code_review_graph/​parser.py Registers generator declarations and expressions for function extraction.

Review effort: Balanced


_JS_FUNC_VALUE_TYPES = frozenset(
{"arrow_function", "function_expression", "function"},
{"arrow_function", "function_expression", "function", "generator_function"},
@tirth8205 tirth8205 closed this pull request by merging all changes into tirth8205:staging in 0160eb0 Nov 6, 2026
gowrishacv pushed a commit to gowrishacv/code-review-graph that referenced this pull request Nov 6, 2026
…rth8205#1131)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gowrishacv pushed a commit to gowrishacv/code-review-graph that referenced this pull request Nov 6, 2026
# Conflicts:
#	code_review_graph/parser.py
gowrishacv pushed a commit to gowrishacv/code-review-graph that referenced this pull request Nov 6, 2026
Ruby methods always carry their full lexical scope (tirth8205#933), so the leaf
collision index from tirth8205#1087 now covers Python only, and the docs and tests say
so. Generators are not component wrappers' functions (tirth8205#972 with tirth8205#1131). Partial
graph coverage counts tracked files only (tirth8205#881 with tirth8205#1094). A pending marker
recomputes all derived data (tirth8205#1105), so that test starts from a finished graph,
the deleted-seed case now passes (tirth8205#1062 with tirth8205#673), and hooks.json keeps its
events under a hooks key (tirth8205#1102 with tirth8205#1126).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants