feat: more cleanup
This commit is contained in:
1 parent
fa756ba245
commit
bd936d3af2
3 files changed
+36
-8
No files matched your search
@@ -36,7 +36,7 @@ impl Buffer {
|
|||||||
let mut opt_level = ShortOptimization::NoOpt;
|
let mut opt_level = ShortOptimization::NoOpt;
|
||||||
|
|
||||||
// check if we have a lot of attributes
|
// check if we have a lot of attributes
|
||||||
let is_short_attr_list = self.is_short_fields(fields, manual_props);
|
let is_short_attr_list = self.is_short_fields(fields, manual_props).is_some();
|
||||||
let is_small_children = self.is_short_children(children).is_some();
|
let is_small_children = self.is_short_children(children).is_some();
|
||||||
|
|
||||||
// if we have few attributes and a lot of children, place the attrs on top
|
// if we have few attributes and a lot of children, place the attrs on top
|
||||||
@@ -179,7 +179,11 @@ impl Buffer {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn is_short_fields(&self, fields: &[ComponentField], manual_props: &Option<syn::Expr>) -> bool {
|
pub fn is_short_fields(
|
||||||
|
&self,
|
||||||
|
fields: &[ComponentField],
|
||||||
|
manual_props: &Option<syn::Expr>,
|
||||||
|
) -> Option<usize> {
|
||||||
let attr_len = fields
|
let attr_len = fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|field| match &field.content {
|
.map(|field| match &field.content {
|
||||||
@@ -193,14 +197,18 @@ impl Buffer {
|
|||||||
Some(p) => {
|
Some(p) => {
|
||||||
let content = prettyplease::unparse_expr(p);
|
let content = prettyplease::unparse_expr(p);
|
||||||
if content.len() + attr_len > 80 {
|
if content.len() + attr_len > 80 {
|
||||||
return false;
|
return None;
|
||||||
}
|
}
|
||||||
let mut lines = content.lines();
|
let mut lines = content.lines();
|
||||||
lines.next().unwrap();
|
lines.next().unwrap();
|
||||||
|
|
||||||
lines.next().is_none()
|
if lines.next().is_none() {
|
||||||
|
Some(attr_len + content.len())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => attr_len < 80,
|
None => Some(attr_len),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,8 +217,6 @@ impl Buffer {
|
|||||||
We want to normalize the expr to the appropriate indent level.
|
We want to normalize the expr to the appropriate indent level.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use syn::spanned::Spanned;
|
|
||||||
|
|
||||||
let formatted = prettyplease::unparse_expr(exp);
|
let formatted = prettyplease::unparse_expr(exp);
|
||||||
|
|
||||||
let mut lines = formatted.lines();
|
let mut lines = formatted.lines();
|
||||||
|
|||||||
@@ -223,6 +223,28 @@ impl Buffer {
|
|||||||
|
|
||||||
match children {
|
match children {
|
||||||
[BodyNode::Text(ref text)] => Some(text.value().len()),
|
[BodyNode::Text(ref text)] => Some(text.value().len()),
|
||||||
|
[BodyNode::Component(ref comp)] => {
|
||||||
|
let is_short_child = self.is_short_children(&comp.children);
|
||||||
|
let is_short_attrs = self.is_short_fields(&comp.fields, &comp.manual_props);
|
||||||
|
|
||||||
|
match (is_short_child, is_short_attrs) {
|
||||||
|
(Some(child_len), Some(attrs_len)) => Some(child_len + attrs_len),
|
||||||
|
(Some(child_len), None) => Some(child_len),
|
||||||
|
(None, Some(attrs_len)) => Some(attrs_len),
|
||||||
|
(None, None) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[BodyNode::RawExpr(ref text)] => {
|
||||||
|
// TODO: let rawexprs to be inlined
|
||||||
|
// let span = syn::spanned::Spanned::span(&text);
|
||||||
|
// let (start, end) = (span.start(), span.end());
|
||||||
|
// if start.line == end.line {
|
||||||
|
// Some(end.column - start.column)
|
||||||
|
// } else {
|
||||||
|
// None
|
||||||
|
// }
|
||||||
|
None
|
||||||
|
}
|
||||||
[BodyNode::Element(ref el)] => self
|
[BodyNode::Element(ref el)] => self
|
||||||
.is_short_children(&el.children)
|
.is_short_children(&el.children)
|
||||||
.map(|f| f + extract_attr_len(&el.attributes))
|
.map(|f| f + extract_attr_len(&el.attributes))
|
||||||
|
|||||||
@@ -435,7 +435,7 @@ fn formats_complex() {
|
|||||||
icons::icon_0 {}
|
icons::icon_0 {}
|
||||||
}
|
}
|
||||||
span { "{name}" }
|
span { "{name}" }
|
||||||
children.is_some().then(|| rsx!{
|
children.is_some().then(|| rsx! {
|
||||||
span {
|
span {
|
||||||
class: "inline-block ml-auto hover:bg-gray-500",
|
class: "inline-block ml-auto hover:bg-gray-500",
|
||||||
onclick: move |evt| {
|
onclick: move |evt| {
|
||||||
|
|||||||
Reference in new issue
Block a user