wasm_bindgen_macro/
lib.rs1#![doc(html_root_url = "https://docs.rs/wasm-bindgen-macro/0.2")]
2#![cfg_attr(
3 wasm_bindgen_unstable_test_coverage,
4 feature(allow_internal_unstable),
5 allow(internal_features)
6)]
7
8extern crate proc_macro;
9
10use proc_macro::TokenStream;
11use quote::quote;
12
13#[proc_macro_attribute]
14#[cfg_attr(
15 wasm_bindgen_unstable_test_coverage,
16 allow_internal_unstable(coverage_attribute)
17)]
18pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
19 match wasm_bindgen_macro_support::expand(attr.into(), input.into()) {
20 Ok(tokens) => {
21 if cfg!(feature = "xxx_debug_only_print_generated_code") {
22 println!("{}", tokens);
23 }
24 tokens.into()
25 }
26 Err(diagnostic) => (quote! { #diagnostic }).into(),
27 }
28}
29
30#[proc_macro]
44#[cfg_attr(
45 wasm_bindgen_unstable_test_coverage,
46 allow_internal_unstable(coverage_attribute)
47)]
48pub fn link_to(input: TokenStream) -> TokenStream {
49 match wasm_bindgen_macro_support::expand_link_to(input.into()) {
50 Ok(tokens) => {
51 if cfg!(feature = "xxx_debug_only_print_generated_code") {
52 println!("{}", tokens);
53 }
54 tokens.into()
55 }
56 Err(diagnostic) => (quote! { String::clone(#diagnostic) }).into(),
60 }
61}
62
63#[proc_macro_attribute]
64#[cfg_attr(
65 wasm_bindgen_unstable_test_coverage,
66 allow_internal_unstable(coverage_attribute)
67)]
68pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
69 match wasm_bindgen_macro_support::expand_class_marker(attr.into(), input.into()) {
70 Ok(tokens) => {
71 if cfg!(feature = "xxx_debug_only_print_generated_code") {
72 println!("{}", tokens);
73 }
74 tokens.into()
75 }
76 Err(diagnostic) => (quote! { #diagnostic }).into(),
77 }
78}