From 30de27073e91b5b670ea1a10b429094d1fd9ac99 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 16 Nov 2023 19:20:39 -0500 Subject: [PATCH 1/2] fix: Correct resolving identifiers in TsImportType --- crates/swc_ecma_transforms_base/src/resolver/mod.rs | 10 ++++++++-- .../ts-resolver/ts_import_type_qualifier/input.ts | 7 +++++++ .../ts-resolver/ts_import_type_qualifier/output.ts | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 crates/swc_ecma_transforms_base/tests/ts-resolver/ts_import_type_qualifier/input.ts create mode 100644 crates/swc_ecma_transforms_base/tests/ts-resolver/ts_import_type_qualifier/output.ts diff --git a/crates/swc_ecma_transforms_base/src/resolver/mod.rs b/crates/swc_ecma_transforms_base/src/resolver/mod.rs index 891f35bf9ae8..4342c7b83bfa 100644 --- a/crates/swc_ecma_transforms_base/src/resolver/mod.rs +++ b/crates/swc_ecma_transforms_base/src/resolver/mod.rs @@ -510,8 +510,6 @@ impl<'a> VisitMut for Resolver<'a> { typed_ref!(visit_mut_ts_infer_type, TsInferType); - typed_ref!(visit_mut_ts_import_type, TsImportType); - typed_ref!(visit_mut_ts_tuple_type, TsTupleType); typed_ref!(visit_mut_ts_intersection_type, TsIntersectionType); @@ -1304,6 +1302,14 @@ impl<'a> VisitMut for Resolver<'a> { n.module_ref.visit_mut_with(self); } + fn visit_mut_ts_import_type(&mut self, n: &mut TsImportType) { + if !self.config.handle_types { + return; + } + + n.type_args.visit_mut_with(self); + } + 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; diff --git a/crates/swc_ecma_transforms_base/tests/ts-resolver/ts_import_type_qualifier/input.ts b/crates/swc_ecma_transforms_base/tests/ts-resolver/ts_import_type_qualifier/input.ts new file mode 100644 index 000000000000..6ce8c46be5d4 --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/ts-resolver/ts_import_type_qualifier/input.ts @@ -0,0 +1,7 @@ +import { MyClass } from "./MyClass.ts"; +const test = new MyClass(); + +// MyClass identifier here should be different +// than the one above. +export type MyType = import("./deps.ts").MyClass; +export type MyType2 = import("./deps.ts").MyClass; diff --git a/crates/swc_ecma_transforms_base/tests/ts-resolver/ts_import_type_qualifier/output.ts b/crates/swc_ecma_transforms_base/tests/ts-resolver/ts_import_type_qualifier/output.ts new file mode 100644 index 000000000000..781c40ab9381 --- /dev/null +++ b/crates/swc_ecma_transforms_base/tests/ts-resolver/ts_import_type_qualifier/output.ts @@ -0,0 +1,4 @@ +import { MyClass__2 } from "./MyClass.ts"; +const test__2 = new MyClass__2(); +export type MyType__2 = import("./deps.ts").MyClass__0; +export type MyType2__2 = import("./deps.ts").MyClass__0; From 67129fcd377122b7217488eedb0a49f63ba97cd6 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 18 Nov 2023 12:12:43 -0500 Subject: [PATCH 2/2] Reset CI?