diff --git a/crates/backend/src/ast.rs b/crates/backend/src/ast.rs index cf9ab19e..c2249a71 100644 --- a/crates/backend/src/ast.rs +++ b/crates/backend/src/ast.rs @@ -1,3 +1,4 @@ +use proc_macro2::TokenTree; use quote::{ToTokens, Tokens}; use shared; use syn; @@ -757,7 +758,16 @@ impl BindgenAttrs { Some(i) => i, None => return BindgenAttrs::default(), }; - syn::parse(attrs.remove(pos).tts.into()).expect("malformed #[wasm_bindgen] attribute") + let mut tts = attrs.remove(pos).tts.into_iter(); + let tt = match tts.next() { + Some(TokenTree::Group(d)) => d.stream(), + Some(_) => panic!("malformed #[wasm_bindgen] attribute"), + None => return BindgenAttrs::default(), + }; + if tts.next().is_some() { + panic!("malformed #[wasm_bindgen] attribute"); + } + syn::parse(tt.into()).expect("malformed #[wasm_bindgen] attribute") } fn module(&self) -> Option<&str> { @@ -859,11 +869,11 @@ impl BindgenAttrs { impl syn::synom::Synom for BindgenAttrs { named!(parse -> Self, alt!( do_parse!( - opts: parens!(call!( + opts: call!( syn::punctuated::Punctuated::<_, syn::token::Comma>::parse_terminated - )) >> + ) >> (BindgenAttrs { - attrs: opts.1.into_iter().collect(), + attrs: opts.into_iter().collect(), }) ) => { |s| s } | diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index 0377db16..ac9f8632 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -109,6 +109,13 @@ impl ToTokens for ast::Struct { (quote! { impl ::wasm_bindgen::describe::WasmDescribe for #name { fn describe() { + use wasm_bindgen::__wbindgen_if_not_std; + __wbindgen_if_not_std! { + compile_error! { + "exporting a class to JS requires the `std` feature to \ + be enabled in the `wasm-bindgen` crate" + } + } use wasm_bindgen::describe::*; inform(RUST_STRUCT); inform(#name_len); @@ -116,13 +123,6 @@ impl ToTokens for ast::Struct { } } - ::wasm_bindgen::__wbindgen_if_not_std! { - compile_error! { - "exporting a class to JS requires the `std` feature to \ - be enabled in the `wasm-bindgen` crate" - } - } - impl ::wasm_bindgen::convert::IntoWasmAbi for #name { type Abi = u32;