mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 17:30:04 -05:00
Merge branch 'master' into funcDeclsInBlocks
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -340,6 +340,7 @@ module ts.formatting {
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.ExportAssignment:
|
||||
case SyntaxKind.ReturnStatement:
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
20
tests/cases/fourslash/formattingCommentsBeforeErrors.ts
Normal file
20
tests/cases/fourslash/formattingCommentsBeforeErrors.ts
Normal 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 ");
|
||||
44
tests/cases/fourslash/formattingConditionals.ts
Normal file
44
tests/cases/fourslash/formattingConditionals.ts
Normal 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", " }");
|
||||
Reference in New Issue
Block a user