Skip to content

Commit 5e827d3

Browse files
committed
fix(formatter): correct a few minor mismatched typescript tests
1 parent 3c94346 commit 5e827d3

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

crates/oxc_formatter/src/parentheses/expression.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ impl NeedsParentheses<'_> for AstNode<'_, ArrowFunctionExpression<'_>> {
660660
AstNodes::TSAsExpression(_)
661661
| AstNodes::TSSatisfiesExpression(_)
662662
| AstNodes::TSTypeAssertion(_)
663+
| AstNodes::TSInstantiationExpression(_)
663664
| AstNodes::UnaryExpression(_)
664665
| AstNodes::AwaitExpression(_)
665666
| AstNodes::LogicalExpression(_)

crates/oxc_formatter/src/write/arrow_function_expression.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use crate::{
1616
},
1717
},
1818
options::FormatTrailingCommas,
19-
utils::{assignment_like::AssignmentLikeLayout, expression::ExpressionLeftSide},
19+
utils::{
20+
assignment_like::AssignmentLikeLayout, expression::ExpressionLeftSide,
21+
format_node_without_trailing_comments::FormatNodeWithoutTrailingComments,
22+
},
2023
write,
2124
write::function::FormatContentWithCacheMode,
2225
};
@@ -729,13 +732,13 @@ fn format_signature<'a, 'b>(
729732
arrow.r#async().then_some("async "),
730733
arrow.type_parameters(),
731734
arrow.params(),
732-
format_once(|f| {
733-
let needs_space = arrow.return_type.as_ref().is_some_and(|return_type| {
734-
f.context().comments().has_comment_before(return_type.span.start)
735-
});
736-
maybe_space(needs_space).fmt(f)
737-
}),
738-
group(&arrow.return_type())
735+
&format_once(|f| {
736+
if let Some(return_type) = &arrow.return_type() {
737+
group(&FormatNodeWithoutTrailingComments(return_type)).fmt(f)
738+
} else {
739+
Ok(())
740+
}
741+
})
739742
))
740743
.fmt(f)
741744
});

crates/oxc_formatter/src/write/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ impl<'a> Format<'a> for FormatTSSignature<'a, '_> {
15051505
return write!(f, [self.signature]);
15061506
}
15071507

1508-
write!(f, [group(&self.signature)])?;
1508+
write!(f, [&self.signature])?;
15091509

15101510
match f.options().semicolons {
15111511
Semicolons::Always => {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ts compatibility: 562/601 (93.51%)
1+
ts compatibility: 564/601 (93.84%)
22

33
# Failed
44

@@ -10,7 +10,7 @@ ts compatibility: 562/601 (93.51%)
1010
| jsx/single-attribute-per-line/single-attribute-per-line.js | 💥✨ | 43.37% |
1111
| jsx/text-wrap/test.js | 💥 | 99.56% |
1212
| typescript/arrow/comments.ts | 💥✨ | 44.44% |
13-
| typescript/arrow/comments/issue-11100.ts | 💥 | 56.52% |
13+
| typescript/arrow/comments/issue-11100.ts | 💥 | 84.00% |
1414
| typescript/as/as-const/as-const.ts | 💥 | 90.91% |
1515
| typescript/as/break-after-keyword/18148.ts | 💥 | 82.22% |
1616
| typescript/as/comments/18160.ts | 💥 | 71.58% |
@@ -28,7 +28,6 @@ ts compatibility: 562/601 (93.51%)
2828
| typescript/conditional-types/new-ternary-spec.ts | 💥✨ | 10.67% |
2929
| typescript/conditional-types/parentheses.ts | 💥✨ | 15.22% |
3030
| typescript/decorators-ts/angular.ts | 💥 | 87.50% |
31-
| typescript/instantiation-expression/17714.ts | 💥 | 0.00% |
3231
| typescript/intersection/intersection-parens.ts | 💥💥 | 86.17% |
3332
| typescript/intersection/consistent-with-flow/intersection-parens.ts | 💥 | 69.77% |
3433
| typescript/last-argument-expansion/decorated-function.tsx | 💥 | 29.06% |
@@ -38,7 +37,6 @@ ts compatibility: 562/601 (93.51%)
3837
| typescript/non-null/optional-chain.ts | 💥 | 72.22% |
3938
| typescript/object-multiline/multiline.ts | 💥✨ | 23.21% |
4039
| typescript/property-signature/consistent-with-flow/comments.ts | 💥 | 80.00% |
41-
| typescript/union/inlining.ts | 💥 | 97.78% |
4240
| typescript/union/union-parens.ts | 💥 | 92.59% |
4341
| typescript/union/comments/18106.ts | 💥 | 90.48% |
4442
| typescript/union/consistent-with-flow/comment.ts | 💥 | 82.61% |

0 commit comments

Comments
 (0)