Add a feature for printing the macro's generated code (#212)

This commit is contained in:
Nick Fitzgerald
2018-05-25 16:17:54 -07:00
committed by Alex Crichton
parent 4c27c349ea
commit 50b8842b95
3 changed files with 8 additions and 1 deletions

View File

@ -22,6 +22,10 @@ spans = ["wasm-bindgen-macro/spans"]
std = [] std = []
serde-serialize = ["serde", "serde_json", "std"] serde-serialize = ["serde", "serde_json", "std"]
# This is only for debugging wasm-bindgen! No stability guarantees, so enable
# this at your own peril!
xxx_debug_only_print_generated_code = ["wasm-bindgen-macro/xxx_debug_only_print_generated_code"]
[dependencies] [dependencies]
wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.11" } wasm-bindgen-macro = { path = "crates/macro", version = "=0.2.11" }
serde = { version = "1.0", optional = true } serde = { version = "1.0", optional = true }

View File

@ -15,6 +15,7 @@ proc-macro = true
[features] [features]
spans = ["proc-macro2/nightly", "wasm-bindgen-backend/spans"] spans = ["proc-macro2/nightly", "wasm-bindgen-backend/spans"]
xxx_debug_only_print_generated_code = []
[dependencies] [dependencies]
syn = { version = '0.14', features = ['full'] } syn = { version = '0.14', features = ['full'] }

4
crates/macro/src/lib.rs Normal file → Executable file
View File

@ -20,7 +20,9 @@ pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
program.push_item(item, Some(opts), &mut ret); program.push_item(item, Some(opts), &mut ret);
program.to_tokens(&mut ret); program.to_tokens(&mut ret);
// println!("{}", ret); if cfg!(feature = "xxx_debug_only_print_generated_code") {
println!("{}", ret);
}
ret.into() ret.into()
} }