mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 20:41:24 +00:00
Implement a polyfill
attribute for imports
Allow using imported APIs under alternative names, such as prefixed names, for web APIs when the exact API differs across browsers.
This commit is contained in:
@ -185,6 +185,13 @@ impl BindgenAttrs {
|
||||
})
|
||||
}
|
||||
|
||||
fn polyfills(&self) -> impl Iterator<Item = &Ident> {
|
||||
self.attrs.iter().filter_map(|a| match a {
|
||||
BindgenAttr::Polyfill(s) => Some(s),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether the variadic attributes is present
|
||||
fn variadic(&self) -> bool {
|
||||
self.attrs.iter().any(|a| match *a {
|
||||
@ -226,6 +233,7 @@ pub enum BindgenAttr {
|
||||
JsName(String, Span),
|
||||
JsClass(String),
|
||||
Extends(Ident),
|
||||
Polyfill(Ident),
|
||||
Variadic,
|
||||
}
|
||||
|
||||
@ -286,6 +294,10 @@ impl Parse for BindgenAttr {
|
||||
input.parse::<Token![=]>()?;
|
||||
return Ok(BindgenAttr::Extends(input.parse::<AnyIdent>()?.0));
|
||||
}
|
||||
if attr == "polyfill" {
|
||||
input.parse::<Token![=]>()?;
|
||||
return Ok(BindgenAttr::Polyfill(input.parse::<AnyIdent>()?.0));
|
||||
}
|
||||
if attr == "module" {
|
||||
input.parse::<Token![=]>()?;
|
||||
return Ok(BindgenAttr::Module(input.parse::<syn::LitStr>()?.value()));
|
||||
@ -556,6 +568,7 @@ impl ConvertToAst<BindgenAttrs> for syn::ForeignItemType {
|
||||
rust_name: self.ident,
|
||||
js_name,
|
||||
extends: attrs.extends().cloned().collect(),
|
||||
polyfills: attrs.polyfills().cloned().collect(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user