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
2 changes: 1 addition & 1 deletion crates/oxc_formatter/src/utils/member_chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl<'a> Format<'a> for MemberChain<'a, '_> {
});

if self.tail.len() <= 1 && !has_comments {
return if is_long_curried_call(self.root.parent) {
return if is_long_curried_call(self.root) {
write!(f, [format_one_line])
} else if is_test_call_expression(self.root) && self.head.members().len() >= 2 {
write!(f, [self.head, soft_line_indent_or_space(&self.tail)])
Expand Down
12 changes: 5 additions & 7 deletions crates/oxc_formatter/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use oxc_ast::{AstKind, ast::CallExpression};
use crate::{
Format, FormatResult, FormatTrailingCommas, format_args,
formatter::{Formatter, prelude::soft_line_break_or_space},
generated::ast_nodes::AstNodes,
generated::ast_nodes::{AstNode, AstNodes},
};

/// This function is in charge to format the call arguments.
Expand Down Expand Up @@ -40,12 +40,10 @@ where
/// ```javascript
/// `connect(a, b, c)(d)`
/// ```
pub fn is_long_curried_call(parent: &AstNodes<'_>) -> bool {
if let AstNodes::CallExpression(call) = parent {
if let AstNodes::CallExpression(parent_call) = call.parent {
return call.arguments().len() > parent_call.arguments().len()
&& !parent_call.arguments().is_empty();
}
pub fn is_long_curried_call(call: &AstNode<'_, CallExpression<'_>>) -> bool {
if let AstNodes::CallExpression(parent_call) = call.parent {
return call.arguments().len() > parent_call.arguments().len()
&& !parent_call.arguments().is_empty();
}

false
Expand Down
16 changes: 9 additions & 7 deletions crates/oxc_formatter/src/write/call_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ impl<'a> Format<'a> for AstNode<'a, ArenaVec<'a, Argument<'a>>> {
);
}

let (is_commonjs_or_amd_call, is_test_call) =
if let AstNodes::CallExpression(call) = self.parent {
(is_commonjs_or_amd_call(self, call), is_test_call_expression(call))
} else {
(false, false)
};
let call_expression =
if let AstNodes::CallExpression(call) = self.parent { Some(call) } else { None };

let (is_commonjs_or_amd_call, is_test_call) = if let Some(call) = call_expression {
(is_commonjs_or_amd_call(self, call), is_test_call_expression(call))
} else {
(false, false)
};

let is_first_arg_string_literal_or_template = self.len() != 2
|| matches!(
Expand Down Expand Up @@ -105,7 +107,7 @@ impl<'a> Format<'a> for AstNode<'a, ArenaVec<'a, Argument<'a>>> {

if let Some(group_layout) = arguments_grouped_layout(self, f) {
write_grouped_arguments(self, group_layout, f)
} else if is_long_curried_call(self.parent) {
} else if call_expression.is_some_and(|call| is_long_curried_call(call)) {
write!(
f,
[
Expand Down
3 changes: 1 addition & 2 deletions tasks/prettier_conformance/snapshots/prettier.js.snap.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
js compatibility: 438/699 (62.66%)
js compatibility: 439/699 (62.80%)

# Failed

Expand Down Expand Up @@ -124,7 +124,6 @@ js compatibility: 438/699 (62.66%)
| js/for/in.js | 💥 | 50.00% |
| js/for/parentheses.js | 💥 | 72.00% |
| js/for-of/async-identifier.js | 💥 | 90.00% |
| js/functional-composition/ramda_compose.js | 💥 | 92.47% |
| js/identifier/for-of/await.js | 💥 | 33.33% |
| js/identifier/for-of/let.js | 💥 | 61.54% |
| js/identifier/parentheses/let.js | 💥💥 | 79.55% |
Expand Down
Loading