From b8a1712688c159efb487be1171691c9ae9489dea Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sun, 22 Feb 2015 16:44:26 -0800 Subject: [PATCH] include binding element with initializer to current formatting rule for binary operator, adjust existing SpaceBeforeOpenBraceInFunction rule to recognize blocks --- src/services/formatting/rules.ts | 4 +++- tests/cases/fourslash/formattingInDestructuring2.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/formattingInDestructuring2.ts diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 697463831e1..c72839dfcc0 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -239,7 +239,7 @@ module ts.formatting { // Place a space before open brace in a function declaration this.FunctionOpenBraceLeftTokenRange = Shared.TokenRange.AnyIncludingMultilineComments; - this.SpaceBeforeOpenBraceInFunction = new Rule(RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, SyntaxKind.OpenBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), RuleAction.Space), RuleFlags.CanDeleteNewLines); + 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); // Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc) this.TypeScriptOpenBraceLeftTokenRange = Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.MultiLineCommentTrivia]); @@ -470,6 +470,8 @@ module ts.formatting { // Technically, "of" is not a binary operator, but format it the same way as "in" case SyntaxKind.ForOfStatement: return context.currentTokenSpan.kind === SyntaxKind.OfKeyword || context.nextTokenSpan.kind === SyntaxKind.OfKeyword; + case SyntaxKind.BindingElement: + return context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken; } return false; } diff --git a/tests/cases/fourslash/formattingInDestructuring2.ts b/tests/cases/fourslash/formattingInDestructuring2.ts new file mode 100644 index 00000000000..753eed44e12 --- /dev/null +++ b/tests/cases/fourslash/formattingInDestructuring2.ts @@ -0,0 +1,9 @@ +/// + +/////*1*/function drawText( { text = "", location: [x, y]= [0, 0], bold = false }) { +//// // Draw text +////} + +format.document(); +goTo.marker("1"); +verify.currentLineContentIs("function drawText({ text = \"\", location: [x, y] = [0, 0], bold = false }) {"); \ No newline at end of file