2018-07-19 14:57:04 -05:00
|
|
|
#![doc(html_root_url = "https://docs.rs/wasm-bindgen-macro/0.2")]
|
|
|
|
|
2017-12-14 19:31:01 -08:00
|
|
|
extern crate proc_macro;
|
|
|
|
extern crate proc_macro2;
|
2018-06-27 22:42:34 -07:00
|
|
|
extern crate syn;
|
2018-07-29 17:59:46 +02:00
|
|
|
extern crate wasm_bindgen_macro_support as macro_support;
|
2017-12-14 19:31:01 -08:00
|
|
|
|
2018-07-29 17:59:46 +02:00
|
|
|
use macro_support::BindgenAttrs;
|
2017-12-14 19:31:01 -08:00
|
|
|
use proc_macro::TokenStream;
|
2018-07-07 10:20:31 -07:00
|
|
|
|
2018-02-07 16:41:33 -08:00
|
|
|
#[proc_macro_attribute]
|
|
|
|
pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
|
2018-03-29 09:14:32 -07:00
|
|
|
let item = syn::parse::<syn::Item>(input.clone()).expect("expected a valid Rust item");
|
2018-07-29 17:59:46 +02:00
|
|
|
let opts = syn::parse::<BindgenAttrs>(attr).expect("invalid arguments to #[wasm_bindgen]");
|
2017-12-14 19:31:01 -08:00
|
|
|
|
2018-07-29 17:59:46 +02:00
|
|
|
let tokens = macro_support::expand(item, opts);
|
2017-12-14 19:31:01 -08:00
|
|
|
|
2018-05-25 16:17:54 -07:00
|
|
|
if cfg!(feature = "xxx_debug_only_print_generated_code") {
|
2018-07-29 17:59:46 +02:00
|
|
|
println!("{}", tokens);
|
2018-05-25 16:17:54 -07:00
|
|
|
}
|
2017-12-14 19:31:01 -08:00
|
|
|
|
2018-07-29 17:59:46 +02:00
|
|
|
tokens.into()
|
2018-02-07 16:41:33 -08:00
|
|
|
}
|