Merge pull request #1441 from Microsoft/dont_indent_comments_on_errors

do not indent leading comments that attached to tokens with errors
This commit is contained in:
Vladimir Matveev
2014-12-10 22:02:15 -08:00
2 changed files with 30 additions and 3 deletions

View File

@@ -622,14 +622,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;
}
}
}