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
12 changes: 10 additions & 2 deletions crates/oxc_formatter/src/parentheses/ts_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl<'a> NeedsParentheses<'a> for AstNode<'a, TSType<'a>> {
AstNodes::TSInferType(it) => it.needs_parentheses(f),
AstNodes::TSConstructorType(it) => it.needs_parentheses(f),
AstNodes::TSUnionType(it) => it.needs_parentheses(f),
AstNodes::TSIntersectionType(it) => it.needs_parentheses(f),
AstNodes::TSConditionalType(it) => it.needs_parentheses(f),
_ => {
// TODO: incomplete
Expand All @@ -32,7 +33,7 @@ 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(_) => true,
AstNodes::TSUnionType(_) | AstNodes::TSIntersectionType(_) => true,
_ => false,
}
}
Expand All @@ -50,7 +51,7 @@ 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(_) => true,
AstNodes::TSUnionType(_) | AstNodes::TSIntersectionType(_) => true,
_ => false,
}
}
Expand All @@ -62,12 +63,19 @@ impl<'a> NeedsParentheses<'a> for AstNode<'a, TSUnionType<'a>> {
}
}

impl<'a> NeedsParentheses<'a> for AstNode<'a, TSIntersectionType<'a>> {
fn needs_parentheses(&self, f: &Formatter<'_, 'a>) -> bool {
matches!(self.parent, AstNodes::TSArrayType(_))
}
}

impl<'a> NeedsParentheses<'a> for AstNode<'a, TSConditionalType<'a>> {
fn needs_parentheses(&self, f: &Formatter<'_, 'a>) -> bool {
match self.parent {
AstNodes::TSConditionalType(ty) => {
ty.extends_type().span() == self.span() || ty.check_type().span() == self.span()
}
AstNodes::TSUnionType(_) | AstNodes::TSIntersectionType(_) => true,
_ => false,
}
}
Expand Down
24 changes: 1 addition & 23 deletions tasks/coverage/snapshots/formatter_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ commit: 261630d6

formatter_typescript Summary:
AST Parsed : 8816/8816 (100.00%)
Positive Passed: 8746/8816 (99.21%)
Positive Passed: 8757/8816 (99.33%)
Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/APISample_jsdoc.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/aliasInstantiationExpressionGenericIntersectionNoCrash1.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/amdLikeInputDeclarationEmit.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/callOfConditionalTypeWithConcreteBranches.ts
Expand All @@ -15,14 +13,10 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/castExpressionPa

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/castFunctionExpressionShouldBeParenthesized.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/classNonUniqueSymbolMethodHasSymbolIndexer.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/coAndContraVariantInferences3.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/complexNarrowingWithAny.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/contextualTypeBasedOnIntersectionWithAnyInTheMix3.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/declarationEmitCastReusesTypeNode4.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/declarationEmitPartialReuseComputedProperty.ts
Expand All @@ -35,8 +29,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/declarationEmitS

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/exportDefaultParenthesizeES6.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/intersectionWithConstructSignaturePrototypeResult.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/jsxNamespaceGlobalReexport.tsx

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/jsxNamespaceGlobalReexportMissingAliasTarget.tsx
Expand All @@ -45,14 +37,10 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/jsxNamespaceImpl

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/keyRemappingKeyofResult.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/multiSignatureTypeInference.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/narrowingByTypeofInSwitch.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/propertyAccessExpressionInnerComments.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/ramdaToolsNoInfinite2.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/readonlyAssignmentInSubclassOfClassExpression.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/reducibleIndexedAccessTypes.ts
Expand All @@ -61,8 +49,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/referenceSatisfi

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/reverseMappedTypeInferenceSameSource1.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/signatureCombiningRestParameters1.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/sourceMapValidationClasses.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/styledComponentsInstantiaionLimitNotReached.ts
Expand All @@ -75,14 +61,8 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/tryStatementInte

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/typeName1.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/typePredicateFreshLiteralWidening.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/compiler/unionSignaturesWithThisParameter.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/classes/mixinAbstractClasses.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/classes/propertyMemberDeclarations/accessorsOverrideProperty9.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/classes/propertyMemberDeclarations/staticAutoAccessorsWithDecorators.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/controlFlow/controlFlowAssignmentPatternOrder.ts
Expand Down Expand Up @@ -129,8 +109,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/pedantic/noUn

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/statements/returnStatements/returnStatementNoAsiAfterTransform.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/types/literal/templateLiteralTypes4.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/types/mapped/mappedTypeModifiers.ts

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/types/objectTypeLiteral/propertySignatures/propertyNamesOfReservedWords.ts
Expand Down
2 changes: 1 addition & 1 deletion tasks/prettier_conformance/snapshots/prettier.ts.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ ts compatibility: 350/573 (61.08%)
| typescript/interface2/comments.ts | 💥 | 78.87% |
| typescript/interface2/module.ts | 💥 | 80.00% |
| typescript/interface2/break/break.ts | 💥💥💥 | 68.93% |
| typescript/intersection/intersection-parens.ts | 💥💥 | 54.84% |
| typescript/intersection/intersection-parens.ts | 💥💥 | 55.91% |
| typescript/intersection/type-arguments.ts | 💥💥 | 46.67% |
| typescript/intersection/consistent-with-flow/comment.ts | 💥 | 0.00% |
| typescript/intersection/consistent-with-flow/intersection-parens.ts | 💥 | 60.47% |
Expand Down
Loading