From 30ada4cffe77ac1f84fbd8ad9efd0fedb0c40774 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 10 Dec 2014 14:03:14 -0800 Subject: [PATCH 1/2] conditionals are now introduce indentation scope --- src/services/smartIndenter.ts | 1 + .../cases/fourslash/formattingConditionals.ts | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/cases/fourslash/formattingConditionals.ts diff --git a/src/services/smartIndenter.ts b/src/services/smartIndenter.ts index cafd92a7551..758c06226a4 100644 --- a/src/services/smartIndenter.ts +++ b/src/services/smartIndenter.ts @@ -342,6 +342,7 @@ module ts.formatting { case SyntaxKind.VariableDeclaration: case SyntaxKind.ExportAssignment: case SyntaxKind.ReturnStatement: + case SyntaxKind.ConditionalExpression: return true; } return false; diff --git a/tests/cases/fourslash/formattingConditionals.ts b/tests/cases/fourslash/formattingConditionals.ts new file mode 100644 index 00000000000..65029134b87 --- /dev/null +++ b/tests/cases/fourslash/formattingConditionals.ts @@ -0,0 +1,23 @@ +/// + + +////var v = +/////*0*/a === b +/////*1*/? c +/////*2*/: d; + +////var v = a === b +/////*3*/? c +/////*4*/: d; + +function verifyLine(marker: string, content: string) { + goTo.marker(marker); + verify.currentLineContentIs(content); +} + +format.document(); +verifyLine("0", " a === b"); +verifyLine("1", " ? c"); +verifyLine("2", " : d;"); +verifyLine("3", " ? c"); +verifyLine("4", " : d;"); From d69ba56ece6ece08051877d37f93d6906435b495 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 10 Dec 2014 22:01:34 -0800 Subject: [PATCH 2/2] added test for inherited indentation --- .../cases/fourslash/formattingConditionals.ts | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tests/cases/fourslash/formattingConditionals.ts b/tests/cases/fourslash/formattingConditionals.ts index 65029134b87..cb6edfcd56b 100644 --- a/tests/cases/fourslash/formattingConditionals.ts +++ b/tests/cases/fourslash/formattingConditionals.ts @@ -10,14 +10,35 @@ /////*3*/? c /////*4*/: d; +////var x = +/////*5*/a +/////*6*/? function(){ +/////*7*/var z = 1 +/////*8*/} +/////*9*/: function(){ +/////*10*/var z = 2 +/////*11*/} + + + + function verifyLine(marker: string, content: string) { goTo.marker(marker); verify.currentLineContentIs(content); } format.document(); -verifyLine("0", " a === b"); -verifyLine("1", " ? c"); -verifyLine("2", " : d;"); -verifyLine("3", " ? c"); -verifyLine("4", " : d;"); +verifyLine("0", " a === b"); +verifyLine("1", " ? c"); +verifyLine("2", " : d;"); + +verifyLine("3", " ? c"); +verifyLine("4", " : d;"); + +verifyLine("5", " a"); +verifyLine("6", " ? function() {"); +verifyLine("7", " var z = 1"); +verifyLine("8", " }"); +verifyLine("9", " : function() {"); +verifyLine("10", " var z = 2"); +verifyLine("11", " }");