Skip to content

Commit c7fc6d3

Browse files
committed
move ImportEnum attributes to a property
1 parent de0ba29 commit c7fc6d3

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

crates/backend/src/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ pub struct ImportEnum {
112112
pub variants: Vec<Ident>,
113113
/// The JS string values of the variants
114114
pub variant_values: Vec<String>,
115+
/// Attributes to apply to the Rust enum
116+
pub rust_attrs: Vec<syn::Attribute>,
115117
}
116118

117119
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]

crates/backend/src/codegen.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ impl ToTokens for ast::ImportEnum {
583583
let expect_string = format!("attempted to convert invalid JSValue into {}", name);
584584
let variants = &self.variants;
585585
let variant_strings = &self.variant_values;
586+
let attrs = &self.rust_attrs;
586587

587588
let mut current_idx: usize = 0;
588589
let variant_indexes: Vec<Literal> = variants
@@ -609,7 +610,7 @@ impl ToTokens for ast::ImportEnum {
609610

610611
(quote! {
611612
#[allow(bad_style)]
612-
#[derive(Copy, Clone, Debug)]
613+
#(#attrs)*
613614
#vis enum #name {
614615
#(#variants = #variant_indexes_ref,)*
615616
}

crates/webidl/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ extern crate heck;
1414
#[macro_use]
1515
extern crate log;
1616
extern crate proc_macro2;
17+
#[macro_use]
1718
extern crate quote;
19+
#[macro_use]
1820
extern crate syn;
1921
extern crate wasm_bindgen_backend as backend;
2022
extern crate webidl;
@@ -640,6 +642,7 @@ impl<'a> WebidlParse<()> for webidl::ast::Enum {
640642
.map(|v| rust_ident(v.to_camel_case().as_str()))
641643
.collect(),
642644
variant_values: self.variants.clone(),
645+
rust_attrs: vec![parse_quote!(#[derive(Copy, Clone, PartialEq, Debug)])],
643646
}),
644647
});
645648

0 commit comments

Comments
 (0)