hearth_graph/imports/mod.rs
1//! Import extraction types and per-language extractors.
2//!
3//! [`ImportSpec`]: crate::lang::ImportSpec
4
5use compact_str::CompactString;
6
7pub(crate) mod js;
8#[cfg(feature = "bundled-languages")]
9pub(crate) mod rust;
10
11/// How an import reference appears in source.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13pub enum ImportKind {
14 /// `import ... from "x"`.
15 EsStatic,
16 /// `export ... from "x"`.
17 EsReexport,
18 /// `import("x")` with a literal specifier.
19 EsDynamic,
20 /// `require("x")`.
21 CommonJs,
22 /// TypeScript `import x = require("x")`.
23 TsImportRequire,
24 /// Rust `use` path, flattened to one leaf per import. The specifier is
25 /// the normalized leaf path (`a::b::c`), not the byte-for-byte source
26 /// text — grouped and aliased use-trees have no single as-written form
27 /// per leaf.
28 RustUse,
29 /// Rust `mod name;` without a body.
30 RustMod,
31}
32
33/// One import extracted from a file, with the specifier as written.
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub struct RawImport {
36 /// Import specifier text as written in the source.
37 pub specifier: CompactString,
38 /// Syntactic form the import took.
39 pub kind: ImportKind,
40 /// 1-based line of the specifier.
41 pub line: u32,
42 /// Byte range of the specifier — the grep-backstop anchor.
43 pub span: (u32, u32),
44}