From 057bd5f3efe55077a5a8e7f627e80175c8af2bd0 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 28 Aug 2023 21:39:05 -0400 Subject: [PATCH] fix(es/dep-graph): Analyze import type children (#7883) **Description:** It was not analyzing children of a dynamic imports. --- crates/swc_ecma_dep_graph/src/lib.rs | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/crates/swc_ecma_dep_graph/src/lib.rs b/crates/swc_ecma_dep_graph/src/lib.rs index 64e3eb11edde..e94780e9a5b8 100644 --- a/crates/swc_ecma_dep_graph/src/lib.rs +++ b/crates/swc_ecma_dep_graph/src/lib.rs @@ -177,6 +177,7 @@ impl<'a> Visit for DependencyCollector<'a> { specifier_span: node.arg.span, import_attributes: Default::default(), }); + node.visit_children_with(self); } fn visit_module_items(&mut self, items: &[ast::ModuleItem]) { @@ -810,4 +811,47 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad" ] ); } + + #[test] + fn ts_import_object_lit_property() { + let source = r#" +export declare const SomeValue: typeof Core & import("./a.d.ts").Constructor<{ + paginate: import("./b.d.ts").PaginateInterface; +} & import("./c.d.ts").RestEndpointMethods>; +"#; + let (module, comments) = helper("test.ts", source).unwrap(); + let dependencies = analyze_dependencies(&module, &comments); + assert_eq!( + dependencies, + vec![ + DependencyDescriptor { + kind: DependencyKind::ImportType, + is_dynamic: false, + leading_comments: Vec::new(), + span: Span::new(BytePos(48), BytePos(176), Default::default()), + specifier: JsWord::from("./a.d.ts"), + specifier_span: Span::new(BytePos(55), BytePos(65), Default::default()), + import_attributes: ImportAttributes::None, + }, + DependencyDescriptor { + kind: DependencyKind::ImportType, + is_dynamic: false, + leading_comments: Vec::new(), + span: Span::new(BytePos(95), BytePos(131), Default::default()), + specifier: JsWord::from("./b.d.ts"), + specifier_span: Span::new(BytePos(102), BytePos(112), Default::default()), + import_attributes: ImportAttributes::None, + }, + DependencyDescriptor { + kind: DependencyKind::ImportType, + is_dynamic: false, + leading_comments: Vec::new(), + span: Span::new(BytePos(137), BytePos(175), Default::default()), + specifier: JsWord::from("./c.d.ts"), + specifier_span: Span::new(BytePos(144), BytePos(154), Default::default()), + import_attributes: ImportAttributes::None, + } + ] + ); + } }