diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/wasm-bindgen-macro/src | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/wasm-bindgen-macro/src')
-rw-r--r-- | vendor/wasm-bindgen-macro/src/lib.rs | 29 | ||||
-rw-r--r-- | vendor/wasm-bindgen-macro/src/worker.js | 1 |
2 files changed, 30 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()) { diff --git a/vendor/wasm-bindgen-macro/src/worker.js b/vendor/wasm-bindgen-macro/src/worker.js new file mode 100644 index 000000000..360d4d429 --- /dev/null +++ b/vendor/wasm-bindgen-macro/src/worker.js @@ -0,0 +1 @@ +// This file is needed for the doctest of `crate::link_to`. |