@@ -328,8 +328,13 @@ module ts.formatting {
328328
329329 if ( formattingScanner . isOnToken ( ) ) {
330330 let startLine = sourceFile . getLineAndCharacterOfPosition ( enclosingNode . getStart ( sourceFile ) ) . line ;
331+ let undecoratedStartLine = startLine ;
332+ if ( enclosingNode . decorators ) {
333+ undecoratedStartLine = sourceFile . getLineAndCharacterOfPosition ( getNonDecoratorTokenPosOfNode ( enclosingNode , sourceFile ) ) . line ;
334+ }
335+
331336 let delta = getOwnOrInheritedDelta ( enclosingNode , options , sourceFile ) ;
332- processNode ( enclosingNode , enclosingNode , startLine , initialIndentation , delta ) ;
337+ processNode ( enclosingNode , enclosingNode , startLine , undecoratedStartLine , initialIndentation , delta ) ;
333338 }
334339
335340 formattingScanner . close ( ) ;
@@ -500,7 +505,7 @@ module ts.formatting {
500505 }
501506 }
502507
503- function processNode ( node : Node , contextNode : Node , nodeStartLine : number , indentation : number , delta : number ) {
508+ function processNode ( node : Node , contextNode : Node , nodeStartLine : number , undecoratedNodeStartLine : number , indentation : number , delta : number ) {
504509 if ( ! rangeOverlapsWithStartEnd ( originalRange , node . getStart ( sourceFile ) , node . getEnd ( ) ) ) {
505510 return ;
506511 }
@@ -526,7 +531,7 @@ module ts.formatting {
526531 forEachChild (
527532 node ,
528533 child => {
529- processChildNode ( child , /*inheritedIndentation*/ Constants . Unknown , node , nodeDynamicIndentation , nodeStartLine , /*isListElement*/ false )
534+ processChildNode ( child , /*inheritedIndentation*/ Constants . Unknown , node , nodeDynamicIndentation , nodeStartLine , undecoratedNodeStartLine , /*isListElement*/ false )
530535 } ,
531536 ( nodes : NodeArray < Node > ) => {
532537 processChildNodes ( nodes , node , nodeStartLine , nodeDynamicIndentation ) ;
@@ -547,11 +552,17 @@ module ts.formatting {
547552 parent : Node ,
548553 parentDynamicIndentation : DynamicIndentation ,
549554 parentStartLine : number ,
555+ undecoratedParentStartLine : number ,
550556 isListItem : boolean ) : number {
551557
552558 let childStartPos = child . getStart ( sourceFile ) ;
553559
554- let childStart = sourceFile . getLineAndCharacterOfPosition ( childStartPos ) ;
560+ let childStartLine = sourceFile . getLineAndCharacterOfPosition ( childStartPos ) . line ;
561+
562+ let undecoratedChildStartLine = childStartLine ;
563+ if ( child . decorators ) {
564+ undecoratedChildStartLine = sourceFile . getLineAndCharacterOfPosition ( getNonDecoratorTokenPosOfNode ( child , sourceFile ) ) . line ;
565+ }
555566
556567 // if child is a list item - try to get its indentation
557568 let childIndentationAmount = Constants . Unknown ;
@@ -594,9 +605,10 @@ module ts.formatting {
594605 return inheritedIndentation ;
595606 }
596607
597- let childIndentation = computeIndentation ( child , childStart . line , childIndentationAmount , node , parentDynamicIndentation , parentStartLine ) ;
608+ let effectiveParentStartLine = child . kind === SyntaxKind . Decorator ? childStartLine : undecoratedParentStartLine ;
609+ let childIndentation = computeIndentation ( child , childStartLine , childIndentationAmount , node , parentDynamicIndentation , effectiveParentStartLine ) ;
598610
599- processNode ( child , childContextNode , childStart . line , childIndentation . indentation , childIndentation . delta ) ;
611+ processNode ( child , childContextNode , childStartLine , undecoratedChildStartLine , childIndentation . indentation , childIndentation . delta ) ;
600612
601613 childContextNode = node ;
602614
@@ -640,7 +652,7 @@ module ts.formatting {
640652
641653 let inheritedIndentation = Constants . Unknown ;
642654 for ( let child of nodes ) {
643- inheritedIndentation = processChildNode ( child , inheritedIndentation , node , listDynamicIndentation , startLine , /*isListElement*/ true )
655+ inheritedIndentation = processChildNode ( child , inheritedIndentation , node , listDynamicIndentation , startLine , startLine , /*isListElement*/ true )
644656 }
645657
646658 if ( listEndToken !== SyntaxKind . Unknown ) {
0 commit comments