mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(prettier): handle parens for sequence expression (#1582)
This commit is contained in:
parent
405d1228a0
commit
b8ce6266ad
3 changed files with 14 additions and 6 deletions
|
|
@ -498,7 +498,9 @@ impl<'a> Format<'a> for SwitchCase<'a> {
|
|||
|
||||
impl<'a> Format<'a> for ReturnStatement<'a> {
|
||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||
function::print_return_or_throw_argument(p, self.argument.as_ref(), true)
|
||||
wrap!(p, self, ReturnStatement, {
|
||||
function::print_return_or_throw_argument(p, self.argument.as_ref(), true)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ impl<'a> Prettier<'a> {
|
|||
AstKind::NumberLiteral(literal) => {
|
||||
matches!(parent_kind, AstKind::MemberExpression(e) if e.object().span() == literal.span)
|
||||
}
|
||||
AstKind::SequenceExpression(_) => !matches!(parent_kind, AstKind::Program(_)),
|
||||
AstKind::SequenceExpression(e) => self.check_sequence_expression(e.span),
|
||||
AstKind::ObjectExpression(e) => self.check_object_function_class(e.span),
|
||||
AstKind::Function(f) if f.is_expression() => {
|
||||
if self.check_object_function_class(f.span) {
|
||||
|
|
@ -231,6 +231,15 @@ impl<'a> Prettier<'a> {
|
|||
false
|
||||
}
|
||||
|
||||
fn check_sequence_expression(&self, span: Span) -> bool {
|
||||
match self.parent_kind() {
|
||||
AstKind::ReturnStatement(_) | AstKind::ForStatement(_) => false,
|
||||
AstKind::ExpressionStatement(expr) => expr.expression.span() != span,
|
||||
AstKind::ArrowExpression(expr) => expr.body.span != span,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn check_object_expression(&self, obj_expr: &ObjectExpression<'a>) -> bool {
|
||||
let mut arrow_expr = None;
|
||||
for kind in self.nodes.iter().rev() {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Compatibility: 199/578 (34.43%)
|
||||
Compatibility: 200/578 (34.60%)
|
||||
|
||||
# Failed
|
||||
|
||||
|
|
@ -450,9 +450,6 @@ Compatibility: 199/578 (34.43%)
|
|||
* require-amd/named-amd-module.js
|
||||
* require-amd/require.js
|
||||
|
||||
### reserved-word
|
||||
* reserved-word/interfaces.js
|
||||
|
||||
### rest
|
||||
* rest/trailing-commas.js
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue