@@ -11,8 +11,8 @@ namespace ts.formatting {
1111 for ( let token = SyntaxKind . FirstToken ; token <= SyntaxKind . LastToken ; token ++ ) {
1212 allTokens . push ( token ) ;
1313 }
14- function anyTokenExcept ( token : SyntaxKind ) : TokenRange {
15- return { tokens : allTokens . filter ( t => t !== token ) , isSpecific : false } ;
14+ function anyTokenExcept ( ... tokens : SyntaxKind [ ] ) : TokenRange {
15+ return { tokens : allTokens . filter ( t => ! tokens . some ( t2 => t2 === t ) ) , isSpecific : false } ;
1616 }
1717
1818 const anyToken : TokenRange = { tokens : allTokens , isSpecific : false } ;
@@ -316,6 +316,11 @@ namespace ts.formatting {
316316
317317 rule ( "NoSpaceBeforeComma" , anyToken , SyntaxKind . CommaToken , [ isNonJsxSameLineTokenContext ] , RuleAction . Delete ) ,
318318
319+ // No space before and after indexer `x[]`
320+ rule ( "NoSpaceBeforeOpenBracket" , anyTokenExcept ( SyntaxKind . AsyncKeyword , SyntaxKind . CaseKeyword ) , SyntaxKind . OpenBracketToken , [ isNonJsxSameLineTokenContext ] , RuleAction . Delete ) ,
321+ rule ( "NoSpaceAfterCloseBracket" , SyntaxKind . CloseBracketToken , anyToken , [ isNonJsxSameLineTokenContext , isNotBeforeBlockInFunctionDeclarationContext ] , RuleAction . Delete ) ,
322+ rule ( "SpaceAfterSemicolon" , SyntaxKind . SemicolonToken , anyToken , [ isNonJsxSameLineTokenContext ] , RuleAction . Space ) ,
323+
319324 // Add a space between statements. All keywords except (do,else,case) has open/close parens after them.
320325 // So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any]
321326 rule (
@@ -326,11 +331,6 @@ namespace ts.formatting {
326331 RuleAction . Space ) ,
327332 // This low-pri rule takes care of "try {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter.
328333 rule ( "SpaceAfterTryFinally" , [ SyntaxKind . TryKeyword , SyntaxKind . FinallyKeyword ] , SyntaxKind . OpenBraceToken , [ isNonJsxSameLineTokenContext ] , RuleAction . Space ) ,
329-
330- // No space before and after indexer `x[]`
331- rule ( "NoSpaceBeforeOpenBracket" , anyTokenExcept ( SyntaxKind . AsyncKeyword ) , SyntaxKind . OpenBracketToken , [ isNonJsxSameLineTokenContext ] , RuleAction . Delete ) ,
332- rule ( "NoSpaceAfterCloseBracket" , SyntaxKind . CloseBracketToken , anyToken , [ isNonJsxSameLineTokenContext , isNotBeforeBlockInFunctionDeclarationContext ] , RuleAction . Delete ) ,
333- rule ( "SpaceAfterSemicolon" , SyntaxKind . SemicolonToken , anyToken , [ isNonJsxSameLineTokenContext ] , RuleAction . Space ) ,
334334 ] ;
335335
336336 return [
0 commit comments