mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 23:10:02 -04:00
don't wrap inside a typeof
This commit is contained in:
parent
cccf051bbc
commit
1a98345d9e
1 changed files with 19 additions and 11 deletions
|
@ -6,7 +6,7 @@ use oxc_ast::{
|
||||||
};
|
};
|
||||||
use oxc_parser::Parser;
|
use oxc_parser::Parser;
|
||||||
use oxc_span::{SourceType, Span};
|
use oxc_span::{SourceType, Span};
|
||||||
use oxc_syntax::operator::AssignmentOperator;
|
use oxc_syntax::operator::{AssignmentOperator, UnaryOperator};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -184,19 +184,27 @@ impl<'a> Visit<'a> for Rewriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
// if let Some(arg) = &it.argument {
|
||||||
self.jschanges.push(JsChange::GenericChange {
|
// self.jschanges.push(JsChange::GenericChange {
|
||||||
span: Span::new(it.span.start + 6, it.span.start + 6),
|
// span: Span::new(it.span.start + 6, it.span.start + 6),
|
||||||
text: format!(" $scramdbg((()=>{{ try {{return arguments}} catch(_){{}} }})(),("),
|
// text: format!(" $scramdbg((()=>{{ try {{return arguments}} catch(_){{}} }})(),("),
|
||||||
});
|
// });
|
||||||
self.jschanges.push(JsChange::GenericChange {
|
// self.jschanges.push(JsChange::GenericChange {
|
||||||
span: Span::new(expression_span(arg).end, expression_span(arg).end),
|
// span: Span::new(expression_span(arg).end, expression_span(arg).end),
|
||||||
text: format!("))"),
|
// 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) {
|
||||||
|
// 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
|
// 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>) {
|
fn visit_for_in_statement(&mut self, it: &oxc_ast::ast::ForInStatement<'a>) {
|
||||||
walk::walk_statement(self, &it.body);
|
walk::walk_statement(self, &it.body);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue