fix formatting and merging if chains in attributes (#2697)

* fix formatting and merging if chains in attributes

* fix autoformat if attribute chains

* Fix IfAttributeValue ToTokens implementation

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Evan AlmloffandJonathan Kelley authored and GitHub committed 2024-07-24 18:56:21 -07:00
1 parent a6e41e9d68
commit 7f210633eb
8 files changed
+301 -145

No files matched your search

+12 -4
View File
@@ -249,10 +249,18 @@ impl<'a> Writer<'a> {
pub(crate) fn attr_value_len(&mut self, value: &ElementAttrValue) -> usize {
match value {
ElementAttrValue::AttrOptionalExpr { condition, value } => {
let condition_len = self.retrieve_formatted_expr(condition).len();
let value_len = self.attr_value_len(value);
condition_len + value_len + 6
ElementAttrValue::IfExpr(if_chain) => {
let condition_len = self.retrieve_formatted_expr(&if_chain.condition).len();
let value_len = self.attr_value_len(&if_chain.then_value);
let if_len = 2;
let brace_len = 2;
let space_len = 2;
let else_len = if_chain
.else_value
.as_ref()
.map(|else_value| self.attr_value_len(else_value) + 1)
.unwrap_or_default();
condition_len + value_len + if_len + brace_len + space_len + else_len
}
ElementAttrValue::AttrLiteral(lit) => lit.to_string().len(),
ElementAttrValue::Shorthand(expr) => expr.span().line_length(),