Skip to content

Commit

Permalink
fix: typescript plugin for non struct fields (#1608)
Browse files Browse the repository at this point in the history
* fix: typescript plugin for non struct fields

* fix: primitive type arg in system

* chore: fmt
  • Loading branch information
Larkooo authored Mar 5, 2024
1 parent f90a71a commit cf095de
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions crates/dojo-bindgen/src/plugins/typescript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,25 @@ export function defineContractComponents(world: World) {
.inputs
.iter()
.map(|arg| {
let token = arg.1.to_composite().unwrap();
// r#type doesnt seem to be working rn.
// instead, we can take a look at our
// handled tokens db
let token =
handled_tokens.iter().find(|t| t.type_name() == token.type_name()).unwrap();

match token.r#type {
CompositeType::Struct => token
.inners
.iter()
.map(|field| format!("props.{}.{}", arg.0, field.name))
.collect::<Vec<String>>()
.join(",\n "),
_ => {
format!("props.{}", arg.0)
let token = &arg.1;
let type_name = &arg.0;

match handled_tokens.iter().find(|t| t.type_name() == token.type_name()) {
Some(t) => {
// Need to flatten the struct members.
match t.r#type {
CompositeType::Struct => t
.inners
.iter()
.map(|field| format!("props.{}.{}", type_name, field.name))
.collect::<Vec<String>>()
.join(",\n "),
_ => {
format!("props.{}", type_name)
}
}
}
None => format!("props.{}", type_name),
}
})
.collect::<Vec<String>>()
Expand Down

0 comments on commit cf095de

Please sign in to comment.