diff options
Diffstat (limited to 'vendor/wasm-bindgen-macro/src/lib.rs')
-rw-r--r-- | vendor/wasm-bindgen-macro/src/lib.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/wasm-bindgen-macro/src/lib.rs b/vendor/wasm-bindgen-macro/src/lib.rs index c677aaf24..fbae81875 100644 --- a/vendor/wasm-bindgen-macro/src/lib.rs +++ b/vendor/wasm-bindgen-macro/src/lib.rs @@ -18,6 +18,35 @@ pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream { } } +/// This macro takes a JS module as input and returns a URL that can be used to +/// access it at runtime. +/// +/// The module can be specified in a few ways: +/// - You can use `inline_js = "..."` to create an inline JS file. +/// - You can use `module = "/foo/bar"` to reference a file relative to the +/// root of the crate the macro is invoked in. +/// +/// The returned URL can be used for things like creating workers/worklets: +/// ```no_run +/// use web_sys::Worker; +/// let worker = Worker::new(&wasm_bindgen::link_to!(module = "/src/worker.js")); +/// ``` +#[proc_macro] +pub fn link_to(input: TokenStream) -> TokenStream { + match wasm_bindgen_macro_support::expand_link_to(input.into()) { + Ok(tokens) => { + if cfg!(feature = "xxx_debug_only_print_generated_code") { + println!("{}", tokens); + } + tokens.into() + } + // This `String::clone` is here so that IDEs know this is supposed to be a + // `String` and can keep type-checking the rest of the program even if the macro + // fails. + Err(diagnostic) => (quote! { String::clone(#diagnostic) }).into(), + } +} + #[proc_macro_attribute] pub fn __wasm_bindgen_class_marker(attr: TokenStream, input: TokenStream) -> TokenStream { match wasm_bindgen_macro_support::expand_class_marker(attr.into(), input.into()) { |