Skip to content

feat: analyze generator functions in JS/TS#435

Open
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/feat-generator-functions-20260702-d66c51fb9a0b926c
Open

feat: analyze generator functions in JS/TS#435
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/feat-generator-functions-20260702-d66c51fb9a0b926c

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist.

Summary

Generator functions (function* foo() {}, async function* foo() {}, and the expression form const g = function* () {}) were completely invisible to the JS/TS complexity analyser. Tree-sitter emits generator_function_declaration and generator_function node types for these constructs, neither of which appeared in any collection, nesting, or naming check.

Root Cause

collectFunctions matched only function_declaration | function_expression | method_definition | arrow_function. Generator node types were silently skipped — their bodies were never traversed, producing zero complexity scores.

Changes to jsLikeAnalyzer.ts

Location Change
collectFunctions isFunctionNode Added generator_function_declaration and generator_function
isNestedFunction Added generator_function (expression form nested inside another function)
getFunctionName Extended childForFieldName("name") branch to cover both generator types
getFunctionReason Added generator_function"generator function expression (nested)"

Not affected: generator class methods (*gen() {}) already produced method_definition nodes and were handled correctly.

async generators: tree-sitter emits generator_function_declaration for async function* foo() {} as well — covered by the same check.

New Tests (6)

  • Top-level function* declaration (JS)
  • async function* declaration (JS)
  • Named generator function expression (JS)
  • Anonymous generator function expression (JS)
  • Generator expression nested inside a regular function — nesting penalty applied (JS)
  • TypeScript generator function with return-type annotation (TS)

Test Status

npm run compile  ✅ (0 errors)
npm run lint     ✅ (0 warnings)
npx mocha out/unit/unit.test.js  ✅ 165 passing (was 159)

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1c6668b751c51af8571f01204ceffb19362e0f66

Generator function declarations (function* foo() {}) and generator
function expressions (const g = function* () {}) were previously
invisible to the complexity analyser — the parser produced
generator_function_declaration and generator_function node types which
were not included in any of the collection or nesting checks.

This commit adds both types to:
- collectFunctions isFunctionNode check (top-level collection)
- isNestedFunction check (nesting penalty when inside another function)
- getFunctionName (name extraction via childForFieldName)
- getFunctionReason (human-readable label in complexity details)

async function* is already covered because tree-sitter emits
generator_function_declaration for it as well.
Generator class methods (*method() {}) were already handled as
method_definition and remain unchanged.

Six new unit tests cover:
- top-level generator function declaration (JS)
- async generator function declaration (JS)
- named generator function expression (JS)
- anonymous generator function expression (JS)
- generator expression nested inside a regular function (JS)
- TypeScript generator function with return-type annotation (TS)

All 165 unit tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@askpt askpt changed the title [repo-assist] feat: analyze generator functions in JS/TS feat: analyze generator functions in JS/TS Jul 2, 2026
@askpt askpt marked this pull request as ready for review July 2, 2026 12:18
Copilot AI review requested due to automatic review settings July 2, 2026 12:18
@askpt askpt self-requested a review as a code owner July 2, 2026 12:18
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.62%. Comparing base (4be010c) to head (3ead4a8).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #435      +/-   ##
==========================================
+ Coverage   78.59%   78.62%   +0.03%     
==========================================
  Files          13       13              
  Lines        4205     4211       +6     
  Branches      469      474       +5     
==========================================
+ Hits         3305     3311       +6     
  Misses        898      898              
  Partials        2        2              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Pull request overview

This PR updates the JS/TS cognitive complexity analyzer to recognize generator functions (declarations and expressions) so they are collected, named, and (for expression forms) treated as nested functions for nesting-penalty purposes, and adds unit tests to prevent regressions.

Changes:

  • Extend JS/TS function collection and naming logic to include generator_function_declaration and generator_function.
  • Treat nested generator expressions as nested functions to apply nesting penalty and include their body complexity in the enclosing function.
  • Add unit tests covering JS and TS generator forms (sync/async, named/anonymous, nested).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/metricsAnalyzer/languages/jsLikeAnalyzer.ts Adds generator node types to function detection, nested-function handling, naming, and nested-function reason text.
src/unit/unit.test.ts Adds a new test suite validating generator function collection and complexity behavior across JS and TS.

Comment thread src/unit/unit.test.ts
Comment on lines +2993 to +2996
// nested generator adds +1 (for the nesting penalty)
// the if inside the generator adds +1 base + 1 nesting = 2
// total outer = 1 (nested generator) + 2 (if inside) = 3
assert.ok(results[0].complexity >= 1, "nested generator should contribute complexity to outer");
if (node.type === "function_declaration" || node.type === "function_expression") {
if (node.type === "function_declaration" || node.type === "function_expression" ||
node.type === "generator_function_declaration" || node.type === "generator_function") {
// Use childForFieldName for O(1) field lookup (tree-sitter exposes "name" for both node types)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant