mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-16 23:50:02 -04:00
clippy + refactor out config parsing
This commit is contained in:
parent
aa218770c7
commit
3d1b5b4c09
2 changed files with 22 additions and 56 deletions
|
@ -29,31 +29,26 @@ fn create_encode_function(encode: Function) -> EncodeFn {
|
|||
})
|
||||
}
|
||||
|
||||
fn get_str(config: &Object, k: &str) -> String {
|
||||
Reflect::get(config, &k.into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn get_config(config: Object) -> Config {
|
||||
Config {
|
||||
prefix: get_str(&config, "prefix"),
|
||||
encode: create_encode_function(Reflect::get(&config, &"encode".into()).unwrap().into()),
|
||||
wrapfn: get_str(&config, "wrapfn"),
|
||||
importfn: get_str(&config, "importfn"),
|
||||
rewritefn: get_str(&config, "rewritefn"),
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn rewrite_js(js: &str, url: &str, config: Object) -> Vec<u8> {
|
||||
rewrite(
|
||||
js,
|
||||
Url::from_str(url).unwrap(),
|
||||
Config {
|
||||
prefix: Reflect::get(&config, &"prefix".into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap(),
|
||||
encode: create_encode_function(Reflect::get(&config, &"encode".into()).unwrap().into()),
|
||||
wrapfn: Reflect::get(&config, &"wrapfn".into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap(),
|
||||
importfn: Reflect::get(&config, &"importfn".into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap(),
|
||||
rewritefn: Reflect::get(&config, &"rewritefn".into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap(),
|
||||
},
|
||||
)
|
||||
rewrite(js, Url::from_str(url).unwrap(), get_config(config))
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
@ -61,27 +56,5 @@ pub fn rewrite_js_from_arraybuffer(js: &[u8], url: &str, config: Object) -> Vec<
|
|||
// we know that this is a valid utf-8 string
|
||||
let js = unsafe { std::str::from_utf8_unchecked(js) };
|
||||
|
||||
rewrite(
|
||||
js,
|
||||
Url::from_str(url).unwrap(),
|
||||
Config {
|
||||
prefix: Reflect::get(&config, &"prefix".into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap(),
|
||||
encode: create_encode_function(Reflect::get(&config, &"encode".into()).unwrap().into()),
|
||||
wrapfn: Reflect::get(&config, &"wrapfn".into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap(),
|
||||
importfn: Reflect::get(&config, &"importfn".into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap(),
|
||||
rewritefn: Reflect::get(&config, &"rewritefn".into())
|
||||
.unwrap()
|
||||
.as_string()
|
||||
.unwrap(),
|
||||
},
|
||||
)
|
||||
rewrite(js, Url::from_str(url).unwrap(), get_config(config))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue