diff --git a/crates/rome_js_semantic/src/events.rs b/crates/rome_js_semantic/src/events.rs index 690dab01357..bfdcbcc93bc 100644 --- a/crates/rome_js_semantic/src/events.rs +++ b/crates/rome_js_semantic/src/events.rs @@ -394,9 +394,9 @@ impl SemanticEventExtractor { self.push_binding_into_scope(hoisted_scope_id, &name_token, &parent_kind); self.export_function_declaration(node, &parent); } - JS_FUNCTION_EXPRESSION => { + JS_CLASS_EXPRESSION | JS_FUNCTION_EXPRESSION => { self.push_binding_into_scope(None, &name_token, &parent_kind); - self.export_function_expression(node, &parent); + self.export_declaration_expression(node, &parent); } JS_CLASS_DECLARATION | JS_CLASS_EXPORT_DEFAULT_DECLARATION @@ -409,10 +409,6 @@ impl SemanticEventExtractor { self.push_binding_into_scope(parent_scope, &name_token, &parent_kind); self.export_declaration(node, &parent); } - JS_CLASS_EXPRESSION => { - self.push_binding_into_scope(None, &name_token, &parent_kind); - self.export_class_expression(node, &parent); - } JS_BINDING_PATTERN_WITH_DEFAULT | JS_OBJECT_BINDING_PATTERN | JS_OBJECT_BINDING_PATTERN_REST @@ -855,30 +851,18 @@ impl SemanticEventExtractor { } } - // Check if a function is exported and raise the [Exported] event. - fn export_function_expression( + // Check if a function or class expression is exported and raise the [Exported] event. + fn export_declaration_expression( &mut self, binding: &JsSyntaxNode, - function_expression: &JsSyntaxNode, + declaration_expression: &JsSyntaxNode, ) { use JsSyntaxKind::*; - debug_assert!(matches!(function_expression.kind(), JS_FUNCTION_EXPRESSION)); - let is_module_exports = function_expression - .parent() - .map(|x| self.is_assignment_left_side_module_exports(&x)) - .unwrap_or(false); - if is_module_exports { - self.stash.push_back(SemanticEvent::Exported { - range: binding.text_range(), - }); - } - } - - // Check if a function is exported and raise the [Exported] event. - fn export_class_expression(&mut self, binding: &JsSyntaxNode, class_expression: &JsSyntaxNode) { - use JsSyntaxKind::*; - debug_assert!(matches!(class_expression.kind(), JS_CLASS_EXPRESSION)); - let is_module_exports = class_expression + debug_assert!(matches!( + declaration_expression.kind(), + JS_FUNCTION_EXPRESSION | JS_CLASS_EXPRESSION + )); + let is_module_exports = declaration_expression .parent() .map(|x| self.is_assignment_left_side_module_exports(&x)) .unwrap_or(false);