diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts
index f609edb0501..56290800c0d 100644
--- a/src/services/formatting/rules.ts
+++ b/src/services/formatting/rules.ts
@@ -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,
diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts
index ebbf09e9feb..9c341dca5ff 100644
--- a/src/services/formatting/smartIndenter.ts
+++ b/src/services/formatting/smartIndenter.ts
@@ -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:
diff --git a/tests/cases/fourslash/formatTypeOperation.ts b/tests/cases/fourslash/formatTypeOperation.ts
new file mode 100644
index 00000000000..8708ef34d5c
--- /dev/null
+++ b/tests/cases/fourslash/formatTypeOperation.ts
@@ -0,0 +1,26 @@
+///
+
+////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;");
\ No newline at end of file
diff --git a/tests/cases/fourslash/formatTypeUnion.ts b/tests/cases/fourslash/formatTypeUnion.ts
deleted file mode 100644
index 267ba656612..00000000000
--- a/tests/cases/fourslash/formatTypeUnion.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-///
-
-////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");
\ No newline at end of file