diff --git a/crates/swc_ecma_transforms_base/src/resolver/mod.rs b/crates/swc_ecma_transforms_base/src/resolver/mod.rs index ac97304e335..928cee64d4f 100644 --- a/crates/swc_ecma_transforms_base/src/resolver/mod.rs +++ b/crates/swc_ecma_transforms_base/src/resolver/mod.rs @@ -344,35 +344,17 @@ impl<'a> Resolver<'a> { if self.in_type { self.current.declared_types.insert(ident.sym.clone()); - let mark = self.current.mark; - - 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 - }; - return; + } else { + self.current + .declared_symbols + .insert(ident.sym.clone(), kind); } let mark = self.current.mark; - self.current - .declared_symbols - .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 - }; + if mark != Mark::root() { + ident.span = ident.span.apply_mark(mark); + } } 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) { // always resolve the identifier for type stripping purposes let old_in_type = self.in_type; + let old_ident_type = self.ident_type; + self.in_type = true; + self.ident_type = IdentType::Ref; + self.modify(&mut n.id, DeclKind::Type); if !self.config.handle_types { self.in_type = old_in_type; + self.ident_type = old_ident_type; return; } @@ -1327,7 +1314,9 @@ impl<'a> VisitMut for Resolver<'a> { n.extends.visit_mut_with(child); n.body.visit_mut_with(child); }); + self.in_type = old_in_type; + self.ident_type = old_ident_type; } 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); } + 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) { let old_kind = self.decl_kind; self.decl_kind = decl.kind.into(); @@ -1660,6 +1656,10 @@ impl VisitMut for Hoister<'_, '_> { if self.resolver.config.handle_types { match decl { Decl::TsInterface(i) => { + if self.in_block { + return; + } + let old_in_type = self.resolver.in_type; self.resolver.in_type = true; self.resolver.modify(&mut i.id, DeclKind::Type); @@ -1833,6 +1833,9 @@ impl VisitMut for Hoister<'_, '_> { #[inline] 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) { if self.in_block { match node.kind { diff --git a/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/1/input.ts b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/1/input.ts new file mode 100644 index 00000000000..4eb391512b2 --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/1/input.ts @@ -0,0 +1,7 @@ +{ + interface Foo { } +} + +{ + interface Foo { } +} diff --git a/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/1/output.ts b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/1/output.ts new file mode 100644 index 00000000000..9d77a19953d --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/1/output.ts @@ -0,0 +1,7 @@ +{ + interface Foo__3 { + } +}{ + interface Foo__4 { + } +} diff --git a/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/2/input.ts b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/2/input.ts new file mode 100644 index 00000000000..783ce5c3d30 --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/2/input.ts @@ -0,0 +1,2 @@ +{ using foo = null } +{ using foo = null } diff --git a/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/2/output.ts b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/2/output.ts new file mode 100644 index 00000000000..38f986f77eb --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/ts-resolver/issue-7967/2/output.ts @@ -0,0 +1,5 @@ +{ + using foo__3 = null +}{ + using foo__4 = null +}