-
Notifications
You must be signed in to change notification settings - Fork 182
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
fix: bindgen nested types init generation #2580
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -124,13 +124,14 @@ impl From<&Composite> for JsDefaultValue { | |||||||||||||||||||||||||||||||||||
JsDefaultValue(format!("{}.{}", value.type_name(), value.inners[0].name)) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
cainome::parser::tokens::CompositeType::Struct => JsDefaultValue(format!( | ||||||||||||||||||||||||||||||||||||
"{{ {} }}", | ||||||||||||||||||||||||||||||||||||
"{{ fieldOrder: [{}], {} }}", | ||||||||||||||||||||||||||||||||||||
value.inners.iter().map(|i| format!("'{}'", i.name)).collect::<Vec<_>>().join(", "), | ||||||||||||||||||||||||||||||||||||
value | ||||||||||||||||||||||||||||||||||||
.inners | ||||||||||||||||||||||||||||||||||||
.iter() | ||||||||||||||||||||||||||||||||||||
.map(|i| format!("{}: {},", i.name, JsDefaultValue::from(&i.token))) | ||||||||||||||||||||||||||||||||||||
.collect::<Vec<_>>() | ||||||||||||||||||||||||||||||||||||
.join("\n") | ||||||||||||||||||||||||||||||||||||
.join(" ") | ||||||||||||||||||||||||||||||||||||
Comment on lines
+127
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohayo sensei! Test case needs updating to match new format. The implementation now uses space-separated fields, but the test case Update the test case to match the new format: let expected = "{
\t\t\tfieldOrder: ['field1', 'field2', 'field3'],
-\t\t\tfield1: 0,
-\t\t\tfield2: 0,
-\t\t\tfield3: 0,
+\t\t\tfield1: 0, field2: 0, field3: 0,
\t\t}";
🛠️ Refactor suggestion Consider maintaining newline separation for better readability. The change to space-separated fields makes the output more compact but potentially harder to read, especially for structs with many fields or complex nested types. Consider keeping the newline separation for better readability: - .join(" ")
+ .join("\n\t\t\t") 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||
)), | ||||||||||||||||||||||||||||||||||||
_ => JsDefaultValue::from(value.type_name().as_str()), | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
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.
Ohayo sensei! Fix inconsistent casing in fieldOrder array.
The field 'tokenmetadata' in the fieldOrder array uses lowercase, while the actual field is defined as 'tokenMetadata'. This inconsistency could cause field matching issues.
Apply this fix:
📝 Committable suggestion