@@ -47,7 +47,7 @@ namespace ts.formatting {
4747 rule ( "IgnoreBeforeComment" , anyToken , comments , anyContext , RuleAction . Ignore ) ,
4848 rule ( "IgnoreAfterLineComment" , SyntaxKind . SingleLineCommentTrivia , anyToken , anyContext , RuleAction . Ignore ) ,
4949
50- rule ( "NoSpaceBeforeColon " , anyToken , SyntaxKind . ColonToken , [ isNonJsxSameLineTokenContext , isNotBinaryOpContext ] , RuleAction . Delete ) ,
50+ rule ( "NotSpaceBeforeColon " , anyToken , SyntaxKind . ColonToken , [ isNonJsxSameLineTokenContext , isNotBinaryOpContext , isNotTypeAnnotationContext ] , RuleAction . Delete ) ,
5151 rule ( "SpaceAfterColon" , SyntaxKind . ColonToken , anyToken , [ isNonJsxSameLineTokenContext , isNotBinaryOpContext ] , RuleAction . Space ) ,
5252 rule ( "NoSpaceBeforeQuestionMark" , anyToken , SyntaxKind . QuestionToken , [ isNonJsxSameLineTokenContext , isNotBinaryOpContext ] , RuleAction . Delete ) ,
5353 // insert space after '?' only when it is used in conditional operator
@@ -300,6 +300,9 @@ namespace ts.formatting {
300300
301301 rule ( "SpaceAfterTypeAssertion" , SyntaxKind . GreaterThanToken , anyToken , [ isOptionEnabled ( "insertSpaceAfterTypeAssertion" ) , isNonJsxSameLineTokenContext , isTypeAssertionContext ] , RuleAction . Space ) ,
302302 rule ( "NoSpaceAfterTypeAssertion" , SyntaxKind . GreaterThanToken , anyToken , [ isOptionDisabledOrUndefined ( "insertSpaceAfterTypeAssertion" ) , isNonJsxSameLineTokenContext , isTypeAssertionContext ] , RuleAction . Delete ) ,
303+
304+ rule ( "SpaceBeforeTypeAnnotation" , anyToken , SyntaxKind . ColonToken , [ isOptionEnabled ( "insertSpaceBeforeTypeAnnotation" ) , isNonJsxSameLineTokenContext , isTypeAnnotationContext ] , RuleAction . Space ) ,
305+ rule ( "NoSpaceBeforeTypeAnnotation" , anyToken , SyntaxKind . ColonToken , [ isOptionDisabledOrUndefined ( "insertSpaceBeforeTypeAnnotation" ) , isNonJsxSameLineTokenContext , isTypeAnnotationContext ] , RuleAction . Delete ) ,
303306 ] ;
304307
305308 // These rules are lower in priority than user-configurable. Rules earlier in this list have priority over rules later in the list.
@@ -441,6 +444,19 @@ namespace ts.formatting {
441444 return ! isBinaryOpContext ( context ) ;
442445 }
443446
447+ function isNotTypeAnnotationContext ( context : FormattingContext ) : boolean {
448+ return ! isTypeAnnotationContext ( context ) ;
449+ }
450+
451+ function isTypeAnnotationContext ( context : FormattingContext ) : boolean {
452+ const contextKind = context . contextNode . kind ;
453+ return contextKind === SyntaxKind . PropertyDeclaration ||
454+ contextKind === SyntaxKind . PropertySignature ||
455+ contextKind === SyntaxKind . Parameter ||
456+ contextKind === SyntaxKind . VariableDeclaration ||
457+ isFunctionLikeKind ( contextKind ) ;
458+ }
459+
444460 function isConditionalOperatorContext ( context : FormattingContext ) : boolean {
445461 return context . contextNode . kind === SyntaxKind . ConditionalExpression ;
446462 }
0 commit comments