feat(metadata): support advanced generics using recursion#763
feat(metadata): support advanced generics using recursion#763moshams272 wants to merge 9 commits intonodejs:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Removes the old Reviewed by Cursor Bugbot for commit 0115291. 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% 77.91% -0.52%
==========================================
Files 157 160 +3
Lines 13962 14236 +274
Branches 1152 1181 +29
==========================================
+ Hits 10951 11092 +141
- Misses 3006 3135 +129
- Partials 5 9 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| const input = | ||
| '(str: MyType) => Promise<Map<string, number & string>, Map<string | number>>'; | ||
| const expected = | ||
| '(str: MyType) => [`<Promise>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[`<Map>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)<[`<string>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type), [`<number>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type) & [`<string>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type)>, [`<Map>`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map)<[`<string>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type) | [`<number>`](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type)>>'; |
There was a problem hiding this comment.
MyType should be handled, no?
There was a problem hiding this comment.
Yes, Parsing individual types inside the parameter string (handling colons, commas, optional params ?, etc.) requires a much deeper level of AST-like parsing and I focused on generics and left the parameter string for now as I will open another PR soon to handle this.
There was a problem hiding this comment.
Just wanted to drop a quick update: regarding your question about myType not being parsed, I went ahead and implemented the function signature parsing.
- 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 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d343adb. Configure here.
| const result = transformType(cleanType); | ||
| if (cleanType.length && result) { | ||
| return `[\`<${cleanType}>\`](${result})${isArray ? '[]' : ''}`; | ||
| } |
There was a problem hiding this comment.
Array type link text formatting changed from old behavior
Low Severity
For plain array types like string[], the old code produced link text <string[]> (with [] inside the link), but the new base-case logic uses cleanType (with [] stripped) in the link text and appends [] outside. This changes rendered documentation output from [`<string[]>`](URL) to [`<string>`](URL)[], making the array brackets unlinked. The old code used trimmedPiece (which preserved []) in the Markdown link template.
Reviewed by Cursor Bugbot for commit d343adb. Configure here.
There was a problem hiding this comment.
I think <string>[] is better than <string[]> as the link is just on word string!
…is stripping, and implement function signature parsing


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.