esmodules

This commit is contained in:
velzie 2024-07-17 08:06:27 -04:00
parent d433f67d67
commit 862f909624
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
9 changed files with 141 additions and 25 deletions

View file

@ -1,6 +1,9 @@
pub mod rewrite;
use std::str::FromStr;
use rewrite::rewrite;
use url::Url;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
@ -10,15 +13,15 @@ extern "C" {
}
#[wasm_bindgen]
pub fn rewrite_js(js: &str) -> String {
rewrite(js)
pub fn rewrite_js(js: &str, url: &str) -> String {
rewrite(js, Url::from_str(url).unwrap())
}
#[wasm_bindgen]
pub fn rewrite_js_from_arraybuffer(js: &[u8]) -> String {
pub fn rewrite_js_from_arraybuffer(js: &[u8], url: &str) -> String {
// technically slower than the c++ string conversion but it will create *less copies*
let js = unsafe { std::str::from_utf8_unchecked(js) };
rewrite(js)
rewrite(js, Url::from_str(url).unwrap())
}