Handle the possibility that the class name is in its own Group (#2159)

* Handle the possibility that the class name is in its own Group

rust-lang/rust#72388 makes this happen

* Handle Groups in more places

* fmt!

* Add some functions to handle Groups

As suggested by @alexcrichton [here](https://gist.github.com/alexcrichton/3c93ab2547d45d9caa3b72309cd4262b).
This commit is contained in:
Rahul Butani
2020-05-26 15:08:56 -05:00
committed by GitHub
parent cf45d5b24a
commit 3dd8f3d2ac
2 changed files with 28 additions and 13 deletions

View File

@ -43,10 +43,7 @@ pub fn wasm_bindgen_test(
}
}
}
let ident = match body.next() {
Some(TokenTree::Ident(token)) => token,
_ => panic!("expected a function name"),
};
let ident = find_ident(&mut body).expect("expected a function name");
let mut tokens = Vec::<TokenTree>::new();
@ -78,3 +75,13 @@ pub fn wasm_bindgen_test(
tokens.into_iter().collect::<TokenStream>().into()
}
fn find_ident(iter: &mut token_stream::IntoIter) -> Option<Ident> {
match iter.next()? {
TokenTree::Ident(i) => Some(i),
TokenTree::Group(g) if g.delimiter() == Delimiter::None => {
find_ident(&mut g.stream().into_iter())
}
_ => None,
}
}