@@ -323,6 +323,9 @@ module ts.formatting {
323323 let previousParent : Node ;
324324 let previousRangeStartLine : number ;
325325
326+ let lastIndentedLine : number ;
327+ let indentationOnLastIndentedLine : number ;
328+
326329 let edits : TextChange [ ] = [ ] ;
327330
328331 formattingScanner . advance ( ) ;
@@ -416,7 +419,9 @@ module ts.formatting {
416419 // if node is located on the same line with the parent
417420 // - inherit indentation from the parent
418421 // - push children if either parent of node itself has non-zero delta
419- indentation = parentDynamicIndentation . getIndentation ( ) ;
422+ indentation = startLine === lastIndentedLine
423+ ? indentationOnLastIndentedLine
424+ : parentDynamicIndentation . getIndentation ( ) ;
420425 delta = Math . min ( options . IndentSize , parentDynamicIndentation . getDelta ( ) + delta ) ;
421426 }
422427 return {
@@ -716,7 +721,6 @@ module ts.formatting {
716721 continue ;
717722 }
718723
719- let triviaStartLine = sourceFile . getLineAndCharacterOfPosition ( triviaItem . pos ) . line ;
720724 switch ( triviaItem . kind ) {
721725 case SyntaxKind . MultiLineCommentTrivia :
722726 let commentIndentation = dynamicIndentation . getIndentationForComment ( currentTokenInfo . token . kind ) ;
@@ -741,6 +745,9 @@ module ts.formatting {
741745 if ( isTokenInRange && ! rangeContainsError ( currentTokenInfo . token ) ) {
742746 let tokenIndentation = dynamicIndentation . getIndentationForToken ( tokenStart . line , currentTokenInfo . token . kind ) ;
743747 insertIndentation ( currentTokenInfo . token . pos , tokenIndentation , lineAdded ) ;
748+
749+ lastIndentedLine = tokenStart . line ;
750+ indentationOnLastIndentedLine = tokenIndentation ;
744751 }
745752 }
746753
0 commit comments