fix syntax error in tryset

This commit is contained in:
velzie 2024-08-03 11:58:59 -04:00
parent 3ebbc5e430
commit a5486de863
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F

View file

@ -56,8 +56,8 @@ impl<'a> Visit<'a> for Rewriter {
// self.jschanges.push(JsChange::GenericChange {
// span: it.span,
// text: format!(
// "({}(typeof {} == 'undefined' || {}, (()=>{{ try {{return arguments}} catch(_){{}} }})()))",
// self.wrapfn, it.name, it.name
// "({}({}, (()=>{{ try {{return arguments}} catch(_){{}} }})()))",
// self.config.wrapfn, it.name
// ),
// });
if UNSAFE_GLOBALS.contains(&it.name.to_string().as_str()) {
@ -144,21 +144,21 @@ 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),
});
}
}
}
}
// #[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 {
@ -183,7 +183,7 @@ impl<'a> Visit<'a> for Rewriter {
walk::walk_object_expression(self, it);
}
fn visit_return_statement(&mut self, it: &oxc_ast::ast::ReturnStatement<'a>) {
// fn visit_return_statement(&mut self, it: &oxc_ast::ast::ReturnStatement<'a>) {
// if let Some(arg) = &it.argument {
// self.jschanges.push(JsChange::GenericChange {
// span: Span::new(it.span.start + 6, it.span.start + 6),
@ -194,8 +194,8 @@ impl<'a> Visit<'a> for Rewriter {
// text: format!("))"),
// });
// }
walk::walk_return_statement(self, it);
}
// // walk::walk_return_statement(self, it);
// }
fn visit_unary_expression(&mut self, it: &oxc_ast::ast::UnaryExpression<'a>) {
if matches!(it.operator, UnaryOperator::Typeof) {
@ -403,7 +403,7 @@ pub fn rewrite(js: &str, url: Url, config: Config) -> Vec<u8> {
buffer.extend_from_slice(
format!(
"((t)=>$scramjet$tryset({},\"{}\",t)||{}{}t)({})",
"((t)=>$scramjet$tryset({},\"{}\",t)||({}{}t))({})",
name,
fmt_op(*op),
name,