diff --git a/crates/oxc_isolated_declarations/src/declaration.rs b/crates/oxc_isolated_declarations/src/declaration.rs index a32c05d1dd72d6..c0ab0003e6f2d6 100644 --- a/crates/oxc_isolated_declarations/src/declaration.rs +++ b/crates/oxc_isolated_declarations/src/declaration.rs @@ -7,7 +7,9 @@ use oxc_span::{GetSpan, SPAN}; use oxc_syntax::scope::ScopeFlags; use crate::{ - diagnostics::{inferred_type_of_expression, signature_computed_property_name}, + diagnostics::{ + binding_element_export, inferred_type_of_expression, signature_computed_property_name, + }, IsolatedDeclarations, }; @@ -46,21 +48,21 @@ impl<'a> IsolatedDeclarations<'a> { decl: &VariableDeclarator<'a>, check_binding: bool, ) -> Option> { - if decl.id.kind.is_destructuring_pattern() { - self.error(OxcDiagnostic::error( - "Binding elements can't be exported directly with --isolatedDeclarations.", - )); - return None; - } - if check_binding { if let Some(name) = decl.id.get_identifier() { if !self.scope.has_reference(name) { return None; } + } else { + return None; } } + if decl.id.kind.is_destructuring_pattern() { + self.error(binding_element_export(decl.id.kind.span())); + return None; + } + let mut binding_type = None; let mut init = None; if decl.id.type_annotation.is_none() { diff --git a/crates/oxc_isolated_declarations/src/diagnostics.rs b/crates/oxc_isolated_declarations/src/diagnostics.rs index eda214b28bf152..4b763b09f485b7 100644 --- a/crates/oxc_isolated_declarations/src/diagnostics.rs +++ b/crates/oxc_isolated_declarations/src/diagnostics.rs @@ -95,3 +95,8 @@ pub fn implicitly_adding_undefined_to_type(span: Span) -> OxcDiagnostic { ) .with_label(span) } + +pub fn binding_element_export(span: Span) -> OxcDiagnostic { + OxcDiagnostic::error("Binding elements can't be exported directly with --isolatedDeclarations.") + .with_label(span) +}