mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +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
|
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() {
|
if decl.is_declare() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
@ -441,7 +445,7 @@ impl<'a> IsolatedDeclarations<'a> {
|
||||||
|
|
||||||
let body = self.ast.class_body(decl.body.span, elements);
|
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() {
|
if decl.modifiers.is_contains_abstract() {
|
||||||
modifiers.add_modifier(Modifier { span: SPAN, kind: ModifierKind::Abstract });
|
modifiers.add_modifier(Modifier { span: SPAN, kind: ModifierKind::Abstract });
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ impl<'a> IsolatedDeclarations<'a> {
|
||||||
if !check_binding
|
if !check_binding
|
||||||
|| func.id.as_ref().is_some_and(|id| self.scope.has_reference(&id.name))
|
|| 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 {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
@ -202,7 +202,7 @@ impl<'a> IsolatedDeclarations<'a> {
|
||||||
if !check_binding
|
if !check_binding
|
||||||
|| decl.id.as_ref().is_some_and(|id| self.scope.has_reference(&id.name))
|
|| 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 {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,11 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<'a> IsolatedDeclarations<'a> {
|
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() {
|
if func.modifiers.is_contains_declare() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -33,7 +37,7 @@ impl<'a> IsolatedDeclarations<'a> {
|
||||||
None,
|
None,
|
||||||
self.ast.copy(&func.type_parameters),
|
self.ast.copy(&func.type_parameters),
|
||||||
return_type,
|
return_type,
|
||||||
self.modifiers_declare(),
|
modifiers.unwrap_or_else(|| self.modifiers_declare()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use oxc_allocator::Box;
|
use oxc_allocator::Box;
|
||||||
#[allow(clippy::wildcard_imports)]
|
#[allow(clippy::wildcard_imports)]
|
||||||
use oxc_ast::ast::*;
|
use oxc_ast::ast::*;
|
||||||
use oxc_ast::Visit;
|
|
||||||
use oxc_span::{Atom, GetSpan, SPAN};
|
use oxc_span::{Atom, GetSpan, SPAN};
|
||||||
|
|
||||||
use crate::{diagnostics::default_export_inferred, IsolatedDeclarations};
|
use crate::{diagnostics::default_export_inferred, IsolatedDeclarations};
|
||||||
|
|
@ -39,13 +38,12 @@ impl<'a> IsolatedDeclarations<'a> {
|
||||||
) -> Option<(Option<VariableDeclaration<'a>>, ExportDefaultDeclaration<'a>)> {
|
) -> Option<(Option<VariableDeclaration<'a>>, ExportDefaultDeclaration<'a>)> {
|
||||||
let declaration = match &decl.declaration {
|
let declaration = match &decl.declaration {
|
||||||
ExportDefaultDeclarationKind::FunctionDeclaration(decl) => self
|
ExportDefaultDeclarationKind::FunctionDeclaration(decl) => self
|
||||||
.transform_function(decl)
|
.transform_function(decl, Some(Modifiers::empty()))
|
||||||
.map(|d| (None, ExportDefaultDeclarationKind::FunctionDeclaration(d))),
|
.map(|d| (None, ExportDefaultDeclarationKind::FunctionDeclaration(d))),
|
||||||
ExportDefaultDeclarationKind::ClassDeclaration(decl) => self
|
ExportDefaultDeclarationKind::ClassDeclaration(decl) => self
|
||||||
.transform_class(decl)
|
.transform_class(decl, Some(Modifiers::empty()))
|
||||||
.map(|d| (None, ExportDefaultDeclarationKind::ClassDeclaration(d))),
|
.map(|d| (None, ExportDefaultDeclarationKind::ClassDeclaration(d))),
|
||||||
ExportDefaultDeclarationKind::TSInterfaceDeclaration(interface_decl) => {
|
ExportDefaultDeclarationKind::TSInterfaceDeclaration(_) => {
|
||||||
self.visit_ts_interface_declaration(interface_decl);
|
|
||||||
Some((None, self.ast.copy(&decl.declaration)))
|
Some((None, self.ast.copy(&decl.declaration)))
|
||||||
}
|
}
|
||||||
expr @ match_expression!(ExportDefaultDeclarationKind) => {
|
expr @ match_expression!(ExportDefaultDeclarationKind) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue