From 4b23f15ad5f2628bb93b35cf437cf372c6a5ebce Mon Sep 17 00:00:00 2001 From: "erwan.vivien" Date: Sun, 25 Jun 2023 11:41:57 +0200 Subject: [PATCH] fix(#3297): Allow variant skip provides a way to avoid havind this error: only C-Style enums allowed with #[wasm_bindgen] ```rust \#[wasm_bindgen] pub enum Operation { INCREMENT, #[cfg(not(target_arch = "wasm32"))] #[wasm_bindgen(skip)] CUSTOM(fn(i32) -> i32), } ``` --- crates/macro-support/src/parser.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/macro-support/src/parser.rs b/crates/macro-support/src/parser.rs index 9765cddd74c..bf9c1207000 100644 --- a/crates/macro-support/src/parser.rs +++ b/crates/macro-support/src/parser.rs @@ -1298,9 +1298,21 @@ impl<'a> MacroParse<(&'a mut TokenStream, BindgenAttrs)> for syn::ItemEnum { _ => bail_span!(self, "only public enums are allowed with #[wasm_bindgen]"), } + fn skip(attrs: &mut Vec) -> bool { + let Ok(attrs) = BindgenAttrs::find(attrs) else { + return false; + }; + + let result = attrs.skip().is_some(); + attrs.check_used(); + + result + } + let variants = self .variants .iter() + .filter(|v| !skip(&mut (v.attrs).clone())) .enumerate() .map(|(i, v)| { match v.fields {