feat(metadata): support advanced generics using recursion#763
feat(metadata): support advanced generics using recursion#763moshams272 wants to merge 5 commits intonodejs:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview The new parser supports nested generics, function return types, and more complex union/intersection combinations (including precedence handling and parenthesis stripping), and adds targeted unit tests to lock in these behaviors. It also removes the unused Reviewed by Cursor Bugbot for commit bb43bc8. Bugbot is set up for automated code reviews on this repo. Configure here. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #763 +/- ##
==========================================
- Coverage 78.43% 78.32% -0.12%
==========================================
Files 157 158 +1
Lines 13962 14047 +85
Branches 1152 1169 +17
==========================================
+ Hits 10951 11002 +51
- Misses 3006 3035 +29
- Partials 5 10 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- 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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit bb43bc8. Configure here.
| parseType(returnType, transformType) || `\`<${returnType}>\``; | ||
| return `${params} => ${parsedReturn}`; | ||
| } | ||
| } |
There was a problem hiding this comment.
Arrow function checked first causes wrong operator precedence
Medium Severity
The => handler runs before | and &, giving => the lowest precedence in this top-down recursive parser. For a type like Promise<string> | (err: Error) => void, splitByOuterSeparator splits on => at depth 0, producing params Promise<string> | (err: Error) and return void — treating the whole expression as a single function type. The correct parse is a union of Promise<string> and (err: Error) => void. Any union or intersection appearing before a function arrow at the same nesting level will be swallowed into the parameter side.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit bb43bc8. Configure here.


Description
This PR uses the Recursive approach instead of using Regex that just covered the basic generic and can't handle:
Transformer<T, Awaitable<U>>(str: MyType) => Promise<T>string & number | booleanThe new implementation uses a top-down Recursive approach, breaking down types layer by layer starting from the weakest operators to the strongest.
Validation
transformers.test.mjsnode --run testand 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
node --run testand all tests passed.node --run format&node --run lint.