From 759710aa6655e61120ea4ec56e35d023f09175a2 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:37:27 +0000 Subject: [PATCH] refactor(transformer): methods only take `&TraverseCtx` where possible (#6812) Methods which only need an immutable ref `&TraverseCtx` take that, instead of unnecessary `&mut TraverseCtx`. --- crates/oxc_transformer/src/common/module_imports.rs | 2 +- crates/oxc_transformer/src/common/var_declarations.rs | 6 +++--- crates/oxc_transformer/src/es2015/arrow_functions.rs | 2 +- crates/oxc_transformer/src/react/jsx_source.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/oxc_transformer/src/common/module_imports.rs b/crates/oxc_transformer/src/common/module_imports.rs index 2481d0c00..ef7d30ba8 100644 --- a/crates/oxc_transformer/src/common/module_imports.rs +++ b/crates/oxc_transformer/src/common/module_imports.rs @@ -193,7 +193,7 @@ impl<'a> ModuleImportsStore<'a> { fn get_import( source: Atom<'a>, names: Vec>, - ctx: &mut TraverseCtx<'a>, + ctx: &TraverseCtx<'a>, ) -> Statement<'a> { let specifiers = ctx.ast.vec_from_iter(names.into_iter().map(|import| match import { Import::Named(import) => { diff --git a/crates/oxc_transformer/src/common/var_declarations.rs b/crates/oxc_transformer/src/common/var_declarations.rs index 29f4b49ca..fe6bce4bf 100644 --- a/crates/oxc_transformer/src/common/var_declarations.rs +++ b/crates/oxc_transformer/src/common/var_declarations.rs @@ -72,7 +72,7 @@ impl<'a> VarDeclarationsStore<'a> { &self, binding: &BoundIdentifier<'a>, init: Option>, - ctx: &mut TraverseCtx<'a>, + ctx: &TraverseCtx<'a>, ) { let ident = binding.create_binding_identifier(ctx); let ident = ctx.ast.binding_pattern_kind_from_binding_identifier(ident); @@ -86,7 +86,7 @@ impl<'a> VarDeclarationsStore<'a> { &self, ident: BindingPattern<'a>, init: Option>, - ctx: &mut TraverseCtx<'a>, + ctx: &TraverseCtx<'a>, ) { let declarator = ctx.ast.variable_declarator(SPAN, VariableDeclarationKind::Var, ident, init, false); @@ -94,7 +94,7 @@ impl<'a> VarDeclarationsStore<'a> { } /// Add a `VariableDeclarator` to be inserted at top of current enclosing statement block. - pub fn insert_declarator(&self, declarator: VariableDeclarator<'a>, ctx: &mut TraverseCtx<'a>) { + pub fn insert_declarator(&self, declarator: VariableDeclarator<'a>, ctx: &TraverseCtx<'a>) { let mut stack = self.stack.borrow_mut(); stack.last_mut_or_init(|| ctx.ast.vec()).push(declarator); } diff --git a/crates/oxc_transformer/src/es2015/arrow_functions.rs b/crates/oxc_transformer/src/es2015/arrow_functions.rs index 6a21f047d..eebfc5c51 100644 --- a/crates/oxc_transformer/src/es2015/arrow_functions.rs +++ b/crates/oxc_transformer/src/es2015/arrow_functions.rs @@ -407,7 +407,7 @@ impl<'a> ArrowFunctions<'a> { &mut self, statements: &mut Vec<'a, Statement<'a>>, this_var: &BoundIdentifier<'a>, - ctx: &mut TraverseCtx<'a>, + ctx: &TraverseCtx<'a>, ) { let binding_pattern = ctx.ast.binding_pattern( ctx.ast.binding_pattern_kind_from_binding_identifier( diff --git a/crates/oxc_transformer/src/react/jsx_source.rs b/crates/oxc_transformer/src/react/jsx_source.rs index 255d8bb40..265572322 100644 --- a/crates/oxc_transformer/src/react/jsx_source.rs +++ b/crates/oxc_transformer/src/react/jsx_source.rs @@ -201,7 +201,7 @@ impl<'a, 'ctx> ReactJsxSource<'a, 'ctx> { pub fn get_filename_var_declarator( &self, - ctx: &mut TraverseCtx<'a>, + ctx: &TraverseCtx<'a>, ) -> Option> { let filename_var = self.filename_var.as_ref()?;