fix autoformatting

This commit is contained in:
Evan Almloff committed 2023-09-19 09:39:53 -05:00
1 parent d297e2baa2
commit ab2b9fb34e
5 files changed
+57 -49

No files matched your search

+1
View File
@@ -49,6 +49,7 @@ impl Writer<'_> {
attributes, attributes,
children, children,
brace, brace,
..
} = el; } = el;
/* /*
+2 -1
View File
@@ -24,6 +24,7 @@ fn basic_syntax_is_a_template(cx: Scope) -> Element {
} }
}) })
} }
#[test] #[test]
fn dual_stream() { fn dual_stream() {
let mut dom = VirtualDom::new(basic_syntax_is_a_template); let mut dom = VirtualDom::new(basic_syntax_is_a_template);
@@ -36,7 +37,7 @@ fn dual_stream() {
LoadTemplate { name: "template", index: 0, id: ElementId(1) }, LoadTemplate { name: "template", index: 0, id: ElementId(1) },
SetAttribute { SetAttribute {
name: "class", name: "class",
value: (&*bump.alloc("123".into_value(&bump))).into(), value: (&*bump.alloc("ast 123".into_value(&bump))).into(),
id: ElementId(1), id: ElementId(1),
ns: None, ns: None,
}, },
+1
View File
@@ -79,6 +79,7 @@ pub fn rsx_node_from_html(node: &Node) -> Option<BodyNode> {
name: el_name, name: el_name,
children, children,
attributes, attributes,
merged_attributes: Default::default(),
key: None, key: None,
brace: Default::default(), brace: Default::default(),
})) }))
+14 -12
View File
@@ -1,7 +1,4 @@
use std::{ use std::fmt::{Display, Formatter};
collections::HashMap,
fmt::{Display, Formatter},
};
use super::*; use super::*;
@@ -22,6 +19,7 @@ pub struct Element {
pub name: ElementName, pub name: ElementName,
pub key: Option<IfmtInput>, pub key: Option<IfmtInput>,
pub attributes: Vec<ElementAttrNamed>, pub attributes: Vec<ElementAttrNamed>,
pub merged_attributes: Vec<ElementAttrNamed>,
pub children: Vec<BodyNode>, pub children: Vec<BodyNode>,
pub brace: syn::token::Brace, pub brace: syn::token::Brace,
} }
@@ -122,17 +120,20 @@ impl Parse for Element {
// Deduplicate any attributes that can be combined // Deduplicate any attributes that can be combined
// For example, if there are two `class` attributes, combine them into one // For example, if there are two `class` attributes, combine them into one
let mut combined_attrs: HashMap<ElementAttrName, ElementAttrNamed> = HashMap::new(); let mut merged_attributes: Vec<ElementAttrNamed> = Vec::new();
for attr in attributes { for attr in &attributes {
if let Some(old_attr) = combined_attrs.get_mut(&attr.attr.name) { if let Some(old_attr_index) = merged_attributes
if let Some(combined) = old_attr.try_combine(&attr) { .iter()
.position(|a| a.attr.name == attr.attr.name)
{
let old_attr = &mut merged_attributes[old_attr_index];
if let Some(combined) = old_attr.try_combine(attr) {
*old_attr = combined; *old_attr = combined;
} }
} else { } else {
combined_attrs.insert(attr.attr.name.clone(), attr); merged_attributes.push(attr.clone());
} }
} }
let attributes: Vec<_> = combined_attrs.into_iter().map(|(_, v)| v).collect();
while !content.is_empty() { while !content.is_empty() {
if (content.peek(LitStr) && content.peek2(Token![:])) && !content.peek3(Token![:]) { if (content.peek(LitStr) && content.peek2(Token![:])) && !content.peek3(Token![:]) {
@@ -155,6 +156,7 @@ impl Parse for Element {
key, key,
name: el_name, name: el_name,
attributes, attributes,
merged_attributes,
children, children,
brace, brace,
}) })
@@ -172,12 +174,12 @@ impl ToTokens for Element {
}; };
let listeners = self let listeners = self
.attributes .merged_attributes
.iter() .iter()
.filter(|f| matches!(f.attr.value, ElementAttrValue::EventTokens { .. })); .filter(|f| matches!(f.attr.value, ElementAttrValue::EventTokens { .. }));
let attr = self let attr = self
.attributes .merged_attributes
.iter() .iter()
.filter(|f| !matches!(f.attr.value, ElementAttrValue::EventTokens { .. })); .filter(|f| !matches!(f.attr.value, ElementAttrValue::EventTokens { .. }));
+39 -36
View File
@@ -308,7 +308,7 @@ impl DynamicMapping {
fn add_node(&mut self, node: BodyNode) { fn add_node(&mut self, node: BodyNode) {
match node { match node {
BodyNode::Element(el) => { BodyNode::Element(el) => {
for attr in el.attributes { for attr in el.merged_attributes {
match &attr.attr.value { match &attr.attr.value {
ElementAttrValue::AttrLiteral(input) if input.is_static() => {} ElementAttrValue::AttrLiteral(input) if input.is_static() => {}
_ => { _ => {
@@ -359,7 +359,7 @@ impl<'a> DynamicContext<'a> {
let element_name_rust = el.name.to_string(); let element_name_rust = el.name.to_string();
let mut static_attrs = Vec::new(); let mut static_attrs = Vec::new();
for attr in &el.attributes { for attr in &el.merged_attributes {
match &attr.attr.value { match &attr.attr.value {
ElementAttrValue::AttrLiteral(value) if value.is_static() => { ElementAttrValue::AttrLiteral(value) if value.is_static() => {
let value = value.source.as_ref().unwrap(); let value = value.source.as_ref().unwrap();
@@ -447,44 +447,47 @@ impl<'a> DynamicContext<'a> {
ElementName::Ident(i) => quote! { dioxus_elements::#i::#name }, ElementName::Ident(i) => quote! { dioxus_elements::#i::#name },
ElementName::Custom(_) => quote! { None }, ElementName::Custom(_) => quote! { None },
}; };
let static_attrs = el.attributes.iter().map(|attr| match &attr.attr.value { let static_attrs = el
ElementAttrValue::AttrLiteral(value) if value.is_static() => { .merged_attributes
let value = value.to_static().unwrap(); .iter()
let ns = { .map(|attr| match &attr.attr.value {
match &attr.attr.name { ElementAttrValue::AttrLiteral(value) if value.is_static() => {
ElementAttrName::BuiltIn(name) => ns(quote!(#name.1)), let value = value.to_static().unwrap();
ElementAttrName::Custom(_) => quote!(None), let ns = {
} match &attr.attr.name {
}; ElementAttrName::BuiltIn(name) => ns(quote!(#name.1)),
let name = &attr.attr.name; ElementAttrName::Custom(_) => quote!(None),
let name = match (el_name, name) { }
(ElementName::Ident(_), ElementAttrName::BuiltIn(_)) => { };
quote! { #el_name::#name.0 } let name = &attr.attr.name;
} let name = match (el_name, name) {
_ => { (ElementName::Ident(_), ElementAttrName::BuiltIn(_)) => {
let as_string = name.to_string(); quote! { #el_name::#name.0 }
quote! { #as_string } }
} _ => {
}; let as_string = name.to_string();
quote! { quote! { #as_string }
::dioxus::core::TemplateAttribute::Static { }
name: #name, };
namespace: #ns, quote! {
value: #value, ::dioxus::core::TemplateAttribute::Static {
name: #name,
namespace: #ns,
value: #value,
// todo: we don't diff these so we never apply the volatile flag // todo: we don't diff these so we never apply the volatile flag
// volatile: dioxus_elements::#el_name::#name.2, // volatile: dioxus_elements::#el_name::#name.2,
}
} }
} }
}
_ => { _ => {
let ct = self.dynamic_attributes.len(); let ct = self.dynamic_attributes.len();
self.dynamic_attributes.push(attr); self.dynamic_attributes.push(attr);
self.attr_paths.push(self.current_path.clone()); self.attr_paths.push(self.current_path.clone());
quote! { ::dioxus::core::TemplateAttribute::Dynamic { id: #ct } } quote! { ::dioxus::core::TemplateAttribute::Dynamic { id: #ct } }
} }
}); });
let attrs = quote! { #(#static_attrs),*}; let attrs = quote! { #(#static_attrs),*};