Skip to content

Commit 4a5ad45

Browse files
committed
fix(formatter): missing parenthesis for PrivateInExpression when its parent is an UnaryExpression
1 parent 890c0dd commit 4a5ad45

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

crates/oxc_formatter/src/parentheses/expression.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ impl<'a> NeedsParentheses<'a> for AstNode<'a, PrivateInExpression<'a>> {
416416
}
417417

418418
is_class_extends(self.span, self.parent)
419+
|| matches!(self.parent, AstNodes::UnaryExpression(_))
419420
}
420421
}
421422

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class F {
2+
#target = null
3+
next () {
4+
!(#target in this);
5+
-(#target in this);
6+
+(#target in this);
7+
}
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
class F {
6+
#target = null
7+
next () {
8+
!(#target in this);
9+
-(#target in this);
10+
+(#target in this);
11+
}
12+
}
13+
14+
==================== Output ====================
15+
class F {
16+
#target = null;
17+
next() {
18+
!(#target in this);
19+
-(#target in this);
20+
+(#target in this);
21+
}
22+
}
23+
24+
===================== End =====================

0 commit comments

Comments
 (0)