Merge branch 'master' into funcDeclsInBlocks

This commit is contained in:
Cyrus Najmabadi
2014-12-11 14:59:03 -08:00
4 changed files with 75 additions and 3 deletions

View File

@@ -620,14 +620,21 @@ module ts.formatting {
var tokenStart = sourceFile.getLineAndCharacterFromPosition(currentTokenInfo.token.pos);
if (isTokenInRange) {
var rangeHasError = rangeContainsError(currentTokenInfo.token);
// save prevStartLine since processRange will overwrite this value with current ones
var prevStartLine = previousRangeStartLine;
lineAdded = processRange(currentTokenInfo.token, tokenStart, parent, childContextNode, dynamicIndentation);
if (lineAdded !== undefined) {
indentToken = lineAdded;
if (rangeHasError) {
// do not indent comments\token if token range overlaps with some error
indentToken = false;
}
else {
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevStartLine;
if (lineAdded !== undefined) {
indentToken = lineAdded;
}
else {
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevStartLine;
}
}
}

View File

@@ -340,6 +340,7 @@ module ts.formatting {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.ExportAssignment:
case SyntaxKind.ReturnStatement:
case SyntaxKind.ConditionalExpression:
return true;
}
return false;

View File

@@ -0,0 +1,20 @@
/// <reference path='fourslash.ts' />
////module A {
//// interface B {
//// // a
//// // b
//// baz();
/////*0*/ // d /*1*/asd a
//// // e
//// foo();
//// // f asd
//// // g as
//// bar();
//// }
////}
goTo.marker("1");
edit.insert("\n");
goTo.marker("0");
verify.currentLineContentIs(" // d ");

View File

@@ -0,0 +1,44 @@
/// <reference path='fourslash.ts' />
////var v =
/////*0*/a === b
/////*1*/? c
/////*2*/: d;
////var v = a === b
/////*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("5", " a");
verifyLine("6", " ? function() {");
verifyLine("7", " var z = 1");
verifyLine("8", " }");
verifyLine("9", " : function() {");
verifyLine("10", " var z = 2");
verifyLine("11", " }");