Skip to content

Commit 6a789b3

Browse files
committed
format conditional expression based on microsoft#4757
1 parent 068256b commit 6a789b3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/services/formatting/smartIndenter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ namespace ts.formatting {
463463
case SyntaxKind.VariableDeclaration:
464464
case SyntaxKind.ExportAssignment:
465465
case SyntaxKind.ReturnStatement:
466-
case SyntaxKind.ConditionalExpression:
467466
case SyntaxKind.ArrayBindingPattern:
468467
case SyntaxKind.ObjectBindingPattern:
469468
case SyntaxKind.JsxOpeningElement:
@@ -512,6 +511,8 @@ namespace ts.formatting {
512511
((<ImportClause>child).namedBindings && (<ImportClause>child).namedBindings.kind !== SyntaxKind.NamedImports);
513512
case SyntaxKind.JsxElement:
514513
return childKind !== SyntaxKind.JsxClosingElement;
514+
case SyntaxKind.ConditionalExpression:
515+
return (parent as ConditionalExpression).whenFalse !== child;
515516
}
516517
// No explicit rule for given nodes so the result will follow the default value argument
517518
return indentByDefault;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////let v =
4+
//// 0 ? 1 :
5+
//// //
6+
/////*falseBranchExpression*/ 2 ? 3 :
7+
/////*indent*/
8+
//// //
9+
/////*falseBranchToken*/ 2;
10+
11+
format.document();
12+
13+
goTo.marker("falseBranchExpression");
14+
verify.currentLineContentIs(" 2 ? 3 :");
15+
goTo.marker("indent");
16+
verify.indentationIs(8);
17+
goTo.marker("falseBranchToken");
18+
verify.currentLineContentIs(" 2;");

0 commit comments

Comments
 (0)