Skip to content

Commit

Permalink
fix WASM enum values name collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
tinrab committed Nov 10, 2024
1 parent 4e7a0b6 commit 3068b66
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bomboni_wasm_derive/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,24 +436,25 @@ fn derive_enum_value(options: &WasmOptions) -> syn::Result<TokenStream> {
let ts_decl = TsDeclParser::new(options).parse();
let ts_decl_name = ts_decl.name();

// let mut variants = String::new();
let mut variants = BTreeMap::new();
if let TsDecl::Enum(ts_enum) = &ts_decl {
let mut unique_member_names = BTreeSet::new();
for member in &ts_enum.members {
let member_name = str_to_case(&member.name, Case::Pascal);
let member_type_value = member.alias_type.to_string();
let member_name = str_to_case(&member.name, Case::ScreamingSnake);
let member_value = member.alias_type.to_string();
if !unique_member_names.insert(member_name.clone())
|| !unique_member_names.insert(member_type_value.clone())
|| !unique_member_names.insert(member_value.clone())
{
return Err(syn::Error::new_spanned(
&options.serde_container.ident,
format!("duplicate enum member name: {member_name}"),
));
}

variants.insert(member_name.clone(), member_type_value.clone());
variants.insert(member_type_value, format!("\"{member_name}\""));
variants.insert(member_name.clone(), member_value.clone());
if !variants.contains_key(member_value.trim_matches('"')) {
variants.insert(member_value, member_name);
}
}
}

Expand Down

0 comments on commit 3068b66

Please sign in to comment.