From 5df8e20815ba90dbe3a13655b751dd56458a7f8d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 3 Oct 2018 00:04:43 -0700 Subject: [PATCH] Parse `Path`s in `extends` attributes Closes #916 --- crates/backend/src/ast.rs | 2 +- crates/backend/src/defined.rs | 2 +- crates/macro-support/src/parser.rs | 6 +++--- crates/webidl/src/lib.rs | 11 +++++++---- tests/wasm/jscast.rs | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/backend/src/ast.rs b/crates/backend/src/ast.rs index 2b4a2d395..b4d58cf3f 100644 --- a/crates/backend/src/ast.rs +++ b/crates/backend/src/ast.rs @@ -143,7 +143,7 @@ pub struct ImportType { pub attrs: Vec, pub doc_comment: Option, pub instanceof_shim: String, - pub extends: Vec, + pub extends: Vec, pub vendor_prefixes: Vec, } diff --git a/crates/backend/src/defined.rs b/crates/backend/src/defined.rs index b1a1442cb..9f466581d 100644 --- a/crates/backend/src/defined.rs +++ b/crates/backend/src/defined.rs @@ -288,7 +288,7 @@ impl ImportedTypes for ast::ImportType { { f(&self.rust_name, ImportedTypeKind::Definition); for class in self.extends.iter() { - f(class, ImportedTypeKind::Reference); + class.imported_types(f); } } } diff --git a/crates/macro-support/src/parser.rs b/crates/macro-support/src/parser.rs index 3947b005f..459bbd1fb 100644 --- a/crates/macro-support/src/parser.rs +++ b/crates/macro-support/src/parser.rs @@ -178,7 +178,7 @@ impl BindgenAttrs { } /// Return the list of classes that a type extends - fn extends(&self) -> impl Iterator { + fn extends(&self) -> impl Iterator { self.attrs.iter().filter_map(|a| match a { BindgenAttr::Extends(s) => Some(s), _ => None, @@ -232,7 +232,7 @@ pub enum BindgenAttr { Readonly, JsName(String, Span), JsClass(String), - Extends(Ident), + Extends(syn::Path), VendorPrefix(Ident), Variadic, } @@ -292,7 +292,7 @@ impl Parse for BindgenAttr { } if attr == "extends" { input.parse::()?; - return Ok(BindgenAttr::Extends(input.parse::()?.0)); + return Ok(BindgenAttr::Extends(input.parse()?)); } if attr == "vendor_prefix" { input.parse::()?; diff --git a/crates/webidl/src/lib.rs b/crates/webidl/src/lib.rs index 48b8270d1..3c7720f90 100644 --- a/crates/webidl/src/lib.rs +++ b/crates/webidl/src/lib.rs @@ -126,8 +126,11 @@ fn parse(webidl_source: &str, allowed_types: Option<&[&str]>) -> Result // `AsRef` and such implementations. for import in program.imports.iter_mut() { if let backend::ast::ImportKind::Type(t) = &mut import.kind { - t.extends - .retain(|n| first_pass_record.builtin_idents.contains(n) || filter(&n.to_string())); + t.extends.retain(|n| { + let ident = &n.segments.last().unwrap().value().ident; + first_pass_record.builtin_idents.contains(ident) || + filter(&ident.to_string()) + }); } } @@ -515,8 +518,8 @@ impl<'src> FirstPassRecord<'src> { self.append_required_features_doc(&import_type, &mut doc_comment, extra); import_type.extends = self .all_superclasses(name) - .map(|name| Ident::new(&name, Span::call_site())) - .chain(Some(Ident::new("Object", Span::call_site()))) + .map(|name| Ident::new(&name, Span::call_site()).into()) + .chain(Some(Ident::new("Object", Span::call_site()).into())) .collect(); import_type.doc_comment = doc_comment; diff --git a/tests/wasm/jscast.rs b/tests/wasm/jscast.rs index e62c5deee..4e94176d5 100644 --- a/tests/wasm/jscast.rs +++ b/tests/wasm/jscast.rs @@ -19,7 +19,7 @@ extern "C" { #[wasm_bindgen(constructor)] fn new() -> JsCast3; - #[wasm_bindgen(extends = JsCast1, extends = JsCast3)] + #[wasm_bindgen(extends = ::jscast::JsCast1, extends = JsCast3)] type JsCast4; #[wasm_bindgen(constructor)] fn new() -> JsCast4;