fix(es/typescript): Correctly handle deep import chains (#9487)

**Related issue:**

- Closes https://github.com/swc-project/swc/issues/9486
This commit is contained in:
magic-akari 2024-08-23 06:01:40 +08:00 committed by GitHub
parent 1121bc0dc1
commit 50d70d35d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 4 deletions

View File

@ -0,0 +1,5 @@
---
swc_ecma_transforms_typescript: patch
---
fix(es/typescript): Correctly handle deep import chains

View File

@ -121,10 +121,10 @@ impl UsageCollect {
let mut new_usage = AHashSet::default();
for id in &self.id_usage {
let mut entry = self.import_chain.remove_entry(id);
while let Some((id, next)) = entry {
new_usage.insert(next);
entry = self.import_chain.remove_entry(&id);
let mut next = self.import_chain.remove(id);
while let Some(id) = next {
next = self.import_chain.remove(&id);
new_usage.insert(id);
}
if self.import_chain.is_empty() {
break;

View File

@ -0,0 +1,5 @@
import { ns1 } from '../anotherFile';
import ns2 = ns1.ns2;
import Class = ns2.Class;
const a = new Class(5);

View File

@ -0,0 +1,4 @@
import { ns1 } from '../anotherFile';
const ns2 = ns1.ns2;
const Class = ns2.Class;
const a = new Class(5);