add try statement catching

This commit is contained in:
velzie 2024-07-29 14:05:28 -04:00
parent ca1574fccc
commit 58f6a4330a
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
4 changed files with 40 additions and 13 deletions

View file

@ -6,6 +6,10 @@ edition = "2021"
[lib]
crate-type = ["cdylib"]
[features]
default = ["debug"]
debug = []
[profile.speed]
inherits = "release"
opt-level = 3

View file

@ -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)]

View file

@ -82,4 +82,8 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
break;
}
}
window.$scramerr = function scramerr(e) {
console.error("CAUGHT ERROR", e);
};
}