Skip to content

Commit

Permalink
fix(isolated-declarations): false positives for non-exported binding …
Browse files Browse the repository at this point in the history
…elements
  • Loading branch information
Dunqing committed Jun 19, 2024
1 parent ac605eb commit a739d38
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
18 changes: 10 additions & 8 deletions crates/oxc_isolated_declarations/src/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -46,21 +48,21 @@ impl<'a> IsolatedDeclarations<'a> {
decl: &VariableDeclarator<'a>,
check_binding: bool,
) -> Option<VariableDeclarator<'a>> {
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() {
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_isolated_declarations/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit a739d38

Please sign in to comment.