Merge branch 'upstream' into fix-non-str-attributes
This commit is contained in:
commit
afd024bcb6
106 files changed
+1415
-2115
No files matched your search
@@ -2,6 +2,7 @@ use crate::Buffer;
|
||||
use dioxus_rsx::*;
|
||||
use proc_macro2::Span;
|
||||
use std::{fmt::Result, fmt::Write};
|
||||
use syn::{spanned::Spanned, Expr};
|
||||
|
||||
#[derive(Debug)]
|
||||
enum ShortOptimization {
|
||||
@@ -83,12 +84,15 @@ impl Buffer {
|
||||
|
||||
self.write_attributes(attributes, key, true)?;
|
||||
|
||||
if !children.is_empty() && !attributes.is_empty() {
|
||||
if !children.is_empty() && (!attributes.is_empty() || key.is_some()) {
|
||||
write!(self.buf, ", ")?;
|
||||
}
|
||||
|
||||
for child in children {
|
||||
for (id, child) in children.iter().enumerate() {
|
||||
self.write_ident(child)?;
|
||||
if id != children.len() - 1 && children.len() > 1 {
|
||||
write!(self.buf, ", ")?;
|
||||
}
|
||||
}
|
||||
|
||||
write!(self.buf, " ")?;
|
||||
@@ -100,7 +104,7 @@ impl Buffer {
|
||||
}
|
||||
self.write_attributes(attributes, key, true)?;
|
||||
|
||||
if !children.is_empty() && !attributes.is_empty() {
|
||||
if !children.is_empty() && (!attributes.is_empty() || key.is_some()) {
|
||||
write!(self.buf, ",")?;
|
||||
}
|
||||
|
||||
@@ -113,7 +117,7 @@ impl Buffer {
|
||||
ShortOptimization::NoOpt => {
|
||||
self.write_attributes(attributes, key, false)?;
|
||||
|
||||
if !children.is_empty() && !attributes.is_empty() {
|
||||
if !children.is_empty() && (!attributes.is_empty() || key.is_some()) {
|
||||
write!(self.buf, ",")?;
|
||||
}
|
||||
|
||||
@@ -286,33 +290,66 @@ impl Buffer {
|
||||
|
||||
if attr_len > 80 {
|
||||
None
|
||||
} else if comp.children.is_empty() {
|
||||
Some(attr_len)
|
||||
} else {
|
||||
self.is_short_children(&comp.children)
|
||||
.map(|child_len| child_len + attr_len)
|
||||
None
|
||||
}
|
||||
}
|
||||
[BodyNode::RawExpr(ref _expr)] => {
|
||||
[BodyNode::RawExpr(ref expr)] => {
|
||||
// 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
|
||||
get_expr_length(expr)
|
||||
}
|
||||
[BodyNode::Element(ref el)] => {
|
||||
let attr_len = self.is_short_attrs(&el.attributes);
|
||||
|
||||
if attr_len > 80 {
|
||||
None
|
||||
} else {
|
||||
self.is_short_children(&el.children)
|
||||
.map(|child_len| child_len + attr_len)
|
||||
if el.children.is_empty() && attr_len < 80 {
|
||||
return Some(el.name.to_string().len());
|
||||
}
|
||||
|
||||
if el.children.len() == 1 {
|
||||
if let BodyNode::Text(ref text) = el.children[0] {
|
||||
let value = text.source.as_ref().unwrap().value();
|
||||
|
||||
if value.len() + el.name.to_string().len() + attr_len < 80 {
|
||||
return Some(value.len() + el.name.to_string().len() + attr_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
// todo, allow non-elements to be on the same line
|
||||
items => {
|
||||
let mut total_count = 0;
|
||||
|
||||
for item in items {
|
||||
match item {
|
||||
BodyNode::Component(_) | BodyNode::Element(_) => return None,
|
||||
BodyNode::Text(text) => {
|
||||
total_count += text.source.as_ref().unwrap().value().len()
|
||||
}
|
||||
BodyNode::RawExpr(expr) => match get_expr_length(expr) {
|
||||
Some(len) => total_count += len,
|
||||
None => return None,
|
||||
},
|
||||
BodyNode::ForLoop(_) => todo!(),
|
||||
BodyNode::IfChain(_) => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
Some(total_count)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_expr_length(expr: &Expr) -> Option<usize> {
|
||||
let span = expr.span();
|
||||
let (start, end) = (span.start(), span.end());
|
||||
if start.line == end.line {
|
||||
Some(end.column - start.column)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user