Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughRefined generic angle-bracket tracking in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
test/exports.test.ts (1)
148-161: Good test coverage for the primary fix scenarios.The new tests properly validate the core issue where generics in value expressions were incorrectly parsed. Consider adding a test for nested generics to ensure complete coverage:
💡 Optional: Additional test case for nested generics
"export const nested = new Map<string, Handler<A, B>>()": { type: "declaration", name: "nested", names: ["nested"], },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/exports.test.ts` around lines 148 - 161, Add a test that covers nested generics so the parser won't mis-handle inner generic angle brackets; specifically add a declaration case for a symbol like "nested" using a nested generic value expression such as new Map<string, Handler<A, B>>() (refer to existing test patterns like APP_MODE_MAP, result, and a/b) to ensure the test verifies the parser correctly recognizes "nested" and its names array contains ["nested"] and the type is "declaration".src/analyze.ts (1)
439-451: Pattern change is optional for robustness; edge case does not occur in the current codebase.The fix correctly distinguishes generic syntax from comparison operators by checking if
<is preceded by an identifier character. However, the regex/[A-Za-z_$]/excludes digits, which would theoretically prevent recognition of generics on identifiers ending in numbers (e.g.,Handler2<A, B>,ES6Map<K, V>). A search of the codebase found no existing instances of this pattern, so this is not a practical issue. That said, extending the regex to/[\w$]/or/[A-Za-z0-9_$]/would be a defensive improvement for future-proofing the logic.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/analyze.ts` around lines 439 - 451, The check that decides whether a '<' starts a generic uses the regex /[A-Za-z_$]/ which ignores digits and thus fails for identifiers ending in numbers; update the condition used where inTypeAnnotation and char === "<" and depth === 0 ... (the block manipulating angleDepth, inTypeAnnotation, char, depth, extraNamesStr) to use a character class that includes digits (e.g., use \w or explicitly A-Za-z0-9_$) so identifiers like Handler2<A,B> or ES6Map<K,V> are recognized as generics and angleDepth is incremented correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/analyze.ts`:
- Around line 439-451: The check that decides whether a '<' starts a generic
uses the regex /[A-Za-z_$]/ which ignores digits and thus fails for identifiers
ending in numbers; update the condition used where inTypeAnnotation and char ===
"<" and depth === 0 ... (the block manipulating angleDepth, inTypeAnnotation,
char, depth, extraNamesStr) to use a character class that includes digits (e.g.,
use \w or explicitly A-Za-z0-9_$) so identifiers like Handler2<A,B> or
ES6Map<K,V> are recognized as generics and angleDepth is incremented correctly.
In `@test/exports.test.ts`:
- Around line 148-161: Add a test that covers nested generics so the parser
won't mis-handle inner generic angle brackets; specifically add a declaration
case for a symbol like "nested" using a nested generic value expression such as
new Map<string, Handler<A, B>>() (refer to existing test patterns like
APP_MODE_MAP, result, and a/b) to ensure the test verifies the parser correctly
recognizes "nested" and its names array contains ["nested"] and the type is
"declaration".
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 69a2b080-83f4-4c72-8e3b-240459988f18
📒 Files selected for processing (2)
src/analyze.tstest/exports.test.ts
Use `\w$` instead of `[A-Za-z_$]` so identifiers ending in digits (e.g. `Map2<T>`) are recognized as generics. Add tests for nested generics and digit-ending identifiers.
|
@pi0 Important! I'm sure you know that, but |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/analyze.ts`:
- Around line 454-457: The bug is that the '>' in an arrow token '=>' is
decrementing angleDepth; update the block that handles char === ">" (where
angleDepth is decremented) to ignore '>' when it is part of an arrow token by
checking the previous character (skip decrement if the previous char is '='
indicating '=>'). Locate the code that updates angleDepth (references: variable
angleDepth and the char === ">" branch) and add a guard (e.g., if (prevChar ===
'=') continue) so '=>' does not change angleDepth; keep existing logic for all
other '>' cases unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0f408cf5-ee16-4fbb-a787-067d8abd2d1c
📒 Files selected for processing (2)
src/analyze.tstest/exports.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- test/exports.test.ts
…perands `\w` and `[A-Za-z0-9_$]` both match bare digits, so `1<2` was incorrectly treated as a generic. Walk back to the start of the word and verify it begins with a letter/underscore/$ (valid JS identifier).
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/exports.test.ts (1)
148-175: Optional: add_/$generic opener fixtures to fully lock the heuristic.Since the opener rule allows identifier starts
[A-Za-z_$], consider adding fixtures likeexport const x = _Factory<T>()andexport const y = $Factory<T>()to guard those branches explicitly.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/exports.test.ts` around lines 148 - 175, Add explicit test fixtures that cover generic-openers beginning with '_' and '$' to lock the heuristic: create declarations like variables x and y that call generic factories whose names start with '_' and '$' (e.g., use identifiers x and y and factory names _Factory and $Factory with a generic parameter, such as x = _Factory<T>() and y = $Factory<T>()), and add them alongside the existing export const cases (reference symbols APP_MODE_MAP, result, nested, m) in the same test file so the parser branches for '_' and '$' are exercised.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/exports.test.ts`:
- Around line 148-175: Add explicit test fixtures that cover generic-openers
beginning with '_' and '$' to lock the heuristic: create declarations like
variables x and y that call generic factories whose names start with '_' and '$'
(e.g., use identifiers x and y and factory names _Factory and $Factory with a
generic parameter, such as x = _Factory<T>() and y = $Factory<T>()), and add
them alongside the existing export const cases (reference symbols APP_MODE_MAP,
result, nested, m) in the same test file so the parser branches for '_' and '$'
are exercised.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 65be45c6-f28a-4134-ae59-1fedfcd4c0a7
📒 Files selected for processing (2)
src/analyze.tstest/exports.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/analyze.ts
The `>` in `=>` inside generic type annotations was decrementing angleDepth, causing commas after the arrow to be treated as declaration separators (e.g. `Map<(x: string) => void, string>`).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #341 +/- ##
==========================================
- Coverage 88.04% 83.64% -4.41%
==========================================
Files 8 7 -1
Lines 1062 489 -573
Branches 188 151 -37
==========================================
- Hits 935 409 -526
+ Misses 127 73 -54
- Partials 0 7 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Sorry my clanker's fault! @Flo0806 updated can you double check? (PS we should really soon migrate to ast aware utils in next major!) |
|
Looks good for me. The linked Nuxt issue is also fixed with this ❤️ |
Fixes: nuxt/nuxt#34644
Hi!
findExportsincorrectly extracts type parameters from generic expressions as export names.For
export const APP_MODE_MAP = new Map<string, IAppMode>(), the result wasnames: ["APP_MODE_MAP", "IAppMode"]instead of just["APP_MODE_MAP"].The comma inside
<string, IAppMode>was treated as a declaration separator because angle bracket tracking only kicked in aftera : (type annotation). Generics in value position(new Map<...>, foo<T>(...))were never tracked.The fix: also track
<as a generic opener when preceded by an identifier character ([A-Za-z_$]), which distinguishesMap<T>fromx < y.This caused, as linked, real issues downstream - in Nuxt,
scanDirExportsfrom unimport picked upIAppModeas a value export, which broke type checking when multiple imports.dirs were configured.Tests
Summary by CodeRabbit
Bug Fixes
<now treated as generic openings and>ignores>=-like sequences, fixing comma/classification errors in declaration extraction.Tests