|
@@ -28,6 +28,7 @@ impl Writer<'_> {
|
|
|
children,
|
|
|
manual_props,
|
|
|
prop_gen_args,
|
|
|
+ key,
|
|
|
..
|
|
|
}: &Component,
|
|
|
) -> Result {
|
|
@@ -38,7 +39,7 @@ impl Writer<'_> {
|
|
|
let mut opt_level = ShortOptimization::NoOpt;
|
|
|
|
|
|
// check if we have a lot of attributes
|
|
|
- let attr_len = self.field_len(fields, manual_props);
|
|
|
+ let attr_len = self.field_len(fields, manual_props) + self.key_len(key.as_ref());
|
|
|
let is_short_attr_list = attr_len < 80;
|
|
|
let is_small_children = self.is_short_children(children).is_some();
|
|
|
|
|
@@ -62,7 +63,7 @@ impl Writer<'_> {
|
|
|
}
|
|
|
|
|
|
// If there's nothing at all, empty optimization
|
|
|
- if fields.is_empty() && children.is_empty() && manual_props.is_none() {
|
|
|
+ if fields.is_empty() && children.is_empty() && manual_props.is_none() && key.is_none() {
|
|
|
opt_level = ShortOptimization::Empty;
|
|
|
}
|
|
|
|
|
@@ -85,7 +86,7 @@ impl Writer<'_> {
|
|
|
ShortOptimization::Oneliner => {
|
|
|
write!(self.out, " ")?;
|
|
|
|
|
|
- self.write_component_fields(fields, manual_props, true)?;
|
|
|
+ self.write_component_fields(fields, key.as_ref(), manual_props, true)?;
|
|
|
|
|
|
if !children.is_empty() && !fields.is_empty() {
|
|
|
write!(self.out, ", ")?;
|
|
@@ -103,7 +104,7 @@ impl Writer<'_> {
|
|
|
|
|
|
ShortOptimization::PropsOnTop => {
|
|
|
write!(self.out, " ")?;
|
|
|
- self.write_component_fields(fields, manual_props, true)?;
|
|
|
+ self.write_component_fields(fields, key.as_ref(), manual_props, true)?;
|
|
|
|
|
|
if !children.is_empty() && !fields.is_empty() {
|
|
|
write!(self.out, ",")?;
|
|
@@ -114,7 +115,7 @@ impl Writer<'_> {
|
|
|
}
|
|
|
|
|
|
ShortOptimization::NoOpt => {
|
|
|
- self.write_component_fields(fields, manual_props, false)?;
|
|
|
+ self.write_component_fields(fields, key.as_ref(), manual_props, false)?;
|
|
|
|
|
|
if !children.is_empty() && !fields.is_empty() {
|
|
|
write!(self.out, ",")?;
|
|
@@ -154,11 +155,23 @@ impl Writer<'_> {
|
|
|
fn write_component_fields(
|
|
|
&mut self,
|
|
|
fields: &[ComponentField],
|
|
|
+ key: Option<&IfmtInput>,
|
|
|
manual_props: &Option<syn::Expr>,
|
|
|
sameline: bool,
|
|
|
) -> Result {
|
|
|
let mut field_iter = fields.iter().peekable();
|
|
|
|
|
|
+ // write the key
|
|
|
+ if let Some(key) = key {
|
|
|
+ write!(self.out, "key: {}", ifmt_to_string(key))?;
|
|
|
+ if !fields.is_empty() {
|
|
|
+ write!(self.out, ",")?;
|
|
|
+ if sameline {
|
|
|
+ write!(self.out, " ")?;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
while let Some(field) = field_iter.next() {
|
|
|
if !sameline {
|
|
|
self.out.indented_tabbed_line().unwrap();
|