use vize_carton::String;
use crate::transform::TransformContext;
use crate::*;
pub fn process_v_bind(ctx: &mut TransformContext<'_>, dir: &DirectiveNode<'_>) {
let prop_name = dir.arg.as_ref().map(|arg| match arg {
ExpressionNode::Simple(exp) => exp.content.clone(),
ExpressionNode::Compound(exp) => exp.loc.source.clone(),
});
if prop_name.is_none() {
if dir.exp.is_some() {
ctx.helper(RuntimeHelper::MergeProps);
}
return;
}
let prop_name = match prop_name {
Some(name) => name,
None => return,
};
match prop_name.as_str() {
"class" => {
ctx.helper(RuntimeHelper::NormalizeClass);
}
"style" => {
ctx.helper(RuntimeHelper::NormalizeStyle);
}
"key" | "ref" => {
}
_ => {}
}
}
pub fn get_bind_name(dir: &DirectiveNode<'_>) -> Option<String> {
dir.arg.as_ref().map(|arg| match arg {
ExpressionNode::Simple(exp) => exp.content.clone(),
ExpressionNode::Compound(exp) => exp.loc.source.clone(),
})
}
pub fn get_bind_value<'a>(dir: &'a DirectiveNode<'a>) -> Option<&'a ExpressionNode<'a>> {
dir.exp.as_ref()
}
pub fn has_camel_modifier(dir: &DirectiveNode<'_>) -> bool {
dir.modifiers.iter().any(|m| m.content == "camel")
}
pub fn has_prop_modifier(dir: &DirectiveNode<'_>) -> bool {
dir.modifiers.iter().any(|m| m.content == "prop")
}
pub fn has_attr_modifier(dir: &DirectiveNode<'_>) -> bool {
dir.modifiers.iter().any(|m| m.content == "attr")
}
pub fn is_dynamic_binding(dir: &DirectiveNode<'_>) -> bool {
if let Some(arg) = &dir.arg {
match arg {
ExpressionNode::Simple(exp) => !exp.is_static,
ExpressionNode::Compound(_) => true,
}
} else {
true }
}
pub use vize_carton::camelize;
#[cfg(test)]
mod tests {
use super::camelize;
#[test]
fn test_camelize() {
assert_eq!(camelize("foo-bar").as_str(), "fooBar");
assert_eq!(camelize("foo-bar-baz").as_str(), "fooBarBaz");
assert_eq!(camelize("foo").as_str(), "foo");
}
}