mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 06:20:02 -04:00
add try statement catching
This commit is contained in:
parent
ca1574fccc
commit
58f6a4330a
4 changed files with 40 additions and 13 deletions
|
@ -6,6 +6,10 @@ edition = "2021"
|
|||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[features]
|
||||
default = ["debug"]
|
||||
debug = []
|
||||
|
||||
[profile.speed]
|
||||
inherits = "release"
|
||||
opt-level = 3
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
use oxc_allocator::Allocator;
|
||||
use oxc_ast::{
|
||||
ast::{AssignmentTarget, Expression, IdentifierReference, ObjectPropertyKind},
|
||||
ast::{
|
||||
AssignmentTarget, BindingPattern, BindingPatternKind, Expression, IdentifierReference,
|
||||
ObjectPropertyKind,
|
||||
},
|
||||
visit::walk,
|
||||
Visit,
|
||||
};
|
||||
|
@ -144,6 +147,22 @@ impl<'a> Visit<'a> for Rewriter {
|
|||
// do not walk further, we don't want to rewrite the identifiers
|
||||
}
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
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),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_object_expression(&mut self, it: &oxc_ast::ast::ObjectExpression<'a>) {
|
||||
for prop in &it.properties {
|
||||
#[allow(clippy::single_match)]
|
||||
|
|
|
@ -82,4 +82,8 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
window.$scramerr = function scramerr(e) {
|
||||
console.error("CAUGHT ERROR", e);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue