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:
Bennett Hardwick
2020-02-20 01:14:32 +10:00
committed by GitHub
parent 9d55978af5
commit ec1b9453c9
14 changed files with 140 additions and 6 deletions

View File

@ -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>,

View File

@ -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
}
}