feat: add enum const types - #3091
Conversation
WalkthroughOhayo sensei! This pull request enhances TypeScript enum generation in the Bindgen module. It introduces two new methods— Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Client
participant Gen as TsEnumGenerator
Caller->>Gen: generate(token, buffer)
Gen->>Gen: token_is_custom_enum(token)
alt Custom Enum
Gen->>Gen: generate_custom_enum(token, buffer)
else Simple Enum
Gen->>Gen: generate_simple_enum(token, buffer)
end
Gen-->>Caller: Return TypeScript enum string
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (2)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (11)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/dojo/bindgen/src/plugins/typescript/generator/mod.rs (1)
51-60: Ohayo sensei! Consider recursive checking for multi-level composites.
The current implementation only checks direct children of the token. If you have deeper nesting (e.g., an array of tuples containing composites), you may need a recursive approach to detect them. Otherwise, this is a neat utility.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
crates/dojo/bindgen/src/plugins/typescript/generator/enum.rs(6 hunks)crates/dojo/bindgen/src/plugins/typescript/generator/mod.rs(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build-explorer
🔇 Additional comments (7)
crates/dojo/bindgen/src/plugins/typescript/generator/mod.rs (1)
68-73: Ohayo sensei! Custom enum detection looks solid.
This function correctly identifies custom enums by confirming they have inner composites. The logic is straightforward and consistent with the rest of the code.crates/dojo/bindgen/src/plugins/typescript/generator/enum.rs (6)
2-2: Ohayo sensei! Good job importing necessary utilities.
Addingconvert_case::{Case, Casing}and referencingtoken_is_custom_enum/token_is_enumfits nicely with your usage in this file.Also applies to: 5-5
26-50: Ohayo sensei! Simple enum generation workflow looks good.
Thegenerate_simple_enumfunction neatly uses a string array plus a mapped type. It's an elegant representation for basic enums in TypeScript.
51-85: Ohayo sensei! Custom enum generation is well-structured.
The split between simple and custom enum generation is clear. The template format here is easy to follow, ensuring each variant receives the right type mapping.
87-106: Ohayo sensei! Conditional logic for enum generation is concise.
Usingtoken_is_custom_enumvs.generate_simple_enumis a clean pattern. The short-circuit for non-enum or empty inners is a good safeguard.
184-185: Ohayo sensei! New test block is well-labeled.
Definingtest_custom_enumclarifies the coverage for custom enum generation. This naming convention aids test suite readability.
228-262: Ohayo sensei! The custom enum token creation is nicely structured.
Constructing a composite with multiple nested variants is thorough. This test fixture demonstrates a realistic scenario for verifying custom enum logic.
| fn generate_simple_enum( | ||
| &self, | ||
| token: &Composite, | ||
| buffer: &mut Buffer, |
There was a problem hiding this comment.
This is not used, can be removed if not planned to be re-introduced later.
There was a problem hiding this comment.
I might be wrong but I think this is used L94 underneath BindgenModelGenerator.generate fn ser
| fn generate_custom_enum( | ||
| &self, | ||
| token: &Composite, | ||
| buffer: &mut Buffer, |
There was a problem hiding this comment.
Same here, buffer is not used anymore, can be removed if not planned to be used (or not part of a trait that must be implemented).
55dc93c to
4a69635
Compare
4a69635 to
5afc1ce
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3091 +/- ##
==========================================
- Coverage 57.22% 57.21% -0.01%
==========================================
Files 441 446 +5
Lines 60121 60547 +426
==========================================
+ Hits 34403 34643 +240
- Misses 25718 25904 +186 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
Related issue
Tests
Added to documentation?
Checklist
scripts/prettier.sh,scripts/rust_fmt.sh,scripts/cairo_fmt.sh)scripts/clippy.sh,scripts/docs.sh)Summary by CodeRabbit
New Features
Tests