Merge pull request #14899 from KingHenne/fix/format-multi-line-object-destructuring
Fix formatting for multi-line object destructuring
This commit is contained in:
commit
75e8ba746e
|
@ -297,8 +297,8 @@ namespace ts.formatting {
|
|||
// Insert a space after { and before } in single-line contexts, but remove space from empty object literals {}.
|
||||
this.SpaceAfterOpenBrace = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsBraceWrappedContext), RuleAction.Space));
|
||||
this.SpaceBeforeCloseBrace = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsBraceWrappedContext), RuleAction.Space));
|
||||
this.NoSpaceAfterOpenBrace = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsBraceWrappedContext), RuleAction.Delete));
|
||||
this.NoSpaceBeforeCloseBrace = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsBraceWrappedContext), RuleAction.Delete));
|
||||
this.NoSpaceAfterOpenBrace = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBraceToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceBeforeCloseBrace = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
|
||||
this.NoSpaceBetweenEmptyBraceBrackets = new Rule(RuleDescriptor.create1(SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsObjectContext), RuleAction.Delete));
|
||||
|
||||
// Insert new line after { and before } in multi-line contexts.
|
||||
|
|
20
tests/cases/fourslash/formattingInDestructuring3.ts
Normal file
20
tests/cases/fourslash/formattingInDestructuring3.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
/////*1*/const {
|
||||
/////*2*/ a,
|
||||
/////*3*/ b,
|
||||
/////*4*/} = {a: 1, b: 2};
|
||||
/////*5*/const {a: c} = {a: 1, b: 2};
|
||||
|
||||
format.document();
|
||||
|
||||
goTo.marker("1");
|
||||
verify.currentLineContentIs("const {");
|
||||
goTo.marker("2");
|
||||
verify.currentLineContentIs(" a,");
|
||||
goTo.marker("3");
|
||||
verify.currentLineContentIs(" b,");
|
||||
goTo.marker("4");
|
||||
verify.currentLineContentIs("} = { a: 1, b: 2 };");
|
||||
goTo.marker("5");
|
||||
verify.currentLineContentIs("const { a: c } = { a: 1, b: 2 };");
|
19
tests/cases/fourslash/formattingInDestructuring4.ts
Normal file
19
tests/cases/fourslash/formattingInDestructuring4.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
/////*1*/const {
|
||||
/////*2*/ a,
|
||||
/////*3*/ b,
|
||||
/////*4*/} = { a: 1, b: 2 };
|
||||
|
||||
format.setOption('InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces', false);
|
||||
|
||||
format.document();
|
||||
|
||||
goTo.marker("1");
|
||||
verify.currentLineContentIs("const {");
|
||||
goTo.marker("2");
|
||||
verify.currentLineContentIs(" a,");
|
||||
goTo.marker("3");
|
||||
verify.currentLineContentIs(" b,");
|
||||
goTo.marker("4");
|
||||
verify.currentLineContentIs("} = {a: 1, b: 2};");
|
Loading…
Reference in a new issue