Fix formatting of conditional types (#21762)

* Add test for formatting of conditional types

* Fix formatting of conditional types
This commit is contained in:
Priyantha Lankapura 2018-02-08 22:58:38 +05:30 committed by Mohamed Hegazy
parent 384527aa09
commit 79dde93068
3 changed files with 16 additions and 2 deletions

View File

@ -409,6 +409,7 @@ namespace ts.formatting {
switch (context.contextNode.kind) {
case SyntaxKind.BinaryExpression:
case SyntaxKind.ConditionalExpression:
case SyntaxKind.ConditionalType:
case SyntaxKind.AsExpression:
case SyntaxKind.ExportSpecifier:
case SyntaxKind.ImportSpecifier:
@ -461,7 +462,8 @@ namespace ts.formatting {
}
function isConditionalOperatorContext(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.ConditionalExpression;
return context.contextNode.kind === SyntaxKind.ConditionalExpression ||
context.contextNode.kind === SyntaxKind.ConditionalType;
}
function isSameLineTokenOrBeforeBlockContext(context: FormattingContext): boolean {

View File

@ -3,4 +3,4 @@
////var x=true?1:2
format.document();
goTo.bof();
verify.currentLineContentIs("var x = true ? 1 : 2");;
verify.currentLineContentIs("var x = true ? 1 : 2");

View File

@ -0,0 +1,12 @@
/// <reference path='fourslash.ts'/>
/////*L1*/type Diff1<T, U> = T extends U?never:T;
/////*L2*/type Diff2<T, U> = T extends U ? never : T;
format.document();
goTo.marker("L1");
verify.currentLineContentIs("type Diff1<T, U> = T extends U ? never : T;");
goTo.marker("L2");
verify.currentLineContentIs("type Diff2<T, U> = T extends U ? never : T;");