Skip to content

Commit 95eb1b6

Browse files
committed
feat(formatter): check ChainExpression for SimpleArgument
1 parent 3b85879 commit 95eb1b6

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

crates/oxc_formatter/src/utils/member_chain/simple_argument.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ impl<'a, 'b> SimpleArgument<'a, 'b> {
104104
self.is_simple_call_like(&expr.callee, &expr.arguments, depth)
105105
}
106106
Expression::ImportExpression(expr) => depth < 2 && expr.options.is_none(),
107+
Expression::ChainExpression(chain) => {
108+
self.is_simple_chain_element(&chain.expression, depth)
109+
}
107110
_ => false,
108111
},
109112
Self::Assignment(SimpleAssignmentTarget::AssignmentTargetIdentifier(_)) => true,
@@ -152,6 +155,28 @@ impl<'a, 'b> SimpleArgument<'a, 'b> {
152155
&& arguments.len() + usize::from(depth) <= 2
153156
&& arguments.iter().all(|argument| Self::new(argument).is_simple_impl(depth + 1))
154157
}
158+
159+
#[inline]
160+
fn is_simple_chain_element(&self, element: &'b ChainElement<'a>, depth: u8) -> bool {
161+
match element {
162+
ChainElement::CallExpression(call) => {
163+
self.is_simple_call_like(&call.callee, &call.arguments, depth)
164+
}
165+
ChainElement::TSNonNullExpression(assertion) => {
166+
Self::from(&assertion.expression).is_simple_impl(depth)
167+
}
168+
ChainElement::StaticMemberExpression(static_expression) => {
169+
Self::from(&static_expression.object).is_simple_impl(depth)
170+
}
171+
ChainElement::ComputedMemberExpression(computed_expression) => {
172+
Self::from(&computed_expression.expression).is_simple_impl(depth)
173+
&& Self::from(&computed_expression.object).is_simple_impl(depth)
174+
}
175+
ChainElement::PrivateFieldExpression(private_field) => {
176+
Self::from(&private_field.object).is_simple_impl(depth)
177+
}
178+
}
179+
}
155180
}
156181

157182
impl<'a, 'b> From<&'b Expression<'a>> for SimpleArgument<'a, 'b> {

tasks/prettier_conformance/snapshots/prettier.js.snap.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
js compatibility: 439/699 (62.80%)
1+
js compatibility: 441/699 (63.09%)
22

33
# Failed
44

@@ -29,8 +29,6 @@ js compatibility: 439/699 (62.80%)
2929
| js/chain-expression/issue-15785-1.js | 💥 | 78.26% |
3030
| js/chain-expression/issue-15785-2.js | 💥 | 66.67% |
3131
| js/chain-expression/issue-15785-3.js | 💥 | 50.00% |
32-
| js/chain-expression/issue-15912.js | 💥 | 0.00% |
33-
| js/chain-expression/issue-15916.js | 💥 | 47.06% |
3432
| js/chain-expression/member-expression.js | 💥 | 45.83% |
3533
| js/chain-expression/test-3.js | 💥 | 75.00% |
3634
| js/chain-expression/test.js | 💥 | 25.00% |

0 commit comments

Comments
 (0)