use serde::Deserialize;
use super::vue::VueVersion;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "lowercase")]
pub(crate) enum RawTemplateSyntaxConfig {
Standard,
Strict,
Quirks,
}
impl RawTemplateSyntaxConfig {
pub(crate) fn as_str(self) -> &'static str {
match self {
Self::Standard => "standard",
Self::Strict => "strict",
Self::Quirks => "quirks",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum JsxMode {
#[default]
Vdom,
Vapor,
}
impl JsxMode {
pub fn as_str(self) -> &'static str {
match self {
Self::Vdom => "vdom",
Self::Vapor => "vapor",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum JsxCompat {
#[default]
Native,
Babel,
}
impl JsxCompat {
pub fn as_str(self) -> &'static str {
match self {
Self::Native => "native",
Self::Babel => "babel",
}
}
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub(crate) struct RawCompilerCompatibilityConfig {
pub(crate) vue_version: Option<VueVersion>,
pub(crate) host_compiler: Option<bool>,
}
#[derive(Debug, Clone, Default, Deserialize)]
#[serde(default, rename_all = "camelCase")]
pub(crate) struct RawCompilerConfig {
pub(crate) vapor: Option<bool>,
pub(crate) template_syntax: Option<RawTemplateSyntaxConfig>,
#[serde(deserialize_with = "deserialize_whitespace")]
pub(crate) whitespace: Option<String>,
pub(crate) jsx_mode: Option<JsxMode>,
pub(crate) jsx_compat: Option<JsxCompat>,
pub(crate) custom_elements: Vec<crate::String>,
pub(crate) compatibility: RawCompilerCompatibilityConfig,
}
fn deserialize_whitespace<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
where
D: serde::Deserializer<'de>,
{
let raw = Option::<Box<serde_json::value::RawValue>>::deserialize(deserializer)?;
raw.filter(|value| value.get().starts_with('"'))
.map(|value| serde_json::from_str(value.get()).map_err(serde::de::Error::custom))
.transpose()
}