Skip to content

Commit b8a1712

Browse files
committed
include binding element with initializer to current formatting rule for binary operator, adjust existing SpaceBeforeOpenBraceInFunction rule to recognize blocks
1 parent ea09299 commit b8a1712

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/services/formatting/rules.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ module ts.formatting {
239239

240240
// Place a space before open brace in a function declaration
241241
this.FunctionOpenBraceLeftTokenRange = Shared.TokenRange.AnyIncludingMultilineComments;
242-
this.SpaceBeforeOpenBraceInFunction = new Rule(RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), RuleAction.Space), RuleFlags.CanDeleteNewLines);
242+
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);
243243

244244
// Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc)
245245
this.TypeScriptOpenBraceLeftTokenRange = Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.MultiLineCommentTrivia]);
@@ -470,6 +470,8 @@ module ts.formatting {
470470
// Technically, "of" is not a binary operator, but format it the same way as "in"
471471
case SyntaxKind.ForOfStatement:
472472
return context.currentTokenSpan.kind === SyntaxKind.OfKeyword || context.nextTokenSpan.kind === SyntaxKind.OfKeyword;
473+
case SyntaxKind.BindingElement:
474+
return context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken;
473475
}
474476
return false;
475477
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
/////*1*/function drawText( { text = "", location: [x, y]= [0, 0], bold = false }) {
4+
//// // Draw text
5+
////}
6+
7+
format.document();
8+
goTo.marker("1");
9+
verify.currentLineContentIs("function drawText({ text = \"\", location: [x, y] = [0, 0], bold = false }) {");

0 commit comments

Comments
 (0)