use js_sys::{Array, JsString};
use wasm_bindgen::prelude::*;
use web_sys::{Blob, BlobPropertyBag, Url};
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen]
type ImportMeta;
#[wasm_bindgen(method, getter)]
fn url(this: &ImportMeta) -> JsString;
#[wasm_bindgen(js_namespace = import, js_name = meta, thread_local)]
static IMPORT_META: ImportMeta;
}
pub fn on_the_fly(code: &str) -> Result<String, JsValue> {
#[expect(deprecated)]
let header = format!(
"import init, * as bindgen from '{}';\n\n",
IMPORT_META.with(|m| m.url()),
);
Url::create_object_url_with_blob(&Blob::new_with_str_sequence_and_options(
&Array::of2(&JsValue::from(header.as_str()), &JsValue::from(code)),
&{
let props = BlobPropertyBag::new();
props.set_type("text/javascript");
props
},
)?)
}
macro_rules! dependent_module {
($file_name:expr) => {
$crate::dynamic_module::on_the_fly(include_str!($file_name))
};
}
pub(crate) use dependent_module;