diff --git a/crates/oxc_formatter/src/parentheses/expression.rs b/crates/oxc_formatter/src/parentheses/expression.rs index d3b767ca2f12e..9afb6c45751bc 100644 --- a/crates/oxc_formatter/src/parentheses/expression.rs +++ b/crates/oxc_formatter/src/parentheses/expression.rs @@ -270,7 +270,7 @@ impl NeedsParentheses<'_> for AstNode<'_, StaticMemberExpression<'_>> { impl NeedsParentheses<'_> for AstNode<'_, PrivateFieldExpression<'_>> { #[inline] fn needs_parentheses(&self, _f: &Formatter<'_, '_>) -> bool { - false + self.is_new_callee() && (self.optional || member_chain_callee_needs_parens(&self.object)) } } diff --git a/crates/oxc_formatter/tests/fixtures/js/new-expression/parenthesis.js b/crates/oxc_formatter/tests/fixtures/js/new-expression/parenthesis.js new file mode 100644 index 0000000000000..b22ed14658dc8 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/js/new-expression/parenthesis.js @@ -0,0 +1,4 @@ +new (this.b().#c)() + +new (this.b().c)() + diff --git a/crates/oxc_formatter/tests/fixtures/js/new-expression/parenthesis.js.snap b/crates/oxc_formatter/tests/fixtures/js/new-expression/parenthesis.js.snap new file mode 100644 index 0000000000000..8041da1e823e0 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/js/new-expression/parenthesis.js.snap @@ -0,0 +1,25 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +new (this.b().#c)() + +new (this.b().c)() + + +==================== Output ==================== +------------------ +{ printWidth: 80 } +------------------ +new (this.b().#c)(); + +new (this.b().c)(); + +------------------- +{ printWidth: 100 } +------------------- +new (this.b().#c)(); + +new (this.b().c)(); + +===================== End =====================