mod analysis;
mod builder;
use vize_carton::{CompactString, FxHashMap, FxHashSet, SmallVec};
use crate::scope::ScopeId;
pub use builder::{is_composable_name, is_vue_api};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct FunctionId(u32);
impl FunctionId {
#[inline(always)]
pub const fn new(id: u32) -> Self {
Self(id)
}
#[inline(always)]
pub const fn as_u32(self) -> u32 {
self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum VueApiCategory {
Reactivity,
Lifecycle,
DependencyInjection,
Watcher,
TemplateRef,
Other,
}
#[derive(Debug, Clone)]
pub struct VueApiCall {
pub name: CompactString,
pub category: VueApiCategory,
pub scope_id: ScopeId,
pub containing_function: Option<FunctionId>,
pub in_setup_context: bool,
pub start: u32,
pub end: u32,
}
#[derive(Debug, Clone)]
pub struct FunctionDef {
pub id: FunctionId,
pub name: Option<CompactString>,
pub scope_id: ScopeId,
pub parent_function: Option<FunctionId>,
pub is_arrow: bool,
pub called_in_setup: bool,
pub uses_vue_apis: bool,
pub is_composable: bool,
pub start: u32,
pub end: u32,
}
#[derive(Debug, Clone)]
pub struct ComposableCallInfo {
pub name: CompactString,
pub source: Option<CompactString>,
pub scope_id: ScopeId,
pub containing_function: Option<FunctionId>,
pub in_setup_context: bool,
pub local_binding: Option<CompactString>,
pub vue_apis_used: SmallVec<[CompactString; 4]>,
pub start: u32,
pub end: u32,
}
#[derive(Debug, Clone)]
pub struct CallEdge {
pub caller: FunctionId,
pub callee: FunctionId,
pub call_site: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum SetupContextKind {
SetupBody,
Composable,
ComposableCallback,
None,
}
#[derive(Debug, Default)]
pub struct CallGraph {
pub(crate) functions: Vec<FunctionDef>,
pub(crate) vue_api_calls: Vec<VueApiCall>,
pub(crate) composable_calls: Vec<ComposableCallInfo>,
pub(crate) call_edges: Vec<CallEdge>,
pub(crate) function_by_name: FxHashMap<CompactString, SmallVec<[FunctionId; 2]>>,
pub(crate) setup_context_functions: FxHashSet<FunctionId>,
pub(crate) setup_function: Option<FunctionId>,
pub(crate) next_id: u32,
}