-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for cfg_attr for struct fields #4351
base: main
Are you sure you want to change the base?
Conversation
0fd7da9
to
b172100
Compare
b172100
to
71a9eca
Compare
d84f3d8
to
e1034d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this is a great improvement!
s.attrs.insert( | ||
0, | ||
syn::Attribute { | ||
pound_token: Default::default(), | ||
style: syn::AttrStyle::Outer, | ||
bracket_token: Default::default(), | ||
meta: syn::parse_quote! { | ||
derive(wasm_bindgen::prelude::BindgenedStruct) | ||
}, | ||
}, | ||
); | ||
if !attr.is_empty() { | ||
s.attrs.insert( | ||
1, | ||
syn::Attribute { | ||
pound_token: Default::default(), | ||
style: syn::AttrStyle::Outer, | ||
bracket_token: Default::default(), | ||
meta: syn::parse_quote! { | ||
wasm_bindgen(#attr) | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
let mut tokens = proc_macro2::TokenStream::new(); | ||
s.to_tokens(&mut tokens); | ||
return Ok(tokens); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets just quote here instead.
if !self.generics.params.is_empty() { | ||
bail_span!( | ||
self.generics, | ||
"structs with #[wasm_bindgen] cannot have lifetime or \ | ||
type parameters currently" | ||
); | ||
} | ||
let struct_attrs = BindgenAttrs::find(&mut self.attrs)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let struct_attrs = BindgenAttrs::find(&mut self.attrs)?; | |
let attrs = BindgenAttrs::find(&mut self.attrs)?; |
Lets just keep it as attrs
, or was there a reason for the rename?
@@ -480,6 +480,19 @@ fn renamed_field() { | |||
js_renamed_field(); | |||
} | |||
|
|||
#[cfg_attr( | |||
target_arch = "wasm32", | |||
wasm_bindgen(inspectable, js_name = "ConditionalSkipClass") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasm_bindgen(inspectable, js_name = "ConditionalSkipClass") | |
wasm_bindgen(js_name = "ConditionalSkipClass") |
Or is there some reason this is here?
wasm_bindgen(inspectable, js_name = "ConditionalSkipClass") | ||
)] | ||
pub struct ConditionalSkip { | ||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(skip))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check on the JS side if this is properly applied.
/// cfg_attr annotated field | ||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(getter_with_clone))] | ||
pub needs_clone: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to say in the comment instead that this wouldn't compile otherwise, to explain how we are testing this.
@@ -101,6 +101,7 @@ pub mod prelude { | |||
pub use crate::JsCast; | |||
pub use crate::JsValue; | |||
pub use crate::UnwrapThrowExt; | |||
pub use wasm_bindgen_macro::BindgenedStruct; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets put it in __rt
instead. It shouldn't be visible after all.
style: syn::AttrStyle::Outer, | ||
bracket_token: Default::default(), | ||
meta: syn::parse_quote! { | ||
derive(wasm_bindgen::prelude::BindgenedStruct) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to parse the attributes to extract the #[wasm_bindgen(wasm_bindgen = <path>)]
attribute and use it here.
closes #2703
Overview