don't wrap inside a typeof

This commit is contained in:
velzie 2024-07-30 08:18:01 -04:00
parent cccf051bbc
commit 1a98345d9e
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F

View file

@ -6,7 +6,7 @@ use oxc_ast::{
};
use oxc_parser::Parser;
use oxc_span::{SourceType, Span};
use oxc_syntax::operator::AssignmentOperator;
use oxc_syntax::operator::{AssignmentOperator, UnaryOperator};
use url::Url;
#[derive(Debug)]
@ -184,19 +184,27 @@ impl<'a> Visit<'a> for Rewriter {
}
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),
text: format!(" $scramdbg((()=>{{ try {{return arguments}} catch(_){{}} }})(),("),
});
self.jschanges.push(JsChange::GenericChange {
span: Span::new(expression_span(arg).end, expression_span(arg).end),
text: format!("))"),
});
}
// if let Some(arg) = &it.argument {
// self.jschanges.push(JsChange::GenericChange {
// span: Span::new(it.span.start + 6, it.span.start + 6),
// text: format!(" $scramdbg((()=>{{ try {{return arguments}} catch(_){{}} }})(),("),
// });
// self.jschanges.push(JsChange::GenericChange {
// span: Span::new(expression_span(arg).end, expression_span(arg).end),
// text: format!("))"),
// });
// }
walk::walk_return_statement(self, it);
}
fn visit_unary_expression(&mut self, it: &oxc_ast::ast::UnaryExpression<'a>) {
if matches!(it.operator, UnaryOperator::Typeof) {
// don't walk to identifier rewrites since it won't matter
return;
}
walk::walk_unary_expression(self, it);
}
// we don't want to rewrite the identifiers here because of a very specific edge case
fn visit_for_in_statement(&mut self, it: &oxc_ast::ast::ForInStatement<'a>) {
walk::walk_statement(self, &it.body);