diff --git a/packages/autofmt/src/element.rs b/packages/autofmt/src/element.rs index 39a58d801..e886bfca0 100644 --- a/packages/autofmt/src/element.rs +++ b/packages/autofmt/src/element.rs @@ -84,7 +84,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, ", ")?; } @@ -104,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, ",")?; } @@ -117,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, ",")?; } @@ -282,9 +282,10 @@ 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)] => { diff --git a/packages/autofmt/tests/samples.rs b/packages/autofmt/tests/samples.rs index 98383522a..954fa8201 100644 --- a/packages/autofmt/tests/samples.rs +++ b/packages/autofmt/tests/samples.rs @@ -25,3 +25,5 @@ twoway! ("tiny" => tiny); twoway! ("tinynoopt" => tinynoopt); twoway! ("long" => long); + +twoway! ("key" => key); diff --git a/packages/autofmt/tests/samples/key.rsx b/packages/autofmt/tests/samples/key.rsx new file mode 100644 index 000000000..c97b6db38 --- /dev/null +++ b/packages/autofmt/tests/samples/key.rsx @@ -0,0 +1,9 @@ +rsx! { + li { key: "{link}", + Link { class: "py-1 px-2 {hover} {hover_bg}", to: "{link}", "{name}" } + } + + li { key: "{link}", asd: "asd", + Link { class: "py-1 px-2 {hover} {hover_bg}", to: "{link}", "{name}" } + } +}