mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 17:54:15 +03:00
fix(es/resolver): Handle TsInterfaceDecl
and UsingDecl
correctly (#8403)
**Related issue**: - Closes #7967
This commit is contained in:
parent
595f13c019
commit
f8ce31627b
@ -344,35 +344,17 @@ impl<'a> Resolver<'a> {
|
|||||||
|
|
||||||
if self.in_type {
|
if self.in_type {
|
||||||
self.current.declared_types.insert(ident.sym.clone());
|
self.current.declared_types.insert(ident.sym.clone());
|
||||||
let mark = self.current.mark;
|
} else {
|
||||||
|
self.current
|
||||||
ident.span = if mark == Mark::root() {
|
.declared_symbols
|
||||||
ident.span
|
.insert(ident.sym.clone(), kind);
|
||||||
} else {
|
|
||||||
let span = ident.span.apply_mark(mark);
|
|
||||||
if cfg!(debug_assertions) && LOG {
|
|
||||||
debug!("\t-> {:?}", span.ctxt());
|
|
||||||
}
|
|
||||||
span
|
|
||||||
};
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mark = self.current.mark;
|
let mark = self.current.mark;
|
||||||
|
|
||||||
self.current
|
if mark != Mark::root() {
|
||||||
.declared_symbols
|
ident.span = ident.span.apply_mark(mark);
|
||||||
.insert(ident.sym.clone(), kind);
|
}
|
||||||
|
|
||||||
ident.span = if mark == Mark::root() {
|
|
||||||
ident.span
|
|
||||||
} else {
|
|
||||||
let span = ident.span.apply_mark(mark);
|
|
||||||
if cfg!(debug_assertions) && LOG {
|
|
||||||
debug!("\t-> {:?}", span.ctxt());
|
|
||||||
}
|
|
||||||
span
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mark_block(&mut self, span: &mut Span) {
|
fn mark_block(&mut self, span: &mut Span) {
|
||||||
@ -1312,11 +1294,16 @@ impl<'a> VisitMut for Resolver<'a> {
|
|||||||
fn visit_mut_ts_interface_decl(&mut self, n: &mut TsInterfaceDecl) {
|
fn visit_mut_ts_interface_decl(&mut self, n: &mut TsInterfaceDecl) {
|
||||||
// always resolve the identifier for type stripping purposes
|
// always resolve the identifier for type stripping purposes
|
||||||
let old_in_type = self.in_type;
|
let old_in_type = self.in_type;
|
||||||
|
let old_ident_type = self.ident_type;
|
||||||
|
|
||||||
self.in_type = true;
|
self.in_type = true;
|
||||||
|
self.ident_type = IdentType::Ref;
|
||||||
|
|
||||||
self.modify(&mut n.id, DeclKind::Type);
|
self.modify(&mut n.id, DeclKind::Type);
|
||||||
|
|
||||||
if !self.config.handle_types {
|
if !self.config.handle_types {
|
||||||
self.in_type = old_in_type;
|
self.in_type = old_in_type;
|
||||||
|
self.ident_type = old_ident_type;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1327,7 +1314,9 @@ impl<'a> VisitMut for Resolver<'a> {
|
|||||||
n.extends.visit_mut_with(child);
|
n.extends.visit_mut_with(child);
|
||||||
n.body.visit_mut_with(child);
|
n.body.visit_mut_with(child);
|
||||||
});
|
});
|
||||||
|
|
||||||
self.in_type = old_in_type;
|
self.in_type = old_in_type;
|
||||||
|
self.ident_type = old_ident_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mut_ts_mapped_type(&mut self, n: &mut TsMappedType) {
|
fn visit_mut_ts_mapped_type(&mut self, n: &mut TsMappedType) {
|
||||||
@ -1484,6 +1473,13 @@ impl<'a> VisitMut for Resolver<'a> {
|
|||||||
params.visit_mut_children_with(self);
|
params.visit_mut_children_with(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn visit_mut_using_decl(&mut self, decl: &mut UsingDecl) {
|
||||||
|
let old_kind = self.decl_kind;
|
||||||
|
self.decl_kind = DeclKind::Lexical;
|
||||||
|
decl.decls.visit_mut_with(self);
|
||||||
|
self.decl_kind = old_kind;
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_mut_var_decl(&mut self, decl: &mut VarDecl) {
|
fn visit_mut_var_decl(&mut self, decl: &mut VarDecl) {
|
||||||
let old_kind = self.decl_kind;
|
let old_kind = self.decl_kind;
|
||||||
self.decl_kind = decl.kind.into();
|
self.decl_kind = decl.kind.into();
|
||||||
@ -1660,6 +1656,10 @@ impl VisitMut for Hoister<'_, '_> {
|
|||||||
if self.resolver.config.handle_types {
|
if self.resolver.config.handle_types {
|
||||||
match decl {
|
match decl {
|
||||||
Decl::TsInterface(i) => {
|
Decl::TsInterface(i) => {
|
||||||
|
if self.in_block {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let old_in_type = self.resolver.in_type;
|
let old_in_type = self.resolver.in_type;
|
||||||
self.resolver.in_type = true;
|
self.resolver.in_type = true;
|
||||||
self.resolver.modify(&mut i.id, DeclKind::Type);
|
self.resolver.modify(&mut i.id, DeclKind::Type);
|
||||||
@ -1833,6 +1833,9 @@ impl VisitMut for Hoister<'_, '_> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn visit_mut_ts_module_block(&mut self, _: &mut TsModuleBlock) {}
|
fn visit_mut_ts_module_block(&mut self, _: &mut TsModuleBlock) {}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_mut_using_decl(&mut self, _: &mut UsingDecl) {}
|
||||||
|
|
||||||
fn visit_mut_var_decl(&mut self, node: &mut VarDecl) {
|
fn visit_mut_var_decl(&mut self, node: &mut VarDecl) {
|
||||||
if self.in_block {
|
if self.in_block {
|
||||||
match node.kind {
|
match node.kind {
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
interface Foo { }
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
interface Foo { }
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
interface Foo__3 {
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
interface Foo__4 {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
{ using foo = null }
|
||||||
|
{ using foo = null }
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
using foo__3 = null
|
||||||
|
}{
|
||||||
|
using foo__4 = null
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user