@@ -728,25 +728,24 @@ namespace ts.formatting {
728
728
dynamicIndentation . getIndentationForToken ( tokenStart . line , currentTokenInfo . token . kind , container ) :
729
729
Constants . Unknown ;
730
730
731
+ let indentNextTokenOrTrivia = true ;
731
732
if ( currentTokenInfo . leadingTrivia ) {
732
733
let commentIndentation = dynamicIndentation . getIndentationForComment ( currentTokenInfo . token . kind , tokenIndentation , container ) ;
733
- let indentNextTokenOrTrivia = true ;
734
734
735
735
for ( let triviaItem of currentTokenInfo . leadingTrivia ) {
736
- if ( ! rangeContainsRange ( originalRange , triviaItem ) ) {
737
- continue ;
738
- }
739
-
736
+ const triviaInRange = rangeContainsRange ( originalRange , triviaItem ) ;
740
737
switch ( triviaItem . kind ) {
741
738
case SyntaxKind . MultiLineCommentTrivia :
742
- indentMultilineComment ( triviaItem , commentIndentation , /*firstLineIsIndented*/ ! indentNextTokenOrTrivia ) ;
739
+ if ( triviaInRange ) {
740
+ indentMultilineComment ( triviaItem , commentIndentation , /*firstLineIsIndented*/ ! indentNextTokenOrTrivia ) ;
741
+ }
743
742
indentNextTokenOrTrivia = false ;
744
743
break ;
745
744
case SyntaxKind . SingleLineCommentTrivia :
746
- if ( indentNextTokenOrTrivia ) {
745
+ if ( indentNextTokenOrTrivia && triviaInRange ) {
747
746
insertIndentation ( triviaItem . pos , commentIndentation , /*lineAdded*/ false ) ;
748
- indentNextTokenOrTrivia = false ;
749
747
}
748
+ indentNextTokenOrTrivia = false ;
750
749
break ;
751
750
case SyntaxKind . NewLineTrivia :
752
751
indentNextTokenOrTrivia = true ;
@@ -756,7 +755,7 @@ namespace ts.formatting {
756
755
}
757
756
758
757
// indent token only if is it is in target range and does not overlap with any error ranges
759
- if ( tokenIndentation !== Constants . Unknown ) {
758
+ if ( tokenIndentation !== Constants . Unknown && indentNextTokenOrTrivia ) {
760
759
insertIndentation ( currentTokenInfo . token . pos , tokenIndentation , lineAdded ) ;
761
760
762
761
lastIndentedLine = tokenStart . line ;
0 commit comments