From f48fdec21e41b10ba98c015b1b0d02c88acda8f6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 4 Apr 2019 09:56:16 -0700 Subject: [PATCH] Fix imported usage of `wasm_bindgen` macro Make sure it refers to `__wasm_bindgen_class_marker` via an absolute path! Closes #1422 --- crates/macro-support/src/parser.rs | 2 +- tests/wasm/classes.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/macro-support/src/parser.rs b/crates/macro-support/src/parser.rs index d94a4680..6ad5172e 100644 --- a/crates/macro-support/src/parser.rs +++ b/crates/macro-support/src/parser.rs @@ -896,7 +896,7 @@ fn prepare_for_impl_recursion( pound_token: Default::default(), style: syn::AttrStyle::Outer, bracket_token: Default::default(), - path: syn::Ident::new("__wasm_bindgen_class_marker", Span::call_site()).into(), + path: syn::parse_quote! { wasm_bindgen::prelude::__wasm_bindgen_class_marker }, tts: quote::quote! { (#class = #js_class) }.into(), }, ); diff --git a/tests/wasm/classes.rs b/tests/wasm/classes.rs index 024848b0..1b0ef953 100644 --- a/tests/wasm/classes.rs +++ b/tests/wasm/classes.rs @@ -459,3 +459,21 @@ pub fn option_class_assert_none(x: Option) { pub fn option_class_assert_some(x: Option) { assert_eq!(x.unwrap().0, 3); } + +mod works_in_module { + use wasm_bindgen::prelude::wasm_bindgen; + + #[wasm_bindgen] + pub struct WorksInModule(u32); + + #[wasm_bindgen] + impl WorksInModule { + #[wasm_bindgen(constructor)] + pub fn new() -> WorksInModule { + WorksInModule(1) + } + + pub fn foo(&self) { + } + } +}