mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(prettier): print empty object properties (#1409)
This commit is contained in:
parent
70b80ba542
commit
bc3069ec76
2 changed files with 29 additions and 33 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use oxc_allocator::Vec;
|
||||
|
||||
use crate::{doc::Doc, group, if_break, ss, Prettier};
|
||||
use crate::{doc::Doc, group, if_break, line, softline, ss, Prettier};
|
||||
|
||||
use super::Format;
|
||||
|
||||
|
|
@ -8,36 +8,35 @@ pub(super) fn print_object_properties<'a, F: Format<'a>>(
|
|||
p: &mut Prettier<'a>,
|
||||
properties: &Vec<'a, F>,
|
||||
) -> Doc<'a> {
|
||||
let mut parts = p.vec();
|
||||
parts.push(ss!("{"));
|
||||
let left_brace = ss!("{");
|
||||
let right_brace = ss!("}");
|
||||
|
||||
let mut indent_parts = p.vec();
|
||||
|
||||
if p.options.bracket_spacing {
|
||||
indent_parts.push(Doc::Line);
|
||||
let content = if properties.is_empty() {
|
||||
group![p, left_brace, softline!(), right_brace]
|
||||
} else {
|
||||
indent_parts.push(Doc::Softline);
|
||||
let mut parts = p.vec();
|
||||
parts.push(ss!("{"));
|
||||
|
||||
let mut indent_parts = p.vec();
|
||||
indent_parts.push(if p.options.bracket_spacing { line!() } else { softline!() });
|
||||
for (i, prop) in properties.iter().enumerate() {
|
||||
indent_parts.push(prop.format(p));
|
||||
if i < properties.len() - 1 {
|
||||
indent_parts.push(Doc::Str(","));
|
||||
indent_parts.push(Doc::Line);
|
||||
}
|
||||
}
|
||||
parts.push(group!(p, Doc::Indent(indent_parts)));
|
||||
parts.push(if_break!(p, ","));
|
||||
|
||||
if p.options.bracket_spacing {
|
||||
parts.push(Doc::Line);
|
||||
} else {
|
||||
parts.push(Doc::Softline);
|
||||
}
|
||||
parts.push(ss!("}"));
|
||||
Doc::Array(parts)
|
||||
};
|
||||
|
||||
let len = properties.len();
|
||||
properties.iter().map(|prop| prop.format(p)).enumerate().for_each(|(i, prop)| {
|
||||
indent_parts.push(prop);
|
||||
if i < len - 1 {
|
||||
indent_parts.push(Doc::Str(","));
|
||||
indent_parts.push(Doc::Line);
|
||||
}
|
||||
});
|
||||
|
||||
parts.push(group!(p, Doc::Indent(indent_parts)));
|
||||
parts.push(if_break!(p, ","));
|
||||
|
||||
if p.options.bracket_spacing {
|
||||
parts.push(Doc::Line);
|
||||
} else {
|
||||
parts.push(Doc::Softline);
|
||||
}
|
||||
|
||||
parts.push(ss!("}"));
|
||||
|
||||
Doc::Group(parts)
|
||||
content
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Compatibility: 98/838 (11.69%)
|
||||
Compatibility: 101/838 (12.05%)
|
||||
|
||||
# Failed
|
||||
|
||||
|
|
@ -29,7 +29,6 @@ Compatibility: 98/838 (11.69%)
|
|||
* arrows/arrow-chain-with-trailing-comments.js
|
||||
* arrows/arrow_function_expression.js
|
||||
* arrows/assignment-chain-with-arrow-chain.js
|
||||
* arrows/block_like.js
|
||||
* arrows/call.js
|
||||
* arrows/chain-as-arg.js
|
||||
* arrows/chain-in-logical-expression.js
|
||||
|
|
@ -451,7 +450,6 @@ Compatibility: 98/838 (11.69%)
|
|||
|
||||
### export
|
||||
* export/blank-line-between-specifiers.js
|
||||
* export/bracket.js
|
||||
* export/empty.js
|
||||
* export/same-local-and-exported.js
|
||||
|
||||
|
|
@ -479,7 +477,6 @@ Compatibility: 98/838 (11.69%)
|
|||
* for/continue-and-break-comment-without-blocks.js
|
||||
* for/for.js
|
||||
* for/in.js
|
||||
* for/var.js
|
||||
|
||||
### for-await
|
||||
* for-await/for-await.js
|
||||
|
|
|
|||
Loading…
Reference in a new issue