mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
28 lines
813 B
Rust
28 lines
813 B
Rust
use oxc_allocator::Allocator;
|
|
|
|
#[allow(clippy::wildcard_imports)]
|
|
use oxc_ast::{ast::*, AstBuilder, VisitMut};
|
|
|
|
pub struct Prepass<'a> {
|
|
ast: AstBuilder<'a>,
|
|
}
|
|
|
|
impl<'a> Prepass<'a> {
|
|
pub fn new(allocator: &'a Allocator) -> Self {
|
|
Self { ast: AstBuilder::new(allocator) }
|
|
}
|
|
|
|
fn strip_parenthesized_expression<'b>(&self, expr: &'b mut Expression<'a>) {
|
|
if let Expression::ParenthesizedExpression(paren_expr) = expr {
|
|
*expr = self.ast.move_expression(&mut paren_expr.expression);
|
|
self.strip_parenthesized_expression(expr);
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<'a, 'b> VisitMut<'a, 'b> for Prepass<'a> {
|
|
fn visit_expression(&mut self, expr: &'b mut Expression<'a>) {
|
|
self.strip_parenthesized_expression(expr);
|
|
self.visit_expression_match(expr);
|
|
}
|
|
}
|