mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(prettier): format SequenceExpression and ParenthesizedExpression (#1397)
This commit is contained in:
parent
08f00cbd82
commit
8cb0795796
3 changed files with 15 additions and 9 deletions
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
use oxc_allocator::{Allocator, Box, String, Vec};
|
||||
|
||||
use crate::Prettier;
|
||||
use crate::{array, line, ss, Prettier};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Doc<'a> {
|
||||
|
|
@ -106,6 +106,7 @@ impl<'a> DocPrinter<'a> {
|
|||
pub enum Separator {
|
||||
Softline,
|
||||
Hardline,
|
||||
CommaLine, // [",", line]
|
||||
}
|
||||
|
||||
/// Doc Builder
|
||||
|
|
@ -137,6 +138,7 @@ impl<'a> Prettier<'a> {
|
|||
parts.push(match separator {
|
||||
Separator::Softline => Doc::Softline,
|
||||
Separator::Hardline => Doc::Hardline,
|
||||
Separator::CommaLine => array![self, ss!(","), line!()],
|
||||
});
|
||||
}
|
||||
parts.push(doc);
|
||||
|
|
|
|||
|
|
@ -1512,14 +1512,21 @@ impl<'a> Format<'a> for AssignmentTargetPropertyProperty<'a> {
|
|||
impl<'a> Format<'a> for SequenceExpression<'a> {
|
||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||
let docs = self.expressions.iter().map(|expr| expr.format(p)).collect::<std::vec::Vec<_>>();
|
||||
// FIXME: group(join([",", line], path.map(print, "expressions")));
|
||||
group![p, Doc::Array(p.join(Separator::Softline, docs))]
|
||||
group![p, Doc::Array(p.join(Separator::CommaLine, docs))]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Format<'a> for ParenthesizedExpression<'a> {
|
||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||
array![p, ss!("("), format!(p, self.expression), ss!(")")]
|
||||
// TODO: if shouldHug
|
||||
// array![p, ss!("("), format!(p, self.expression), ss!(")")]
|
||||
group![
|
||||
p,
|
||||
ss!("("),
|
||||
indent!(p, array![p, softline!(), format!(p, self.expression)]),
|
||||
softline!(),
|
||||
ss!(")")
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Compatibility: 78/881 (8.85%)
|
||||
Compatibility: 81/881 (9.19%)
|
||||
|
||||
# Failed
|
||||
|
||||
|
|
@ -66,7 +66,6 @@ Compatibility: 78/881 (8.85%)
|
|||
* assignment/issue-1419.js
|
||||
* assignment/issue-15534.js
|
||||
* assignment/issue-1966.js
|
||||
* assignment/issue-2184.js
|
||||
* assignment/issue-2482-1.js
|
||||
* assignment/issue-2482-2.js
|
||||
* assignment/issue-2540.js
|
||||
|
|
@ -167,7 +166,6 @@ Compatibility: 78/881 (8.85%)
|
|||
* binary-expressions/short-right.js
|
||||
* binary-expressions/test.js
|
||||
* binary-expressions/tuple-and-record.js
|
||||
* binary-expressions/unary.js
|
||||
|
||||
### binary_math
|
||||
* binary_math/parens.js
|
||||
|
|
@ -518,6 +516,7 @@ Compatibility: 78/881 (8.85%)
|
|||
|
||||
### expression_statement
|
||||
* expression_statement/no_regression.js
|
||||
* expression_statement/use_strict.js
|
||||
|
||||
### for
|
||||
* for/comment.js
|
||||
|
|
@ -682,7 +681,6 @@ Compatibility: 78/881 (8.85%)
|
|||
### member
|
||||
* member/conditional.js
|
||||
* member/expand.js
|
||||
* member/logical.js
|
||||
|
||||
### method-chain
|
||||
* method-chain/13018.js
|
||||
|
|
@ -958,7 +956,6 @@ Compatibility: 78/881 (8.85%)
|
|||
* sequence-break/break.js
|
||||
|
||||
### sequence-expression
|
||||
* sequence-expression/export-default.js
|
||||
* sequence-expression/ignore.js
|
||||
* sequence-expression/parenthesized.js
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue