Skip to content

Commit ac9724a

Browse files
committed
Fixing more problems
1 parent 34f5d34 commit ac9724a

File tree

5 files changed

+180
-187
lines changed

5 files changed

+180
-187
lines changed

crates/macro-support/src/parser.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ impl<'a> MacroParse<BindgenAttrs> for &'a mut syn::ItemImpl {
863863
syn::Type::Path(syn::TypePath {
864864
qself: None,
865865
ref path,
866-
}) => extract_path_ident(path)?,
866+
}) => path,
867867
_ => bail_span!(
868868
self.self_ty,
869869
"unsupported self type in #[wasm_bindgen] impl"
@@ -891,7 +891,7 @@ impl<'a> MacroParse<BindgenAttrs> for &'a mut syn::ItemImpl {
891891
// then go for the rest.
892892
fn prepare_for_impl_recursion(
893893
item: &mut syn::ImplItem,
894-
class: &Ident,
894+
class: &syn::Path,
895895
impl_opts: &BindgenAttrs,
896896
) -> Result<(), Diagnostic> {
897897
let method = match item {
@@ -917,10 +917,12 @@ fn prepare_for_impl_recursion(
917917
other => bail_span!(other, "failed to parse this item as a known item"),
918918
};
919919

920+
let ident = extract_path_ident(class)?;
921+
920922
let js_class = impl_opts
921923
.js_class()
922924
.map(|s| s.0.to_string())
923-
.unwrap_or(class.to_string());
925+
.unwrap_or(ident.to_string());
924926

925927
method.attrs.insert(
926928
0,
@@ -1291,20 +1293,23 @@ fn assert_not_variadic(attrs: &BindgenAttrs) -> Result<(), Diagnostic> {
12911293
Ok(())
12921294
}
12931295

1294-
/// If the path is a single ident, return it.
1296+
/// Extracts the last ident from the path
12951297
fn extract_path_ident(path: &syn::Path) -> Result<Ident, Diagnostic> {
1296-
if path.leading_colon.is_some() {
1297-
bail_span!(path, "global paths are not supported yet");
1298-
}
1299-
if path.segments.len() != 1 {
1300-
bail_span!(path, "multi-segment paths are not supported yet");
1298+
for segment in path.segments.iter() {
1299+
match segment.arguments {
1300+
syn::PathArguments::None => {}
1301+
_ => bail_span!(path, "paths with type parameters are not supported yet"),
1302+
}
13011303
}
1302-
let value = &path.segments[0];
1303-
match value.arguments {
1304-
syn::PathArguments::None => {}
1305-
_ => bail_span!(path, "paths with type parameters are not supported yet"),
1304+
1305+
match path.segments.last() {
1306+
Some(value) => {
1307+
Ok(value.ident.clone())
1308+
},
1309+
None => {
1310+
bail_span!(path, "empty idents are not supported");
1311+
},
13061312
}
1307-
Ok(value.ident.clone())
13081313
}
13091314

13101315
pub fn reset_attrs_used() {

0 commit comments

Comments
 (0)