@@ -325,7 +325,7 @@ namespace ts.formatting {
325325
326326 let lastIndentedLine : number ;
327327 let indentationOnLastIndentedLine : number ;
328-
328+
329329 let edits : TextChange [ ] = [ ] ;
330330
331331 formattingScanner . advance ( ) ;
@@ -354,12 +354,12 @@ namespace ts.formatting {
354354 * If list element is in the range - its indentation will be equal
355355 * to inherited indentation from its predecessors.
356356 */
357- function tryComputeIndentationForListItem ( startPos : number ,
358- endPos : number ,
359- parentStartLine : number ,
360- range : TextRange ,
357+ function tryComputeIndentationForListItem ( startPos : number ,
358+ endPos : number ,
359+ parentStartLine : number ,
360+ range : TextRange ,
361361 inheritedIndentation : number ) : number {
362-
362+
363363 if ( rangeOverlapsWithStartEnd ( range , startPos , endPos ) ) {
364364 if ( inheritedIndentation !== Constants . Unknown ) {
365365 return inheritedIndentation ;
@@ -376,7 +376,7 @@ namespace ts.formatting {
376376
377377 return Constants . Unknown ;
378378 }
379-
379+
380380 function computeIndentation (
381381 node : TextRangeWithKind ,
382382 startLine : number ,
@@ -419,8 +419,8 @@ namespace ts.formatting {
419419 // if node is located on the same line with the parent
420420 // - inherit indentation from the parent
421421 // - push children if either parent of node itself has non-zero delta
422- indentation = startLine === lastIndentedLine
423- ? indentationOnLastIndentedLine
422+ indentation = startLine === lastIndentedLine
423+ ? indentationOnLastIndentedLine
424424 : parentDynamicIndentation . getIndentation ( ) ;
425425 delta = Math . min ( options . IndentSize , parentDynamicIndentation . getDelta ( ) + delta ) ;
426426 }
@@ -586,7 +586,7 @@ namespace ts.formatting {
586586 if ( ! rangeOverlapsWithStartEnd ( originalRange , child . pos , child . end ) ) {
587587 return inheritedIndentation ;
588588 }
589-
589+
590590 if ( child . getFullWidth ( ) === 0 ) {
591591 return inheritedIndentation ;
592592 }
@@ -624,8 +624,8 @@ namespace ts.formatting {
624624 return inheritedIndentation ;
625625 }
626626
627- function processChildNodes ( nodes : NodeArray < Node > ,
628- parent : Node ,
627+ function processChildNodes ( nodes : NodeArray < Node > ,
628+ parent : Node ,
629629 parentStartLine : number ,
630630 parentDynamicIndentation : DynamicIndentation ) : void {
631631
@@ -751,7 +751,7 @@ namespace ts.formatting {
751751 // indent token only if is it is in target range and does not overlap with any error ranges
752752 if ( tokenIndentation !== Constants . Unknown ) {
753753 insertIndentation ( currentTokenInfo . token . pos , tokenIndentation , lineAdded ) ;
754-
754+
755755 lastIndentedLine = tokenStart . line ;
756756 indentationOnLastIndentedLine = tokenIndentation ;
757757 }
@@ -772,12 +772,12 @@ namespace ts.formatting {
772772 }
773773 }
774774
775- function processRange ( range : TextRangeWithKind ,
776- rangeStart : LineAndCharacter ,
777- parent : Node ,
778- contextNode : Node ,
775+ function processRange ( range : TextRangeWithKind ,
776+ rangeStart : LineAndCharacter ,
777+ parent : Node ,
778+ contextNode : Node ,
779779 dynamicIndentation : DynamicIndentation ) : boolean {
780-
780+
781781 let rangeHasError = rangeContainsError ( range ) ;
782782 let lineAdded : boolean ;
783783 if ( ! rangeHasError && ! previousRangeHasError ) {
@@ -787,7 +787,7 @@ namespace ts.formatting {
787787 trimTrailingWhitespacesForLines ( originalStart . line , rangeStart . line ) ;
788788 }
789789 else {
790- lineAdded =
790+ lineAdded =
791791 processPair ( range , rangeStart . line , parent , previousRange , previousRangeStartLine , previousParent , contextNode , dynamicIndentation )
792792 }
793793 }
@@ -933,8 +933,8 @@ namespace ts.formatting {
933933 let lineStartPosition = getStartPositionOfLine ( line , sourceFile ) ;
934934 let lineEndPosition = getEndLinePosition ( line , sourceFile ) ;
935935
936- // do not trim whitespaces in comments
937- if ( range && isComment ( range . kind ) && range . pos <= lineEndPosition && range . end > lineEndPosition ) {
936+ // do not trim whitespaces in comments or template expression
937+ if ( range && ( isComment ( range . kind ) || isStringOrRegularExpressionOrTemplateLiteral ( range . kind ) ) && range . pos <= lineEndPosition && range . end > lineEndPosition ) {
938938 continue ;
939939 }
940940
0 commit comments