Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions crates/oxc_formatter/src/parentheses/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,22 +531,27 @@ impl NeedsParentheses<'_> for AstNode<'_, AssignmentExpression<'_>> {
AstNodes::SequenceExpression(sequence) => {
// Skip through SequenceExpression and ParenthesizedExpression ancestors
if let Some(ancestor) = self.ancestors().find(|p| {
!matches!(p, AstNodes::SequenceExpression(_) | AstNodes::ParenthesizedExpression(_))
}) && let AstNodes::ForStatement(for_stmt) = ancestor {
let is_initializer = for_stmt
.init
.as_ref()
.is_some_and(|init| init.span().contains_inclusive(self.span()));
let is_update = for_stmt.update.as_ref().is_some_and(|update| {
update.span().contains_inclusive(self.span())
});
return !(is_initializer || is_update);
}
!matches!(
p,
AstNodes::SequenceExpression(_) | AstNodes::ParenthesizedExpression(_)
)
}) && let AstNodes::ForStatement(for_stmt) = ancestor
{
let is_initializer = for_stmt
.init
.as_ref()
.is_some_and(|init| init.span().contains_inclusive(self.span()));
let is_update = for_stmt
.update
.as_ref()
.is_some_and(|update| update.span().contains_inclusive(self.span()));
return !(is_initializer || is_update);
}

true
}
// `interface { [a = 1]; }` and `class { [a = 1]; }` not need parens
AstNodes::TSPropertySignature(_) | AstNodes::PropertyDefinition(_) |
// `interface A { [a = 1]; }` not need parens
AstNodes::TSPropertySignature(_) |
// Never need parentheses in these contexts:
// - `a = (b = c)` = nested assignments don't need extra parens
AstNodes::AssignmentExpression(_) => false,
Expand All @@ -567,6 +572,7 @@ impl NeedsParentheses<'_> for AstNode<'_, AssignmentExpression<'_>> {
// - `new (a = b)`
// - `(a = b).prop`
// - `await (a = b)`
// - `class { [a = 1]; }`
// - etc.
_ => true,
}
Expand Down
4 changes: 1 addition & 3 deletions tasks/prettier_conformance/snapshots/prettier.js.snap.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
js compatibility: 696/749 (92.92%)
js compatibility: 698/749 (93.19%)

# Failed

| Spec path | Failed or Passed | Match ratio |
| :-------- | :--------------: | :---------: |
| js/arrows/comment.js | 💥💥 | 88.89% |
| js/assignment-expression/property-key.js | 💥 | 88.89% |
| js/assignment-expression/property-value.js | 💥 | 88.89% |
| js/call/boolean/boolean.js | 💥 | 77.88% |
| js/class-comment/misc.js | 💥 | 72.73% |
| js/class-comment/superclass.js | 💥 | 95.35% |
Expand Down
3 changes: 1 addition & 2 deletions tasks/prettier_conformance/snapshots/prettier.ts.snap.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ts compatibility: 544/598 (90.97%)
ts compatibility: 545/598 (91.14%)

# Failed

Expand All @@ -25,7 +25,6 @@ ts compatibility: 544/598 (90.97%)
| typescript/comments/16121.ts | 💥 | 72.46% |
| typescript/comments/mapped_types.ts | 💥 | 96.77% |
| typescript/comments/method_types.ts | 💥 | 82.05% |
| typescript/compiler/indexSignatureWithInitializer.ts | 💥 | 87.50% |
| typescript/conditional-types/comments.ts | 💥✨ | 31.51% |
| typescript/conditional-types/conditional-types.ts | 💥✨ | 34.48% |
| typescript/conditional-types/infer-type.ts | 💥✨ | 4.76% |
Expand Down
Loading