Skip to content

Commit 402baba

Browse files
committed
Merge pull request #5353 from Microsoft/tokenFollowingMultilineComment
do not indent token if its start line matches end line of previous to…
2 parents 853e9a2 + 912e49b commit 402baba

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/services/formatting/formatting.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,8 @@ namespace ts.formatting {
695695
let tokenStart = sourceFile.getLineAndCharacterOfPosition(currentTokenInfo.token.pos);
696696
if (isTokenInRange) {
697697
let rangeHasError = rangeContainsError(currentTokenInfo.token);
698-
// save prevStartLine since processRange will overwrite this value with current ones
699-
let prevStartLine = previousRangeStartLine;
698+
// save previousRange since processRange will overwrite this value with current one
699+
let savePreviousRange = previousRange;
700700
lineAdded = processRange(currentTokenInfo.token, tokenStart, parent, childContextNode, dynamicIndentation);
701701
if (rangeHasError) {
702702
// do not indent comments\token if token range overlaps with some error
@@ -707,7 +707,9 @@ namespace ts.formatting {
707707
indentToken = lineAdded;
708708
}
709709
else {
710-
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevStartLine;
710+
// indent token only if end line of previous range does not match start line of the token
711+
const prevEndLine = savePreviousRange && sourceFile.getLineAndCharacterOfPosition(savePreviousRange.end).line;
712+
indentToken = lastTriviaWasNewLine && tokenStart.line !== prevEndLine;
711713
}
712714
}
713715
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path="fourslash.ts"/>
2+
/////*foo
3+
////*/"123123";
4+
5+
format.document();
6+
verify.currentFileContentIs(`/*foo
7+
*/"123123";`)

0 commit comments

Comments
 (0)