Merge pull request #4623 from SaschaNaz/formatIntersectionType
Format intersection type
This commit is contained in:
commit
3c96e70766
4 changed files with 33 additions and 18 deletions
|
@ -227,11 +227,13 @@ namespace ts.formatting {
|
|||
public SpaceBetweenTagAndTemplateString: Rule;
|
||||
public NoSpaceBetweenTagAndTemplateString: Rule;
|
||||
|
||||
// Union type
|
||||
// Type operation
|
||||
public SpaceBeforeBar: Rule;
|
||||
public NoSpaceBeforeBar: Rule;
|
||||
public SpaceAfterBar: Rule;
|
||||
public NoSpaceAfterBar: Rule;
|
||||
public SpaceBeforeAmpersand: Rule;
|
||||
public SpaceAfterAmpersand: Rule;
|
||||
|
||||
constructor() {
|
||||
///
|
||||
|
@ -394,12 +396,13 @@ namespace ts.formatting {
|
|||
this.SpaceBetweenTagAndTemplateString = new Rule(RuleDescriptor.create3(SyntaxKind.Identifier, Shared.TokenRange.FromTokens([SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||
this.NoSpaceBetweenTagAndTemplateString = new Rule(RuleDescriptor.create3(SyntaxKind.Identifier, Shared.TokenRange.FromTokens([SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
|
||||
// union type
|
||||
// type operation
|
||||
this.SpaceBeforeBar = new Rule(RuleDescriptor.create3(SyntaxKind.BarToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||
this.NoSpaceBeforeBar = new Rule(RuleDescriptor.create3(SyntaxKind.BarToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
this.SpaceAfterBar = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.BarToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||
this.NoSpaceAfterBar = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.BarToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||
|
||||
this.SpaceBeforeAmpersand = new Rule(RuleDescriptor.create3(SyntaxKind.AmpersandToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||
this.SpaceAfterAmpersand = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.AmpersandToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||
|
||||
// These rules are higher in priority than user-configurable rules.
|
||||
this.HighPriorityCommonRules =
|
||||
|
@ -432,6 +435,7 @@ namespace ts.formatting {
|
|||
this.SpaceAfterTypeKeyword, this.NoSpaceAfterTypeKeyword,
|
||||
this.SpaceBetweenTagAndTemplateString, this.NoSpaceBetweenTagAndTemplateString,
|
||||
this.SpaceBeforeBar, this.NoSpaceBeforeBar, this.SpaceAfterBar, this.NoSpaceAfterBar,
|
||||
this.SpaceBeforeAmpersand, this.SpaceAfterAmpersand,
|
||||
|
||||
// TypeScript-specific rules
|
||||
this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport,
|
||||
|
|
|
@ -436,7 +436,6 @@ namespace ts.formatting {
|
|||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.FunctionType:
|
||||
case SyntaxKind.ConstructorType:
|
||||
case SyntaxKind.UnionType:
|
||||
case SyntaxKind.ParenthesizedType:
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
case SyntaxKind.AwaitExpression:
|
||||
|
|
26
tests/cases/fourslash/formatTypeOperation.ts
Normal file
26
tests/cases/fourslash/formatTypeOperation.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////type Union = number | {}/*formatBarOperator*/
|
||||
/////*indent*/
|
||||
////|string/*autoformat*/
|
||||
////type Intersection = Foo & Bar;/*formatAmpersandOperator*/
|
||||
////type Complexed =
|
||||
//// Foo&
|
||||
//// Bar|/*unionTypeNoIndent*/
|
||||
//// Baz;/*intersectionTypeNoIndent*/
|
||||
|
||||
format.document();
|
||||
|
||||
goTo.marker("formatBarOperator");
|
||||
verify.currentLineContentIs("type Union = number | {}");
|
||||
goTo.marker("indent");
|
||||
verify.indentationIs(4);
|
||||
goTo.marker("autoformat");
|
||||
verify.currentLineContentIs(" | string");
|
||||
goTo.marker("formatAmpersandOperator");
|
||||
verify.currentLineContentIs("type Intersection = Foo & Bar;");
|
||||
|
||||
goTo.marker("unionTypeNoIndent");
|
||||
verify.currentLineContentIs(" Bar |");
|
||||
goTo.marker("intersectionTypeNoIndent");
|
||||
verify.currentLineContentIs(" Baz;");
|
|
@ -1,14 +0,0 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////type Union = number | {}/*formatOperator*/
|
||||
/////*indent*/
|
||||
////|string/*autoformat*/
|
||||
|
||||
format.document();
|
||||
|
||||
goTo.marker("formatOperator");
|
||||
verify.currentLineContentIs("type Union = number | {}");
|
||||
goTo.marker("indent");
|
||||
verify.indentationIs(4);
|
||||
goTo.marker("autoformat");
|
||||
verify.currentLineContentIs(" | string");
|
Loading…
Reference in a new issue