Skip to content

Commit fca8105

Browse files
committed
Correct all cases involving AstNodes::CallExpression and AstNodes::NewExpression
1 parent 83fcaa4 commit fca8105

File tree

9 files changed

+19
-40
lines changed

9 files changed

+19
-40
lines changed

crates/oxc_formatter/src/utils/call_expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn is_test_call_expression(call: &AstNode<CallExpression<'_>>) -> bool {
3636
match (args.next(), args.next(), args.next()) {
3737
(Some(argument), None, None) if arguments.len() == 1 => {
3838
if is_angular_test_wrapper(call) && {
39-
if let AstNodes::CallExpression(call) = call.grand_parent() {
39+
if let AstNodes::CallExpression(call) = call.parent {
4040
is_test_call_expression(call)
4141
} else {
4242
false

crates/oxc_formatter/src/utils/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use crate::{
2929
/// `connect(a, b, c)(d)`
3030
/// ```
3131
pub fn is_long_curried_call(call: &AstNode<'_, CallExpression<'_>>) -> bool {
32-
if let AstNodes::CallExpression(parent_call) = call.parent {
32+
if let AstNodes::CallExpression(parent_call) = call.parent
33+
&& parent_call.is_callee_span(call.span)
34+
{
3335
return call.arguments().len() > parent_call.arguments().len()
3436
&& !parent_call.arguments().is_empty();
3537
}

crates/oxc_formatter/src/write/as_or_satisfies_expression.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,9 @@ fn format_as_or_satisfies_expression<'a>(
5656

5757
fn is_callee_or_object_context(span: Span, parent: &AstNodes<'_>) -> bool {
5858
match parent {
59-
// Callee
60-
AstNodes::CallExpression(_) | AstNodes::NewExpression(_)
6159
// Static member
62-
| AstNodes::StaticMemberExpression(_) => true,
63-
AstNodes::ComputedMemberExpression(member) => {
64-
member.object.span() == span
65-
}
66-
_ => false,
60+
AstNodes::StaticMemberExpression(_) => true,
61+
AstNodes::ComputedMemberExpression(member) => member.object.span() == span,
62+
_ => parent.is_call_like_callee_span(span),
6763
}
6864
}

crates/oxc_formatter/src/write/binary_like_expression.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,7 @@ impl<'a> Format<'a> for BinaryLikeExpression<'a, '_> {
227227
// For example, `(a+b)(call)`, `!(a + b)`, `(a + b).test`.
228228
let is_inside_parenthesis = match parent {
229229
AstNodes::StaticMemberExpression(_) | AstNodes::UnaryExpression(_) => true,
230-
AstNodes::CallExpression(call) => call.callee().span() == self.span(),
231-
AstNodes::NewExpression(new) => new.callee().span() == self.span(),
232-
_ => false,
230+
_ => parent.is_call_like_callee_span(self.span()),
233231
};
234232

235233
if is_inside_parenthesis {

crates/oxc_formatter/src/write/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,9 @@ impl<'a> FormatWrite<'a> for AstNode<'a, AwaitExpression<'a>> {
415415
let format_inner = format_with(|f| write!(f, ["await", space(), self.argument()]));
416416

417417
let is_callee_or_object = match self.parent {
418-
AstNodes::CallExpression(_)
419-
| AstNodes::NewExpression(_)
420-
| AstNodes::StaticMemberExpression(_) => true,
418+
AstNodes::StaticMemberExpression(_) => true,
421419
AstNodes::ComputedMemberExpression(member) => member.object.span() == self.span(),
422-
_ => false,
420+
_ => self.parent.is_call_like_callee_span(self.span),
423421
};
424422

425423
if is_callee_or_object {

crates/oxc_formatter/src/write/parameters.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ impl<'a> FormatWrite<'a> for AstNode<'a, FormalParameters<'a>> {
5252
ParameterLayout::NoParameters
5353
} else if can_hug || {
5454
// `self`: Function
55-
// `self.ancestors().nth(1)`: Argument
56-
// `self.ancestors().nth(2)`: CallExpression
57-
if let Some(AstNodes::CallExpression(call)) = self.ancestors().nth(2) {
55+
// `self.parent`: Function
56+
// `self.grand_parent()`: CallExpression
57+
if let AstNodes::CallExpression(call) = self.grand_parent() {
5858
is_test_call_expression(call)
5959
} else {
6060
false

crates/oxc_formatter/tests/fixtures/js/comments/return.js.snap

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ function escapePathForGlob(path) {
1515
function escapePathForGlob(path) {
1616
return fastGlob
1717
.escapePath(
18-
path.replaceAll(
19-
"\\",
20-
"\0",
21-
), // Workaround for fast-glob#262 (part 1)
18+
path.replaceAll("\\", "\0"), // Workaround for fast-glob#262 (part 1)
2219
)
2320
.replaceAll(String.raw`\!`, "@(!)") // Workaround for fast-glob#261
2421
.replaceAll("\0", String.raw`@(\\)`); // Workaround for fast-glob#262 (part 2)

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
js compatibility: 685/749 (91.46%)
1+
js compatibility: 691/749 (92.26%)
22

33
# Failed
44

@@ -32,7 +32,6 @@ js compatibility: 685/749 (91.46%)
3232
| js/for/9812.js | 💥 | 82.83% |
3333
| js/for/for-in-with-initializer.js | 💥 | 37.50% |
3434
| js/for/parentheses.js | 💥 | 96.00% |
35-
| js/functional-composition/pipe-function-calls.js | 💥 | 87.80% |
3635
| js/identifier/for-of/let.js | 💥 | 92.31% |
3736
| js/identifier/parentheses/let.js | 💥💥 | 82.27% |
3837
| js/if/comment-between-condition-and-body.js | 💥 | 65.79% |
@@ -41,12 +40,10 @@ js compatibility: 685/749 (91.46%)
4140
| js/if/trailing_comment.js | 💥 | 91.43% |
4241
| js/last-argument-expansion/dangling-comment-in-arrow-function.js | 💥 | 22.22% |
4342
| js/object-multiline/multiline.js | 💥✨ | 22.22% |
44-
| js/preserve-line/parameter-list.js | 💥 | 97.37% |
4543
| js/quote-props/classes.js | 💥💥✨✨ | 47.06% |
4644
| js/quote-props/objects.js | 💥💥✨✨ | 45.10% |
4745
| js/quote-props/with_numbers.js | 💥💥✨✨ | 46.43% |
4846
| js/quotes/objects.js | 💥💥 | 80.00% |
49-
| js/require/require.js | 💥 | 93.83% |
5047
| js/sequence-expression/ignored.js | 💥 | 25.00% |
5148
| js/strings/template-literals.js | 💥💥 | 98.01% |
5249
| js/ternaries/binary.js | 💥💥💥💥✨✨✨✨ | 18.42% |
@@ -58,11 +55,8 @@ js compatibility: 685/749 (91.46%)
5855
| js/ternaries/parenthesis.js | 💥💥💥💥✨✨✨✨ | 12.50% |
5956
| js/ternaries/test.js | 💥💥💥💥✨✨✨✨ | 22.40% |
6057
| js/ternaries/parenthesis/await-expression.js | 💥✨ | 14.29% |
61-
| js/test-declarations/angular_async.js | 💥💥 | 86.21% |
62-
| js/test-declarations/angular_fakeAsync.js | 💥💥 | 75.86% |
63-
| js/test-declarations/angular_waitForAsync.js | 💥💥 | 75.86% |
64-
| js/test-declarations/angularjs_inject.js | 💥💥 | 69.84% |
65-
| js/test-declarations/test_declarations.js | 💥💥 | 93.08% |
58+
| js/test-declarations/angularjs_inject.js | 💥💥 | 91.53% |
59+
| js/test-declarations/test_declarations.js | 💥💥 | 95.88% |
6660
| jsx/fbt/test.js | 💥 | 84.06% |
6761
| jsx/ignore/jsx_ignore.js | 💥 | 92.59% |
6862
| jsx/jsx/quotes.js | 💥💥💥💥 | 79.41% |

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ts compatibility: 534/598 (89.30%)
1+
ts compatibility: 540/598 (90.30%)
22

33
# Failed
44

@@ -13,10 +13,6 @@ ts compatibility: 534/598 (89.30%)
1313
| typescript/angular-component-examples/15934.component.ts | 💥💥 | 53.85% |
1414
| typescript/angular-component-examples/test.component.ts | 💥💥 | 41.18% |
1515
| typescript/arrow/comments.ts | 💥✨ | 44.44% |
16-
| typescript/as/as.ts | 💥 | 92.65% |
17-
| typescript/as/long-identifiers.ts | 💥 | 89.66% |
18-
| typescript/cast/generic-cast.ts | 💥 | 97.37% |
19-
| typescript/cast/hug-args.ts | 💥 | 70.59% |
2016
| typescript/chain-expression/call-expression.ts | 💥 | 64.06% |
2117
| typescript/chain-expression/member-expression.ts | 💥 | 59.70% |
2218
| typescript/chain-expression/test.ts | 💥 | 0.00% |
@@ -41,7 +37,6 @@ ts compatibility: 534/598 (89.30%)
4137
| typescript/decorators/comments.ts | 💥 | 60.00% |
4238
| typescript/decorators/decorators-comments.ts | 💥 | 65.71% |
4339
| typescript/decorators-ts/angular.ts | 💥 | 87.50% |
44-
| typescript/functional-composition/pipe-function-calls.ts | 💥 | 82.76% |
4540
| typescript/instantiation-expression/17714.ts | 💥 | 0.00% |
4641
| typescript/interface/comments-generic.ts | 💥💥 | 41.94% |
4742
| typescript/interface/long-extends.ts | 💥💥 | 83.64% |
@@ -59,8 +54,7 @@ ts compatibility: 534/598 (89.30%)
5954
| typescript/prettier-ignore/mapped-types.ts | 💥 | 96.61% |
6055
| typescript/property-signature/consistent-with-flow/comments.ts | 💥 | 80.00% |
6156
| typescript/property-signature/consistent-with-flow/union.ts | 💥 | 85.71% |
62-
| typescript/satisfies-operators/hug-args.ts | 💥💥 | 0.00% |
63-
| typescript/test-declarations/test_declarations.ts | 💥💥 | 40.00% |
57+
| typescript/test-declarations/test_declarations.ts | 💥💥 | 50.00% |
6458
| typescript/type-params/18041.ts | 💥 | 43.75% |
6559
| typescript/type-params/constraints-and-default-2.ts | 💥 | 97.60% |
6660
| typescript/type-params/constraints-and-default.ts | 💥 | 87.32% |

0 commit comments

Comments
 (0)