mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(isolated-declarations): shouldn’t add declare in declaration with export default (#3804)
Added tests in #3808
This commit is contained in:
parent
f3c3970131
commit
683c7b0dd1
4 changed files with 17 additions and 11 deletions
|
|
@ -247,7 +247,11 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
elements
|
||||
}
|
||||
|
||||
pub fn transform_class(&self, decl: &Class<'a>) -> Option<Box<'a, Class<'a>>> {
|
||||
pub fn transform_class(
|
||||
&self,
|
||||
decl: &Class<'a>,
|
||||
modifiers: Option<Modifiers<'a>>,
|
||||
) -> Option<Box<'a, Class<'a>>> {
|
||||
if decl.is_declare() {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -441,7 +445,7 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
|
||||
let body = self.ast.class_body(decl.body.span, elements);
|
||||
|
||||
let mut modifiers = self.modifiers_declare();
|
||||
let mut modifiers = modifiers.unwrap_or_else(|| self.modifiers_declare());
|
||||
if decl.modifiers.is_contains_abstract() {
|
||||
modifiers.add_modifier(Modifier { span: SPAN, kind: ModifierKind::Abstract });
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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).map(Declaration::FunctionDeclaration)
|
||||
self.transform_function(func, None).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).map(Declaration::ClassDeclaration)
|
||||
self.transform_class(decl, None).map(Declaration::ClassDeclaration)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,11 @@ use crate::{
|
|||
};
|
||||
|
||||
impl<'a> IsolatedDeclarations<'a> {
|
||||
pub fn transform_function(&mut self, func: &Function<'a>) -> Option<Box<'a, Function<'a>>> {
|
||||
pub fn transform_function(
|
||||
&mut self,
|
||||
func: &Function<'a>,
|
||||
modifiers: Option<Modifiers<'a>>,
|
||||
) -> Option<Box<'a, Function<'a>>> {
|
||||
if func.modifiers.is_contains_declare() {
|
||||
None
|
||||
} else {
|
||||
|
|
@ -33,7 +37,7 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
None,
|
||||
self.ast.copy(&func.type_parameters),
|
||||
return_type,
|
||||
self.modifiers_declare(),
|
||||
modifiers.unwrap_or_else(|| self.modifiers_declare()),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use oxc_allocator::Box;
|
||||
#[allow(clippy::wildcard_imports)]
|
||||
use oxc_ast::ast::*;
|
||||
use oxc_ast::Visit;
|
||||
use oxc_span::{Atom, GetSpan, SPAN};
|
||||
|
||||
use crate::{diagnostics::default_export_inferred, IsolatedDeclarations};
|
||||
|
|
@ -39,13 +38,12 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
) -> Option<(Option<VariableDeclaration<'a>>, ExportDefaultDeclaration<'a>)> {
|
||||
let declaration = match &decl.declaration {
|
||||
ExportDefaultDeclarationKind::FunctionDeclaration(decl) => self
|
||||
.transform_function(decl)
|
||||
.transform_function(decl, Some(Modifiers::empty()))
|
||||
.map(|d| (None, ExportDefaultDeclarationKind::FunctionDeclaration(d))),
|
||||
ExportDefaultDeclarationKind::ClassDeclaration(decl) => self
|
||||
.transform_class(decl)
|
||||
.transform_class(decl, Some(Modifiers::empty()))
|
||||
.map(|d| (None, ExportDefaultDeclarationKind::ClassDeclaration(d))),
|
||||
ExportDefaultDeclarationKind::TSInterfaceDeclaration(interface_decl) => {
|
||||
self.visit_ts_interface_declaration(interface_decl);
|
||||
ExportDefaultDeclarationKind::TSInterfaceDeclaration(_) => {
|
||||
Some((None, self.ast.copy(&decl.declaration)))
|
||||
}
|
||||
expr @ match_expression!(ExportDefaultDeclarationKind) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue