Skip to content

feat(metadata): support advanced generics using recursion#763

Merged
avivkeller merged 10 commits into
nodejs:mainfrom
moshams272:feat/advanced-generics
May 22, 2026
Merged

feat(metadata): support advanced generics using recursion#763
avivkeller merged 10 commits into
nodejs:mainfrom
moshams272:feat/advanced-generics

Conversation

@moshams272
Copy link
Copy Markdown
Collaborator

Description

This PR uses the Recursive approach instead of using Regex that just covered the basic generic and can't handle:

  • Nested Generics Transformer<T, Awaitable<U>>
  • Function Signature (str: MyType) => Promise<T>
  • Complex Union and Intersection string & number | boolean
  • Depth

The new implementation uses a top-down Recursive approach, breaking down types layer by layer starting from the weakest operators to the strongest.

Validation

  • Added comprehensive test cases in transformers.test.mjs
  • Run node --run test and verified that all test cases (old and new) passed successfully.

Related Issues

This PR acts as an extension to #666. While #666 solved the basic mapping, this implementation introduces a recursive parser to handle more complex nested types.

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

@moshams272 moshams272 requested a review from a team as a code owner April 12, 2026 08:46
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview May 22, 2026 6:41pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 12, 2026

PR Summary

Medium Risk
Replaces regex-based type parsing with a new recursive parser, which could change how type annotations render and link across generated docs for edge-case signatures. Risk is mitigated by expanded unit test coverage but still touches core metadata link generation.

Overview
Improves transformTypeToReferenceLink by replacing the prior regex/split-based generic handling with a new recursive parseType parser that supports nested generics, arrays, arrow-function signatures, and correct | vs & precedence.

Adds TYPE_OPENERS/TYPE_CLOSERS constants for depth-aware parsing, removes the old TYPE_GENERIC_REGEX, and expands unit tests to cover complex nested combinations (functions, destructuring, unions/intersections, and multi-parameter generics).

Reviewed by Cursor Bugbot for commit 560f5bc. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 12, 2026

Codecov Report

❌ Patch coverage is 86.61972% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.80%. Comparing base (3d00fa8) to head (560f5bc).
⚠️ Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
src/generators/metadata/utils/typeParser.mjs 83.89% 36 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #763      +/-   ##
==========================================
+ Coverage   78.43%   82.80%   +4.36%     
==========================================
  Files         157      171      +14     
  Lines       13962    14904     +942     
  Branches     1152     1305     +153     
==========================================
+ Hits        10951    12341    +1390     
+ Misses       3006     2555     -451     
- Partials        5        8       +3     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/generators/metadata/utils/transformers.mjs Outdated
Comment thread src/generators/metadata/utils/transformers.mjs
Comment thread src/generators/metadata/utils/transformers.mjs Outdated
Comment thread src/generators/metadata/utils/transformers.mjs Outdated
Comment thread src/generators/metadata/utils/__tests__/transformers.test.mjs Outdated
Comment thread src/generators/metadata/utils/typeParser.mjs
- Enforce exact TS operator precedence: Arrow functions (=>) before Unions (|) and Intersections (&).

- Implement stripOuterParentheses to unwrap redundant outer groups and prevent parser depth-blindness.

- Fix array loss: safely preserve [] notation for both base types and generics.

- Correctly handle higher-order functions by re-joining subsequent arrow operator segments.
Comment thread src/generators/metadata/utils/typeParser.mjs
Comment thread src/generators/metadata/utils/typeParser.mjs
Comment thread src/generators/metadata/utils/typeParser.mjs Outdated
@avivkeller
Copy link
Copy Markdown
Member

Made a little optimization

@avivkeller avivkeller force-pushed the feat/advanced-generics branch from c3ff2d3 to 560f5bc Compare May 22, 2026 18:40
@avivkeller avivkeller merged commit f97991b into nodejs:main May 22, 2026
21 checks passed
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 560f5bc. Configure here.

start = i + (isArrow ? 2 : 1);
if (isArrow) {
return 1;
} // skip the '>'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dead code: arrow branch in splitByOuterSeparator never reached

Low Severity

The isArrow / separator === '=>' branch in splitByOuterSeparator is dead code. All call sites pass single-character separators: ',', ':', '|', or '&'. The '=>' case in parseType uses direct index-based slicing via op.index instead. This adds unnecessary branching logic and an extra return 1 path that are never exercised, making the function harder to understand.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 560f5bc. Configure here.

@moshams272 moshams272 deleted the feat/advanced-generics branch May 23, 2026 02:00
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.

2 participants