use vize_carton::{FxHashMap, String};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ParseMode {
#[default]
Base,
Html,
Sfc,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TextMode {
#[default]
Data,
RcData,
RawText,
CData,
AttributeValue,
}
#[derive(Debug, Clone)]
pub struct ParserOptions {
pub mode: ParseMode,
pub whitespace: WhitespaceStrategy,
pub delimiters: (String, String),
pub is_pre_tag: fn(&str) -> bool,
pub is_native_tag: Option<fn(&str) -> bool>,
pub is_custom_element: Option<fn(&str) -> bool>,
pub is_void_tag: fn(&str) -> bool,
pub get_namespace: fn(&str, Option<&str>) -> crate::Namespace,
pub on_error: Option<fn(crate::CompilerError)>,
pub on_warn: Option<fn(crate::CompilerError)>,
pub comments: bool,
}
impl Default for ParserOptions {
fn default() -> Self {
Self {
mode: ParseMode::Base,
whitespace: WhitespaceStrategy::Condense,
delimiters: (String::from("{{"), String::from("}}")),
is_pre_tag: |_| false,
is_native_tag: None,
is_custom_element: None,
is_void_tag: vize_carton::is_void_tag,
get_namespace: |_, _| crate::Namespace::Html,
on_error: None,
on_warn: None,
comments: true,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum WhitespaceStrategy {
#[default]
Condense,
Preserve,
}
#[derive(Debug, Clone)]
pub struct TransformOptions {
pub filename: String,
pub prefix_identifiers: bool,
pub hoist_static: bool,
pub cache_handlers: bool,
pub scope_id: Option<String>,
pub ssr: bool,
pub ssr_css_vars: Option<String>,
pub binding_metadata: Option<BindingMetadata>,
pub inline: bool,
pub is_ts: bool,
}
impl Default for TransformOptions {
fn default() -> Self {
Self {
filename: String::from("template.vue"),
prefix_identifiers: false,
hoist_static: false,
cache_handlers: false,
scope_id: None,
ssr: false,
ssr_css_vars: None,
binding_metadata: None,
inline: false,
is_ts: false,
}
}
}
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BindingMetadata {
pub bindings: FxHashMap<std::string::String, BindingType>,
pub props_aliases: FxHashMap<std::string::String, std::string::String>,
pub is_script_setup: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
#[repr(u8)]
pub enum BindingType {
SetupLet = 0,
SetupMaybeRef = 1,
SetupRef = 2,
SetupReactiveConst = 3,
SetupConst = 4,
Props = 5,
PropsAliased = 6,
Data = 7,
Options = 8,
LiteralConst = 9,
JsGlobalUniversal = 10,
JsGlobalBrowser = 11,
JsGlobalNode = 12,
JsGlobalDeno = 13,
JsGlobalBun = 14,
VueGlobal = 15,
ExternalModule = 16,
}
impl BindingType {
#[inline]
pub const fn to_vir(self) -> &'static str {
match self {
Self::SetupLet => "let",
Self::SetupMaybeRef => "st?",
Self::SetupRef => "st",
Self::SetupReactiveConst => "ist",
Self::SetupConst => "c",
Self::Props => "ist", Self::PropsAliased => "ist", Self::Data => "data",
Self::Options => "opt",
Self::LiteralConst => "lit",
Self::JsGlobalUniversal => "~js",
Self::JsGlobalBrowser => "!js",
Self::JsGlobalNode => "#js",
Self::JsGlobalDeno => "#deno",
Self::JsGlobalBun => "#bun",
Self::VueGlobal => "vue",
Self::ExternalModule => "ext",
}
}
}
#[derive(Debug, Clone)]
pub struct CodegenOptions {
pub mode: CodegenMode,
pub prefix_identifiers: bool,
pub source_map: bool,
pub filename: String,
pub scope_id: Option<String>,
pub ssr: bool,
pub optimize_imports: bool,
pub runtime_module_name: String,
pub runtime_global_name: String,
pub is_ts: bool,
pub inline: bool,
pub binding_metadata: Option<BindingMetadata>,
pub cache_handlers: bool,
}
impl Default for CodegenOptions {
fn default() -> Self {
Self {
mode: CodegenMode::Function,
prefix_identifiers: false,
source_map: false,
filename: String::from("template.vue"),
scope_id: None,
ssr: false,
optimize_imports: false,
runtime_module_name: String::from("vue"),
runtime_global_name: String::from("Vue"),
is_ts: false,
inline: false,
binding_metadata: None,
cache_handlers: false,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum CodegenMode {
#[default]
Function,
Module,
}
#[derive(Debug, Clone, Default)]
pub struct CompilerOptions {
pub parser: ParserOptions,
pub transform: TransformOptions,
pub codegen: CodegenOptions,
}