@@ -96,6 +96,7 @@ module ts.formatting {
96
96
public NoSpaceBeforeComma : Rule ;
97
97
98
98
public SpaceAfterCertainKeywords : Rule ;
99
+ public SpaceAfterLetConstInVariableDeclaration : Rule ;
99
100
public NoSpaceBeforeOpenParenInFuncCall : Rule ;
100
101
public SpaceAfterFunctionInFuncDecl : Rule ;
101
102
public NoSpaceBeforeOpenParenInFuncDecl : Rule ;
@@ -243,7 +244,7 @@ module ts.formatting {
243
244
244
245
// Place a space before open brace in a function declaration
245
246
this . FunctionOpenBraceLeftTokenRange = Shared . TokenRange . AnyIncludingMultilineComments ;
246
- this . SpaceBeforeOpenBraceInFunction = new Rule ( RuleDescriptor . create2 ( this . FunctionOpenBraceLeftTokenRange , SyntaxKind . OpenBraceToken ) , RuleOperation . create2 ( new RuleOperationContext ( Rules . IsFunctionDeclContext , Rules . IsNotFormatOnEnter , Rules . IsSameLineTokenOrBeforeMultilineBlockContext ) , RuleAction . Space ) , RuleFlags . CanDeleteNewLines ) ;
247
+ this . SpaceBeforeOpenBraceInFunction = new Rule ( RuleDescriptor . create2 ( this . FunctionOpenBraceLeftTokenRange , SyntaxKind . OpenBraceToken ) , RuleOperation . create2 ( new RuleOperationContext ( Rules . IsFunctionDeclContext , Rules . IsBeforeBlockContext , Rules . IsNotFormatOnEnter , Rules . IsSameLineTokenOrBeforeMultilineBlockContext ) , RuleAction . Space ) , RuleFlags . CanDeleteNewLines ) ;
247
248
248
249
// Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc)
249
250
this . TypeScriptOpenBraceLeftTokenRange = Shared . TokenRange . FromTokens ( [ SyntaxKind . Identifier , SyntaxKind . MultiLineCommentTrivia ] ) ;
@@ -288,6 +289,7 @@ module ts.formatting {
288
289
this . NoSpaceBeforeComma = new Rule ( RuleDescriptor . create2 ( Shared . TokenRange . Any , SyntaxKind . CommaToken ) , RuleOperation . create2 ( new RuleOperationContext ( Rules . IsSameLineTokenContext ) , RuleAction . Delete ) ) ;
289
290
290
291
this . SpaceAfterCertainKeywords = new Rule ( RuleDescriptor . create4 ( Shared . TokenRange . FromTokens ( [ SyntaxKind . VarKeyword , SyntaxKind . ThrowKeyword , SyntaxKind . NewKeyword , SyntaxKind . DeleteKeyword , SyntaxKind . ReturnKeyword , SyntaxKind . TypeOfKeyword ] ) , Shared . TokenRange . Any ) , RuleOperation . create2 ( new RuleOperationContext ( Rules . IsSameLineTokenContext ) , RuleAction . Space ) ) ;
292
+ this . SpaceAfterLetConstInVariableDeclaration = new Rule ( RuleDescriptor . create4 ( Shared . TokenRange . FromTokens ( [ SyntaxKind . LetKeyword , SyntaxKind . ConstKeyword ] ) , Shared . TokenRange . Any ) , RuleOperation . create2 ( new RuleOperationContext ( Rules . IsSameLineTokenContext , Rules . IsStartOfVariableDeclarationList ) , RuleAction . Space ) ) ;
291
293
this . NoSpaceBeforeOpenParenInFuncCall = new Rule ( RuleDescriptor . create2 ( Shared . TokenRange . Any , SyntaxKind . OpenParenToken ) , RuleOperation . create2 ( new RuleOperationContext ( Rules . IsSameLineTokenContext , Rules . IsFunctionCallOrNewContext , Rules . IsPreviousTokenNotComma ) , RuleAction . Delete ) ) ;
292
294
this . SpaceAfterFunctionInFuncDecl = new Rule ( RuleDescriptor . create3 ( SyntaxKind . FunctionKeyword , Shared . TokenRange . Any ) , RuleOperation . create2 ( new RuleOperationContext ( Rules . IsFunctionDeclContext ) , RuleAction . Space ) ) ;
293
295
this . NoSpaceBeforeOpenParenInFuncDecl = new Rule ( RuleDescriptor . create2 ( Shared . TokenRange . Any , SyntaxKind . OpenParenToken ) , RuleOperation . create2 ( new RuleOperationContext ( Rules . IsSameLineTokenContext , Rules . IsFunctionDeclContext ) , RuleAction . Delete ) ) ;
@@ -362,6 +364,7 @@ module ts.formatting {
362
364
this . SpaceAfterFunctionInFuncDecl , this . NewLineAfterOpenBraceInBlockContext , this . SpaceAfterGetSetInMember ,
363
365
this . NoSpaceBetweenReturnAndSemicolon ,
364
366
this . SpaceAfterCertainKeywords ,
367
+ this . SpaceAfterLetConstInVariableDeclaration ,
365
368
this . NoSpaceBeforeOpenParenInFuncCall ,
366
369
this . SpaceBeforeBinaryKeywordOperator , this . SpaceAfterBinaryKeywordOperator ,
367
370
this . SpaceAfterVoidOperator ,
@@ -473,6 +476,8 @@ module ts.formatting {
473
476
// Technically, "of" is not a binary operator, but format it the same way as "in"
474
477
case SyntaxKind . ForOfStatement :
475
478
return context . currentTokenSpan . kind === SyntaxKind . OfKeyword || context . nextTokenSpan . kind === SyntaxKind . OfKeyword ;
479
+ case SyntaxKind . BindingElement :
480
+ return context . currentTokenSpan . kind === SyntaxKind . EqualsToken || context . nextTokenSpan . kind === SyntaxKind . EqualsToken ;
476
481
}
477
482
return false ;
478
483
}
@@ -644,6 +649,11 @@ module ts.formatting {
644
649
return context . TokensAreOnSameLine ( ) ;
645
650
}
646
651
652
+ static IsStartOfVariableDeclarationList ( context : FormattingContext ) : boolean {
653
+ return context . currentTokenParent . kind === SyntaxKind . VariableDeclarationList &&
654
+ context . currentTokenParent . getStart ( context . sourceFile ) === context . currentTokenSpan . pos ;
655
+ }
656
+
647
657
static IsNotFormatOnEnter ( context : FormattingContext ) : boolean {
648
658
return context . formattingRequestKind != FormattingRequestKind . FormatOnEnter ;
649
659
}
0 commit comments