From cea0e6b62fb566535d5fc41bbbd7009282737582 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Sat, 2 Nov 2024 01:22:55 +0000 Subject: [PATCH] refactor(isolated_declarations): do not use `AstBuilder::*_from_*` methods (#7071) Preparation for #7073. Avoid using `AstBuilder::*_from_*` methods to construct enums, use explicit construction instead. Before: ```rs let ident = self.ast.binding_pattern_kind_from_binding_identifier(ident); ``` After: ```rs let ident = BindingPatternKind::BindingIdentifier(ident); ``` Often this produces shorter code, as well as (in my opinion) being easier to read. --- crates/oxc_isolated_declarations/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/oxc_isolated_declarations/src/lib.rs b/crates/oxc_isolated_declarations/src/lib.rs index cc703f91b15ca..b76023d8a3777 100644 --- a/crates/oxc_isolated_declarations/src/lib.rs +++ b/crates/oxc_isolated_declarations/src/lib.rs @@ -332,7 +332,7 @@ impl<'a> IsolatedDeclarations<'a> { ); transformed_stmts.insert( declaration.span, - Statement::from(self.ast.declaration_from_variable(decl)), + Statement::VariableDeclaration(self.ast.alloc(decl)), ); transformed_spans.insert(declaration.span); } @@ -378,9 +378,7 @@ impl<'a> IsolatedDeclarations<'a> { if decl.specifiers.is_none() { new_stm.push(stmt.clone_in(self.ast.allocator)); } else if let Some(new_decl) = self.transform_import_declaration(decl) { - new_stm.push(Statement::from( - self.ast.module_declaration_from_import_declaration(new_decl), - )); + new_stm.push(Statement::ImportDeclaration(new_decl)); } } Statement::VariableDeclaration(decl) => { @@ -391,14 +389,14 @@ impl<'a> IsolatedDeclarations<'a> { transformed_variable_declarator.remove(&declarator.span) }), ); - new_stm.push(Statement::from(self.ast.declaration_from_variable( - self.ast.variable_declaration( + new_stm.push(Statement::VariableDeclaration( + self.ast.alloc_variable_declaration( decl.span, decl.kind, declarations, self.is_declare(), ), - ))); + )); } } _ => {}