-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add enum const types #3091
base: main
Are you sure you want to change the base?
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
✨ Finishing Touches
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. 🪧 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_enum
fits nicely with your usage in this file.Also applies to: 5-5
26-50
: Ohayo sensei! Simple enum generation workflow looks good.
Thegenerate_simple_enum
function 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_enum
vs.generate_simple_enum
is 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_enum
clarifies 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.
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