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 SideEffect,
65}
66
67#[derive(Debug, Clone, Copy, PartialEq, Eq)]
68pub enum ImportKind {
69 Esm,
70 CommonJs,
71 Dynamic,
73 Mock,
77}
78
79#[derive(Debug, Clone)]
80pub struct ReexportFact {
81 pub source: String,
82 pub imported: ReexportTarget,
83 pub exported: String,
84 pub is_ambiguous: bool,
85}
86
87#[derive(Debug, Clone, PartialEq, Eq)]
88pub enum ReexportTarget {
89 Name(String),
90 Default,
91 Namespace,
92 All,
93}