Skip to content
Closed
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
19 changes: 15 additions & 4 deletions crates/oxc_formatter/src/parentheses/ts_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ impl<'a> NeedsParentheses<'a> for AstNode<'a, TSFunctionType<'a>> {
AstNodes::TSConditionalType(ty) => {
ty.extends_type().span() == self.span() || ty.check_type().span() == self.span()
}
AstNodes::TSUnionType(_) | AstNodes::TSIntersectionType(_) => true,
AstNodes::TSUnionType(_)
| AstNodes::TSIntersectionType(_)
| AstNodes::TSOptionalType(_) => true,
_ => false,
}
}
Expand All @@ -52,7 +54,9 @@ impl<'a> NeedsParentheses<'a> for AstNode<'a, TSConstructorType<'a>> {
AstNodes::TSConditionalType(ty) => {
ty.extends_type().span() == self.span() || ty.check_type().span() == self.span()
}
AstNodes::TSUnionType(_) | AstNodes::TSIntersectionType(_) => true,
AstNodes::TSUnionType(_)
| AstNodes::TSIntersectionType(_)
| AstNodes::TSOptionalType(_) => true,
_ => false,
}
}
Expand All @@ -73,7 +77,10 @@ impl<'a> NeedsParentheses<'a> for AstNode<'a, TSUnionType<'a>> {
/// Returns `true` if a TS primary type needs parentheses
fn operator_type_or_higher_needs_parens(span: Span, parent: &AstNodes) -> bool {
match parent {
AstNodes::TSArrayType(_) | AstNodes::TSTypeOperator(_) | AstNodes::TSRestType(_) => true,
AstNodes::TSArrayType(_)
| AstNodes::TSTypeOperator(_)
| AstNodes::TSRestType(_)
| AstNodes::TSOptionalType(_) => true,
AstNodes::TSIndexedAccessType(indexed) => indexed.object_type.span() == span,
_ => false,
}
Expand All @@ -85,6 +92,7 @@ impl<'a> NeedsParentheses<'a> for AstNode<'a, TSIntersectionType<'a>> {
self.parent,
AstNodes::TSArrayType(_)
| AstNodes::TSTypeOperator(_)
| AstNodes::TSOptionalType(_)
| AstNodes::TSIndexedAccessType(_)
)
}
Expand All @@ -96,7 +104,9 @@ impl<'a> NeedsParentheses<'a> for AstNode<'a, TSConditionalType<'a>> {
AstNodes::TSConditionalType(ty) => {
ty.extends_type().span() == self.span() || ty.check_type().span() == self.span()
}
AstNodes::TSUnionType(_) | AstNodes::TSIntersectionType(_) => true,
AstNodes::TSUnionType(_)
| AstNodes::TSIntersectionType(_)
| AstNodes::TSOptionalType(_) => true,
_ => false,
}
}
Expand All @@ -109,6 +119,7 @@ impl<'a> NeedsParentheses<'a> for AstNode<'a, TSTypeOperator<'a>> {
AstNodes::TSArrayType(_)
| AstNodes::TSTypeOperator(_)
| AstNodes::TSIndexedAccessType(_)
| AstNodes::TSOptionalType(_)
)
}
}
3 changes: 1 addition & 2 deletions tasks/prettier_conformance/snapshots/prettier.ts.snap.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ts compatibility: 467/573 (81.50%)
ts compatibility: 468/573 (81.68%)

# Failed

Expand Down Expand Up @@ -83,7 +83,6 @@ ts compatibility: 467/573 (81.50%)
| typescript/non-null/parens.ts | 💥 | 96.00% |
| typescript/nosemi/index-signature.ts | 💥 | 75.00% |
| typescript/object-multiline/multiline.ts | 💥✨ | 23.21% |
| typescript/optional-type/complex.ts | 💥 | 0.00% |
| typescript/optional-variance/basic.ts | 💥 | 98.36% |
| typescript/optional-variance/with-jsx.tsx | 💥 | 98.36% |
| typescript/override-modifiers/override-modifier.ts | 💥 | 25.00% |
Expand Down
Loading