mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-22 17:21:35 +00:00
webidl: add support for typedefs
This commit is contained in:
@ -10,6 +10,7 @@ pub struct Program {
|
||||
pub imports: Vec<Import>,
|
||||
pub enums: Vec<Enum>,
|
||||
pub structs: Vec<Struct>,
|
||||
pub type_aliases: Vec<TypeAlias>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
|
||||
@ -120,6 +121,13 @@ pub enum TypeLocation {
|
||||
ExportRet,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
|
||||
pub struct TypeAlias {
|
||||
pub vis: syn::Visibility,
|
||||
pub dest: Ident,
|
||||
pub src: syn::Type,
|
||||
}
|
||||
|
||||
impl Program {
|
||||
pub fn push_item(
|
||||
&mut self,
|
||||
|
@ -59,6 +59,9 @@ impl ToTokens for ast::Program {
|
||||
for e in self.enums.iter() {
|
||||
e.to_tokens(tokens);
|
||||
}
|
||||
for a in self.type_aliases.iter() {
|
||||
a.to_tokens(tokens);
|
||||
}
|
||||
|
||||
// Generate a static which will eventually be what lives in a custom section
|
||||
// of the wasm executable. For now it's just a plain old static, but we'll
|
||||
@ -823,3 +826,15 @@ impl ToTokens for ast::ImportStatic {
|
||||
}).to_tokens(into);
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for ast::TypeAlias {
|
||||
fn to_tokens(&self, into: &mut TokenStream) {
|
||||
let vis = &self.vis;
|
||||
let dest = &self.dest;
|
||||
let src = &self.src;
|
||||
(quote! {
|
||||
#[allow(non_camel_case_types)]
|
||||
#vis type #dest = #src;
|
||||
}).to_tokens(into);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user