mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
Merge pull request #5353 from Microsoft/tokenFollowingMultilineComment
do not indent token if its start line matches end line of previous to…
This commit is contained in:
@@ -695,8 +695,8 @@ namespace ts.formatting {
|
||||
let tokenStart = sourceFile.getLineAndCharacterOfPosition(currentTokenInfo.token.pos);
|
||||
if (isTokenInRange) {
|
||||
let rangeHasError = rangeContainsError(currentTokenInfo.token);
|
||||
// save prevStartLine since processRange will overwrite this value with current ones
|
||||
let prevStartLine = previousRangeStartLine;
|
||||
// save previousRange since processRange will overwrite this value with current one
|
||||
let savePreviousRange = previousRange;
|
||||
lineAdded = processRange(currentTokenInfo.token, tokenStart, parent, childContextNode, dynamicIndentation);
|
||||
if (rangeHasError) {
|
||||
// do not indent comments\token if token range overlaps with some error
|
||||
@@ -707,7 +707,9 @@ namespace ts.formatting {
|
||||
indentToken = lineAdded;
|
||||
}
|
||||
else {
|
||||
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevStartLine;
|
||||
// indent token only if end line of previous range does not match start line of the token
|
||||
const prevEndLine = savePreviousRange && sourceFile.getLineAndCharacterOfPosition(savePreviousRange.end).line;
|
||||
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevEndLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
7
tests/cases/fourslash/formatAfterMultilineComment.ts
Normal file
7
tests/cases/fourslash/formatAfterMultilineComment.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
/////*foo
|
||||
////*/"123123";
|
||||
|
||||
format.document();
|
||||
verify.currentFileContentIs(`/*foo
|
||||
*/"123123";`)
|
||||
Reference in New Issue
Block a user