blast_radius/parse/
facts.rs1use std::collections::{BTreeMap, BTreeSet};
2use std::path::{Path, PathBuf};
3
4#[derive(Debug, Clone)]
5pub struct ModuleFacts {
6 pub file: PathBuf,
7 pub exports: Vec<ExportFact>,
8 pub imports: Vec<ImportFact>,
9 pub reexports: Vec<ReexportFact>,
10 pub used_locals: BTreeSet<String>,
11 pub jsx_locals: BTreeSet<String>,
12 pub namespace_member_usage: BTreeMap<String, BTreeSet<String>>,
13 pub jsx_namespace_member_usage: BTreeMap<String, BTreeSet<String>>,
14 pub warnings: Vec<String>,
15}
16
17impl ModuleFacts {
18 pub(super) fn empty(file: &Path) -> Self {
19 Self {
20 file: file.to_path_buf(),
21 exports: Vec::new(),
22 imports: Vec::new(),
23 reexports: Vec::new(),
24 used_locals: BTreeSet::new(),
25 jsx_locals: BTreeSet::new(),
26 namespace_member_usage: BTreeMap::new(),
27 jsx_namespace_member_usage: BTreeMap::new(),
28 warnings: Vec::new(),
29 }
30 }
31}
32
33#[derive(Debug, Clone)]
34pub struct ExportFact {
35 pub exported: String,
36 pub local: Option<String>,
37 pub kind: ExportKind,
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum ExportKind {
42 Local,
43 Default,
44 Reexport,
45 CommonJs,
46}
47
48#[derive(Debug, Clone)]
49pub struct ImportFact {
50 pub source: String,
51 pub local: String,
52 pub imported: ImportTarget,
53 pub kind: ImportKind,
54 pub type_only: bool,
55}
56
57#[derive(Debug, Clone, PartialEq, Eq)]
58pub enum ImportTarget {
59 Name(String),
60 Default,
61 Namespace,
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
65pub enum ImportKind {
66 Esm,
67 CommonJs,
68}
69
70#[derive(Debug, Clone)]
71pub struct ReexportFact {
72 pub source: String,
73 pub imported: ReexportTarget,
74 pub exported: String,
75 pub is_ambiguous: bool,
76}
77
78#[derive(Debug, Clone, PartialEq, Eq)]
79pub enum ReexportTarget {
80 Name(String),
81 Default,
82 Namespace,
83 All,
84}