@@ -70,8 +70,8 @@ namespace ts.formatting {
70
70
rule ( "NoSpaceAfterUnaryPrefixOperator" , unaryPrefixOperators , unaryPrefixExpressions , [ isNonJsxSameLineTokenContext , isNotBinaryOpContext ] , RuleAction . DeleteSpace ) ,
71
71
rule ( "NoSpaceAfterUnaryPreincrementOperator" , SyntaxKind . PlusPlusToken , unaryPreincrementExpressions , [ isNonJsxSameLineTokenContext ] , RuleAction . DeleteSpace ) ,
72
72
rule ( "NoSpaceAfterUnaryPredecrementOperator" , SyntaxKind . MinusMinusToken , unaryPredecrementExpressions , [ isNonJsxSameLineTokenContext ] , RuleAction . DeleteSpace ) ,
73
- rule ( "NoSpaceBeforeUnaryPostincrementOperator" , unaryPostincrementExpressions , SyntaxKind . PlusPlusToken , [ isNonJsxSameLineTokenContext ] , RuleAction . DeleteSpace ) ,
74
- rule ( "NoSpaceBeforeUnaryPostdecrementOperator" , unaryPostdecrementExpressions , SyntaxKind . MinusMinusToken , [ isNonJsxSameLineTokenContext ] , RuleAction . DeleteSpace ) ,
73
+ rule ( "NoSpaceBeforeUnaryPostincrementOperator" , unaryPostincrementExpressions , SyntaxKind . PlusPlusToken , [ isNonJsxSameLineTokenContext , isNotStatementConditionContext ] , RuleAction . DeleteSpace ) ,
74
+ rule ( "NoSpaceBeforeUnaryPostdecrementOperator" , unaryPostdecrementExpressions , SyntaxKind . MinusMinusToken , [ isNonJsxSameLineTokenContext , isNotStatementConditionContext ] , RuleAction . DeleteSpace ) ,
75
75
76
76
// More unary operator special-casing.
77
77
// DevDiv 181814: Be careful when removing leading whitespace
@@ -790,6 +790,25 @@ namespace ts.formatting {
790
790
return context . contextNode . kind === SyntaxKind . NonNullExpression ;
791
791
}
792
792
793
+ function isNotStatementConditionContext ( context : FormattingContext ) : boolean {
794
+ return ! isStatementConditionContext ( context ) ;
795
+ }
796
+
797
+ function isStatementConditionContext ( context : FormattingContext ) : boolean {
798
+ switch ( context . contextNode . kind ) {
799
+ case SyntaxKind . IfStatement :
800
+ case SyntaxKind . ForStatement :
801
+ case SyntaxKind . ForInStatement :
802
+ case SyntaxKind . ForOfStatement :
803
+ case SyntaxKind . DoStatement :
804
+ case SyntaxKind . WhileStatement :
805
+ return true ;
806
+
807
+ default :
808
+ return false ;
809
+ }
810
+ }
811
+
793
812
function isSemicolonDeletionContext ( context : FormattingContext ) : boolean {
794
813
let nextTokenKind = context . nextTokenSpan . kind ;
795
814
let nextTokenStart = context . nextTokenSpan . pos ;
0 commit comments