Skip to content

feat: name anonymous function expressions from assignment and object context - #515

Merged
askpt merged 4 commits into
mainfrom
repo-assist/improve-anon-fn-assignment-naming-20260807-1c46293e37c60b64
Aug 9, 2026
Merged

feat: name anonymous function expressions from assignment and object context#515
askpt merged 4 commits into
mainfrom
repo-assist/improve-anon-fn-assignment-naming-20260807-1c46293e37c60b64

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Task 5 — Coding Improvement: When a function_expression or generator_function has no internal name, the analyzer now infers a human-readable name from the parent AST context instead of always falling back to (anonymous).

New name inference rules

Pattern Before After
{ getData: function() {} } (anonymous) getData
{ getStream: function*() {} } (anonymous) getStream
exports.bar = function() {} (anonymous) bar
obj.method = function() {} (anonymous) method
handler = function() {} (anonymous) handler
(function() {})() (IIFE) (anonymous) (anonymous) ✅ unchanged
{ getData: function inner() {} } inner inner ✅ unchanged

This mirrors the existing behaviour for arrow_function, which already resolves names via variable_declarator and pair parent nodes. The change makes CodeLens output consistent regardless of whether a developer uses arrow syntax or the function keyword in object literals and CommonJS module patterns.

Implementation

In jsLikeAnalyzer.ts, after childForFieldName("name") returns null for anonymous function_expression/generator_function, the code now checks:

  1. pair parent ({ key: function() {} }): use the key if it is a property_identifier or identifier
  2. assignment_expression parent (x = function() {}): use the property name for member_expression left-hand side, or the identifier name for a simple identifier

Test Status

npm run compile  ✅  (0 errors)
npm run lint     ✅  (0 warnings)
npm run test:unit → 207 passing (was 203), 0 failing

Adds 4 new tests covering all new naming cases. Coverage: jsLikeAnalyzer.ts 100% statements, 97.41% branches (was 98.14%).

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.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@42c2ab5b4e4c9273534c39259b2e0df7f20f07e9

…context

When a function_expression or generator_function has no internal name,
infer the name from the parent AST context:

- { getData: function() {} }  → 'getData'  (pair parent, identifier key)
- exports.bar = function() {} → 'bar'       (assignment, member_expression)
- handler = function() {}     → 'handler'  (assignment, identifier)

This mirrors the existing arrow_function behaviour (which already resolves
names via variable_declarator and pair parent nodes) and makes CodeLens
output consistent regardless of whether a developer writes a function
expression or an arrow function in object literals and module patterns.

Named function expressions (e.g. { getData: function inner() {} }) and
IIFE patterns (e.g. (function() {})()) are unaffected.

Adds 4 new tests covering all new cases; 207 tests pass, lint clean.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@askpt askpt changed the title [repo-assist] feat: name anonymous function expressions from assignment and object context feat: name anonymous function expressions from assignment and object context Aug 8, 2026
@askpt

askpt commented Aug 8, 2026

Copy link
Copy Markdown
Owner

@copilot resolve the merge conflicts in this pull request

…non-fn-assignment-naming-20260807-1c46293e37c60b64

# Conflicts:
#	src/metricsAnalyzer/languages/jsLikeAnalyzer.ts

Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>

Copilot AI commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in commit 0c5ee01. The conflict in jsLikeAnalyzer.ts was between the comment style — main had the pair handling with a slightly different comment, while this PR added the assignment_expression block. The resolved version keeps both the updated comment and the assignment_expression logic.

Copilot AI requested a review from askpt August 8, 2026 14:57
@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.76%. Comparing base (f24d2a8) to head (6f801ad).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #515      +/-   ##
==========================================
+ Coverage   81.68%   81.76%   +0.07%     
==========================================
  Files          13       13              
  Lines        4367     4386      +19     
  Branches      445      449       +4     
==========================================
+ Hits         3567     3586      +19     
  Misses        799      799              
  Partials        1        1              

☔ 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.

@askpt
askpt marked this pull request as ready for review August 9, 2026 09:14
Copilot AI balanced review requested due to automatic review settings August 9, 2026 09:14

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

Adds contextual naming for anonymous JavaScript/TypeScript function and generator expressions.

Changes:

  • Infers names from object properties and assignment targets.
  • Adds unit tests for contextual naming scenarios.

Reviewed changes

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

File Description
src/metricsAnalyzer/languages/jsLikeAnalyzer.ts Adds assignment-based name inference.
src/unit/unit.test.ts Adds naming behavior tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/metricsAnalyzer/languages/jsLikeAnalyzer.ts
Comment thread src/unit/unit.test.ts Outdated
Comment thread src/unit/unit.test.ts Outdated
Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
@askpt
askpt merged commit d18d79b into main Aug 9, 2026
10 checks passed
@askpt
askpt deleted the repo-assist/improve-anon-fn-assignment-naming-20260807-1c46293e37c60b64 branch August 9, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants