Skip to content

Commit

Permalink
refactor(transformer/es2019): move all entry points to implementation…
Browse files Browse the repository at this point in the history
… of Traverse trait (#5065)

follow-up #4881
  • Loading branch information
Dunqing committed Aug 22, 2024
1 parent d50eb72 commit deda6ac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 5 additions & 7 deletions crates/oxc_transformer/src/es2019/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod options;
pub use optional_catch_binding::OptionalCatchBinding;
pub use options::ES2019Options;
use oxc_ast::ast::*;
use oxc_traverse::TraverseCtx;
use oxc_traverse::{Traverse, TraverseCtx};
use std::rc::Rc;

use crate::context::Ctx;
Expand All @@ -22,14 +22,12 @@ impl<'a> ES2019<'a> {
pub fn new(options: ES2019Options, ctx: Ctx<'a>) -> Self {
Self { optional_catch_binding: OptionalCatchBinding::new(Rc::clone(&ctx)), ctx, options }
}
}

pub fn transform_catch_clause(
&mut self,
clause: &mut CatchClause<'a>,
ctx: &mut TraverseCtx<'a>,
) {
impl<'a> Traverse<'a> for ES2019<'a> {
fn enter_catch_clause(&mut self, clause: &mut CatchClause<'a>, ctx: &mut TraverseCtx<'a>) {
if self.options.optional_catch_binding {
self.optional_catch_binding.transform_catch_clause(clause, ctx);
self.optional_catch_binding.enter_catch_clause(clause, ctx);
}
}
}
6 changes: 4 additions & 2 deletions crates/oxc_transformer/src/es2019/optional_catch_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::cell::Cell;
use oxc_ast::ast::*;
use oxc_semantic::SymbolFlags;
use oxc_span::SPAN;
use oxc_traverse::TraverseCtx;
use oxc_traverse::{Traverse, TraverseCtx};

use crate::context::Ctx;

Expand All @@ -49,10 +49,12 @@ impl<'a> OptionalCatchBinding<'a> {
pub fn new(ctx: Ctx<'a>) -> Self {
Self { _ctx: ctx }
}
}

impl<'a> Traverse<'a> for OptionalCatchBinding<'a> {
/// If CatchClause has no param, add a parameter called `unused`.
#[allow(clippy::unused_self)]
pub fn transform_catch_clause(&self, clause: &mut CatchClause<'a>, ctx: &mut TraverseCtx<'a>) {
fn enter_catch_clause(&mut self, clause: &mut CatchClause<'a>, ctx: &mut TraverseCtx<'a>) {
if clause.param.is_some() {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl<'a> Traverse<'a> for Transformer<'a> {
}

fn enter_catch_clause(&mut self, clause: &mut CatchClause<'a>, ctx: &mut TraverseCtx<'a>) {
self.x2_es2019.transform_catch_clause(clause, ctx);
self.x2_es2019.enter_catch_clause(clause, ctx);
}

fn enter_ts_export_assignment(
Expand Down

0 comments on commit deda6ac

Please sign in to comment.