diff --git a/crates/oxc_isolated_declarations/src/class.rs b/crates/oxc_isolated_declarations/src/class.rs index 9e32442a75abe6..0d11dd1d1033ad 100644 --- a/crates/oxc_isolated_declarations/src/class.rs +++ b/crates/oxc_isolated_declarations/src/class.rs @@ -303,11 +303,7 @@ impl<'a> IsolatedDeclarations<'a> { inferred_accessor_types } - pub fn transform_class( - &self, - decl: &Class<'a>, - modifiers: Option>, - ) -> Option>> { + pub fn transform_class(&self, decl: &Class<'a>) -> Option>> { if decl.declare { return None; } @@ -462,11 +458,6 @@ impl<'a> IsolatedDeclarations<'a> { let body = self.ast.class_body(decl.body.span, elements); - let mut modifiers = modifiers.unwrap_or_else(|| self.modifiers_declare()); - if decl.r#abstract { - modifiers.add_modifier(Modifier { span: SPAN, kind: ModifierKind::Abstract }); - }; - Some(self.ast.class( decl.r#type, decl.span, @@ -477,8 +468,8 @@ impl<'a> IsolatedDeclarations<'a> { self.ast.copy(&decl.super_type_parameters), self.ast.copy(&decl.implements), self.ast.new_vec(), - modifiers.is_contains_abstract(), - modifiers.is_contains_declare(), + decl.r#abstract, + self.is_declare(), )) } diff --git a/crates/oxc_isolated_declarations/src/declaration.rs b/crates/oxc_isolated_declarations/src/declaration.rs index 507fd754001a73..deea0e037422b8 100644 --- a/crates/oxc_isolated_declarations/src/declaration.rs +++ b/crates/oxc_isolated_declarations/src/declaration.rs @@ -39,7 +39,7 @@ impl<'a> IsolatedDeclarations<'a> { decl.span, decl.kind, self.ast.new_vec_from_iter(declarations), - self.modifiers_declare().is_contains_declare(), + self.is_declare(), ) } @@ -126,7 +126,7 @@ impl<'a> IsolatedDeclarations<'a> { decl.span, VariableDeclarationKind::Const, declarations, - self.modifiers_declare().is_contains_declare(), + self.is_declare(), ) } @@ -161,7 +161,7 @@ impl<'a> IsolatedDeclarations<'a> { self.ast.copy(&decl.id), Some(TSModuleDeclarationBody::TSModuleDeclaration(inner)), decl.kind, - self.modifiers_declare().is_contains_declare(), + self.is_declare(), ) } TSModuleDeclarationBody::TSModuleBlock(block) => { @@ -171,7 +171,7 @@ impl<'a> IsolatedDeclarations<'a> { self.ast.copy(&decl.id), Some(TSModuleDeclarationBody::TSModuleBlock(body)), decl.kind, - self.modifiers_declare().is_contains_declare(), + self.is_declare(), ) } } @@ -187,7 +187,7 @@ impl<'a> IsolatedDeclarations<'a> { if !check_binding || func.id.as_ref().is_some_and(|id| self.scope.has_reference(&id.name)) { - self.transform_function(func, None).map(Declaration::FunctionDeclaration) + self.transform_function(func).map(Declaration::FunctionDeclaration) } else { None } @@ -202,7 +202,7 @@ impl<'a> IsolatedDeclarations<'a> { if !check_binding || decl.id.as_ref().is_some_and(|id| self.scope.has_reference(&id.name)) { - self.transform_class(decl, None).map(Declaration::ClassDeclaration) + self.transform_class(decl).map(Declaration::ClassDeclaration) } else { None } diff --git a/crates/oxc_isolated_declarations/src/enum.rs b/crates/oxc_isolated_declarations/src/enum.rs index 113d23af8aff9a..5324cc2a9becce 100644 --- a/crates/oxc_isolated_declarations/src/enum.rs +++ b/crates/oxc_isolated_declarations/src/enum.rs @@ -90,17 +90,13 @@ impl<'a> IsolatedDeclarations<'a> { members.push(member); } - let mut modifiers = self.modifiers_declare(); - if decl.r#const { - modifiers.add_modifier(Modifier { span: SPAN, kind: ModifierKind::Const }); - } Some(self.ast.ts_enum_declaration( decl.span, self.ast.copy(&decl.id), members, - modifiers.is_contains_const(), - modifiers.is_contains_declare(), + decl.r#const, + self.is_declare(), )) } diff --git a/crates/oxc_isolated_declarations/src/function.rs b/crates/oxc_isolated_declarations/src/function.rs index 808e9e79cdb843..2c18a7a2c4709a 100644 --- a/crates/oxc_isolated_declarations/src/function.rs +++ b/crates/oxc_isolated_declarations/src/function.rs @@ -13,11 +13,7 @@ use crate::{ }; impl<'a> IsolatedDeclarations<'a> { - pub fn transform_function( - &mut self, - func: &Function<'a>, - modifiers: Option>, - ) -> Option>> { + pub fn transform_function(&mut self, func: &Function<'a>) -> Option>> { if func.declare { None } else { @@ -32,7 +28,7 @@ impl<'a> IsolatedDeclarations<'a> { self.ast.copy(&func.id), false, false, - modifiers.unwrap_or_else(|| self.modifiers_declare()).is_contains_declare(), + self.is_declare(), self.ast.copy(&func.this_param), params, None, diff --git a/crates/oxc_isolated_declarations/src/lib.rs b/crates/oxc_isolated_declarations/src/lib.rs index a9e4da97a3b441..285b653b4f96c4 100644 --- a/crates/oxc_isolated_declarations/src/lib.rs +++ b/crates/oxc_isolated_declarations/src/lib.rs @@ -393,14 +393,8 @@ impl<'a> IsolatedDeclarations<'a> { }) } - pub fn modifiers_declare(&self) -> Modifiers<'a> { - if self.scope.is_ts_module_block_flag() { - // If we are in a module block, we don't need to add declare - Modifiers::empty() - } else { - Modifiers::new( - self.ast.new_vec_single(Modifier { span: SPAN, kind: ModifierKind::Declare }), - ) - } + pub fn is_declare(&self) -> bool { + // If we are in a module block, we don't need to add declare + !self.scope.is_ts_module_block_flag() } } diff --git a/crates/oxc_isolated_declarations/src/module.rs b/crates/oxc_isolated_declarations/src/module.rs index 32e773a5cd902d..417f2a5f3bd8c4 100644 --- a/crates/oxc_isolated_declarations/src/module.rs +++ b/crates/oxc_isolated_declarations/src/module.rs @@ -38,10 +38,10 @@ impl<'a> IsolatedDeclarations<'a> { ) -> Option<(Option>, ExportDefaultDeclaration<'a>)> { let declaration = match &decl.declaration { ExportDefaultDeclarationKind::FunctionDeclaration(decl) => self - .transform_function(decl, Some(Modifiers::empty())) + .transform_function(decl) .map(|d| (None, ExportDefaultDeclarationKind::FunctionDeclaration(d))), ExportDefaultDeclarationKind::ClassDeclaration(decl) => self - .transform_class(decl, Some(Modifiers::empty())) + .transform_class(decl) .map(|d| (None, ExportDefaultDeclarationKind::ClassDeclaration(d))), ExportDefaultDeclarationKind::TSInterfaceDeclaration(_) => { Some((None, self.ast.copy(&decl.declaration))) @@ -75,7 +75,7 @@ impl<'a> IsolatedDeclarations<'a> { span: SPAN, kind, declarations, - declare: self.modifiers_declare().is_contains_declare(), + declare: self.is_declare(), }), ExportDefaultDeclarationKind::from( self.ast.identifier_reference_expression(