mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-16 07:30:02 -04:00
add more flags
This commit is contained in:
parent
7adf76d37f
commit
4d1b7ef1b8
10 changed files with 85 additions and 57 deletions
21
rewriter/Cargo.lock
generated
21
rewriter/Cargo.lock
generated
|
@ -1360,19 +1360,20 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.92"
|
||||
version = "0.2.93"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
|
||||
checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.92"
|
||||
version = "0.2.93"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
|
||||
checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
|
@ -1385,9 +1386,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.92"
|
||||
version = "0.2.93"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
|
||||
checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
|
@ -1395,9 +1396,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.92"
|
||||
version = "0.2.93"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
|
||||
checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -1408,9 +1409,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.92"
|
||||
version = "0.2.93"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
|
||||
checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
|
|
|
@ -37,6 +37,10 @@ fn get_obj(obj: &JsValue, k: &str) -> JsValue {
|
|||
Reflect::get(obj, &k.into()).unwrap()
|
||||
}
|
||||
|
||||
fn get_bool(obj: &JsValue, k: &str) -> bool {
|
||||
Reflect::get(obj, &k.into()).unwrap().as_bool().unwrap()
|
||||
}
|
||||
|
||||
fn get_str(obj: &JsValue, k: &str) -> String {
|
||||
Reflect::get(obj, &k.into()).unwrap().as_string().unwrap()
|
||||
}
|
||||
|
@ -44,6 +48,7 @@ fn get_str(obj: &JsValue, k: &str) -> String {
|
|||
fn get_config(scramjet: &Object) -> Config {
|
||||
let codec = &get_obj(scramjet, "codec");
|
||||
let config = &get_obj(scramjet, "config");
|
||||
let flags = &get_obj(config, "flags");
|
||||
|
||||
Config {
|
||||
prefix: get_str(config, "prefix"),
|
||||
|
@ -53,6 +58,8 @@ fn get_config(scramjet: &Object) -> Config {
|
|||
rewritefn: get_str(config, "rewritefn"),
|
||||
metafn: get_str(config, "metafn"),
|
||||
setrealmfn: get_str(config, "setrealmfn"),
|
||||
|
||||
capture_errors: get_bool(flags, "captureErrors"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,6 +120,7 @@ fn dorewrite(source_text: &str) -> String {
|
|||
rewritefn: "$rewrite".to_string(),
|
||||
metafn: "$meta".to_string(),
|
||||
setrealmfn: "$setrealm".to_string(),
|
||||
capture_errors: true,
|
||||
},
|
||||
)
|
||||
.as_slice(),
|
||||
|
|
|
@ -43,6 +43,8 @@ pub struct Config {
|
|||
pub setrealmfn: String,
|
||||
pub metafn: String,
|
||||
pub encode: EncodeFn,
|
||||
|
||||
pub capture_errors: bool,
|
||||
}
|
||||
|
||||
impl Rewriter {
|
||||
|
@ -206,13 +208,15 @@ impl<'a> Visit<'a> for Rewriter {
|
|||
fn visit_try_statement(&mut self, it: &oxc_ast::ast::TryStatement<'a>) {
|
||||
// for debugging we need to know what the error was
|
||||
|
||||
if let Some(h) = &it.handler {
|
||||
if let Some(name) = &h.param {
|
||||
if let Some(name) = name.pattern.get_identifier() {
|
||||
self.jschanges.push(JsChange::GenericChange {
|
||||
span: Span::new(h.body.span.start + 1, h.body.span.start + 1),
|
||||
text: format!("$scramerr({});", name),
|
||||
});
|
||||
if self.config.capture_errors {
|
||||
if let Some(h) = &it.handler {
|
||||
if let Some(name) = &h.param {
|
||||
if let Some(name) = name.pattern.get_identifier() {
|
||||
self.jschanges.push(JsChange::GenericChange {
|
||||
span: Span::new(h.body.span.start + 1, h.body.span.start + 1),
|
||||
text: format!("$scramerr({});", name),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue