mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-13 13:01:22 +00:00
Allow web-sys to emit correct typescript declarations from webidl (#1998)
* Update to emit typescript names * Update to use NamedAnyref * Update incoming / outgoing * Remove added space * Remove comment * Add basic typescript tests for web-sys
This commit is contained in:
@ -181,6 +181,7 @@ pub struct ImportType {
|
||||
pub rust_name: Ident,
|
||||
pub js_name: String,
|
||||
pub attrs: Vec<syn::Attribute>,
|
||||
pub typescript_name: Option<String>,
|
||||
pub doc_comment: Option<String>,
|
||||
pub instanceof_shim: String,
|
||||
pub is_type_of: Option<syn::Expr>,
|
||||
|
@ -579,6 +579,21 @@ impl ToTokens for ast::ImportType {
|
||||
}
|
||||
};
|
||||
|
||||
let description = if let Some(typescript_name) = &self.typescript_name {
|
||||
let typescript_name_len = typescript_name.len() as u32;
|
||||
let typescript_name_chars = typescript_name.chars().map(|c| c as u32);
|
||||
quote! {
|
||||
use wasm_bindgen::describe::*;
|
||||
inform(NAMED_ANYREF);
|
||||
inform(#typescript_name_len);
|
||||
#(inform(#typescript_name_chars);)*
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
JsValue::describe()
|
||||
}
|
||||
};
|
||||
|
||||
let is_type_of = self.is_type_of.as_ref().map(|is_type_of| {
|
||||
quote! {
|
||||
#[inline]
|
||||
@ -611,7 +626,7 @@ impl ToTokens for ast::ImportType {
|
||||
|
||||
impl WasmDescribe for #rust_name {
|
||||
fn describe() {
|
||||
JsValue::describe();
|
||||
#description
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user