mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 14:12:13 +00:00
Add support for empty enum variants and enum variants that start with a digit
This commit is contained in:
parent
61b3d52dc9
commit
07b4ef5838
@ -30,6 +30,8 @@ pub fn rust_ident(name: &str) -> Ident {
|
||||
panic!("tried to create empty Ident (from \"\")");
|
||||
} else if is_rust_keyword(name) {
|
||||
Ident::new(&format!("{}_", name), proc_macro2::Span::call_site())
|
||||
} else if name.chars().next().unwrap().is_ascii_digit() {
|
||||
Ident::new(&format!("N{}", name), proc_macro2::Span::call_site())
|
||||
} else {
|
||||
raw_ident(name)
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
These WebIDL files have enum variants that are not valid rust Idents, for example "2x", or "".
|
@ -720,7 +720,13 @@ impl<'a> WebidlParse<()> for webidl::ast::Enum {
|
||||
variants: self
|
||||
.variants
|
||||
.iter()
|
||||
.map(|v| rust_ident(camel_case_ident(&v).as_str()))
|
||||
.map(|v|
|
||||
if !v.is_empty() {
|
||||
rust_ident(camel_case_ident(&v).as_str())
|
||||
} else {
|
||||
rust_ident("None")
|
||||
}
|
||||
)
|
||||
.collect(),
|
||||
variant_values: self.variants.clone(),
|
||||
rust_attrs: vec![parse_quote!(#[derive(Copy, Clone, PartialEq, Debug)])],
|
||||
|
Loading…
x
Reference in New Issue
Block a user