1#![doc(html_root_url = "https://docs.rs/wasm-bindgen-macro/0.2")]
23extern crate proc_macro;
45use proc_macro::TokenStream;
6use quote::quote;
78/// A list of all the attributes can be found here: https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/index.html
9#[proc_macro_attribute]
10pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
11match wasm_bindgen_macro_support::expand(attr.into(), input.into()) {
12Ok(tokens) => {
13if cfg!(feature = "xxx_debug_only_print_generated_code") {
14println!("{}", tokens);
15 }
16 tokens.into()
17 }
18Err(diagnostic) => (quote! { #diagnostic }).into(),
19 }
20}
2122/// This macro takes a JS module as input and returns a URL that can be used to
23/// access it at runtime.
24///
25/// The module can be specified in a few ways:
26/// - You can use `inline_js = "..."` to create an inline JS file.
27/// - You can use `module = "/foo/bar"` to reference a file relative to the
28/// root of the crate the macro is invoked in.
29///
30/// The returned URL can be used for things like creating workers/worklets:
31/// ```no_run
32/// use web_sys::Worker;
33/// let worker = Worker::new(&wasm_bindgen::link_to!(module = "/src/worker.js"));
34/// ```
35#[proc_macro]
36pub fn link_to(input: TokenStream) -> TokenStream {
37match wasm_bindgen_macro_support::expand_link_to(input.into()) {
38Ok(tokens) => {
39if cfg!(feature = "xxx_debug_only_print_generated_code") {
40println!("{}", tokens);
41 }
42 tokens.into()
43 }
44// This `String::clone` is here so that IDEs know this is supposed to be a
45 // `String` and can keep type-checking the rest of the program even if the macro
46 // fails.
47Err(diagnostic) => (quote! { String::clone(#diagnostic) }).into(),
48 }
49}
5051#[proc_macro_attribute]
52pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream {
53match wasm_bindgen_macro_support::expand_class_marker(attr.into(), input.into()) {
54Ok(tokens) => {
55if cfg!(feature = "xxx_debug_only_print_generated_code") {
56println!("{}", tokens);
57 }
58 tokens.into()
59 }
60Err(diagnostic) => (quote! { #diagnostic }).into(),
61 }
62}
6364#[proc_macro_derive(BindgenedStruct, attributes(wasm_bindgen))]
65pub fn __wasm_bindgen_struct_marker(item: TokenStream) -> TokenStream {
66match wasm_bindgen_macro_support::expand_struct_marker(item.into()) {
67Ok(tokens) => {
68if cfg!(feature = "xxx_debug_only_print_generated_code") {
69println!("{}", tokens);
70 }
71 tokens.into()
72 }
73Err(diagnostic) => (quote! { #diagnostic }).into(),
74 }
75}