Use the JS name of an imported type for instanceof checks

This commit is contained in:
Nick Fitzgerald
2018-08-07 16:18:13 -07:00
parent 9104bf87e9
commit 998d37a353
6 changed files with 31 additions and 2 deletions

View File

@ -542,6 +542,9 @@ impl ConvertToAst<BindgenAttrs> for syn::ForeignItemType {
type Target = ast::ImportKind;
fn convert(self, attrs: BindgenAttrs) -> Result<Self::Target, Diagnostic> {
let js_name = attrs
.js_name()
.map_or_else(|| self.ident.to_string(), |s| s.to_string());
let shim = format!("__wbg_instanceof_{}_{}", self.ident, ShortHash(&self.ident));
Ok(ast::ImportKind::Type(ast::ImportType {
vis: self.vis,
@ -549,6 +552,7 @@ impl ConvertToAst<BindgenAttrs> for syn::ForeignItemType {
doc_comment: None,
instanceof_shim: shim,
rust_name: self.ident,
js_name,
extends: attrs.extends().cloned().collect(),
}))
}