@@ -537,70 +537,56 @@ namespace ts.formatting {
537
537
case SyntaxKind . CloseBraceToken :
538
538
case SyntaxKind . CloseBracketToken :
539
539
case SyntaxKind . CloseParenToken :
540
- return indentation + getEffectiveDelta ( delta , container ) ;
540
+ return indentation + getDelta ( container ) ;
541
541
}
542
542
return tokenIndentation !== Constants . Unknown ? tokenIndentation : indentation ;
543
543
} ,
544
- getIndentationForToken : ( line , kind , container ) => {
545
- if ( nodeStartLine !== line && node . decorators ) {
546
- if ( kind === getFirstNonDecoratorTokenOfNode ( node ) ) {
547
- // if this token is the first token following the list of decorators, we do not need to indent
548
- return indentation ;
549
- }
550
- }
551
- switch ( kind ) {
552
- // open and close brace, 'else' and 'while' (in do statement) tokens has indentation of the parent
553
- case SyntaxKind . OpenBraceToken :
554
- case SyntaxKind . CloseBraceToken :
555
- case SyntaxKind . OpenParenToken :
556
- case SyntaxKind . CloseParenToken :
557
- case SyntaxKind . ElseKeyword :
558
- case SyntaxKind . WhileKeyword :
559
- case SyntaxKind . AtToken :
560
- return indentation ;
561
- case SyntaxKind . SlashToken :
562
- case SyntaxKind . GreaterThanToken : {
563
- if ( container . kind === SyntaxKind . JsxOpeningElement ||
564
- container . kind === SyntaxKind . JsxClosingElement ||
565
- container . kind === SyntaxKind . JsxSelfClosingElement
566
- ) {
567
- return indentation ;
568
- }
569
- break ;
570
- }
571
- case SyntaxKind . OpenBracketToken :
572
- case SyntaxKind . CloseBracketToken : {
573
- if ( container . kind !== SyntaxKind . MappedType ) {
574
- return indentation ;
575
- }
576
- break ;
577
- }
578
- }
579
- // if token line equals to the line of containing node (this is a first token in the node) - use node indentation
580
- return nodeStartLine !== line ? indentation + getEffectiveDelta ( delta , container ) : indentation ;
581
- } ,
544
+ getIndentationForToken : ( line , kind , container ) =>
545
+ shouldAddDelta ( line , kind , container ) ? indentation + getDelta ( container ) : indentation ,
582
546
getIndentation : ( ) => indentation ,
583
- getDelta : child => getEffectiveDelta ( delta , child ) ,
547
+ getDelta,
584
548
recomputeIndentation : lineAdded => {
585
549
if ( node . parent && SmartIndenter . shouldIndentChildNode ( node . parent , node ) ) {
586
- if ( lineAdded ) {
587
- indentation += options . indentSize ;
588
- }
589
- else {
590
- indentation -= options . indentSize ;
591
- }
550
+ indentation += lineAdded ? options . indentSize : - options . indentSize ;
551
+ delta = SmartIndenter . shouldIndentChildNode ( node ) ? options . indentSize : 0 ;
552
+ }
553
+ }
554
+ } ;
592
555
593
- if ( SmartIndenter . shouldIndentChildNode ( node ) ) {
594
- delta = options . indentSize ;
556
+ function shouldAddDelta ( line : number , kind : SyntaxKind , container : Node ) : boolean {
557
+ switch ( kind ) {
558
+ // open and close brace, 'else' and 'while' (in do statement) tokens has indentation of the parent
559
+ case SyntaxKind . OpenBraceToken :
560
+ case SyntaxKind . CloseBraceToken :
561
+ case SyntaxKind . OpenParenToken :
562
+ case SyntaxKind . CloseParenToken :
563
+ case SyntaxKind . ElseKeyword :
564
+ case SyntaxKind . WhileKeyword :
565
+ case SyntaxKind . AtToken :
566
+ return false ;
567
+ case SyntaxKind . SlashToken :
568
+ case SyntaxKind . GreaterThanToken :
569
+ switch ( container . kind ) {
570
+ case SyntaxKind . JsxOpeningElement :
571
+ case SyntaxKind . JsxClosingElement :
572
+ case SyntaxKind . JsxSelfClosingElement :
573
+ return false ;
595
574
}
596
- else {
597
- delta = 0 ;
575
+ break ;
576
+ case SyntaxKind . OpenBracketToken :
577
+ case SyntaxKind . CloseBracketToken :
578
+ if ( container . kind !== SyntaxKind . MappedType ) {
579
+ return false ;
598
580
}
599
- }
581
+ break ;
600
582
}
601
- } ;
583
+ // if token line equals to the line of containing node (this is a first token in the node) - use node indentation
584
+ return nodeStartLine !== line
585
+ // if this token is the first token following the list of decorators, we do not need to indent
586
+ && ! ( node . decorators && kind === getFirstNonDecoratorTokenOfNode ( node ) ) ;
587
+ }
602
588
603
- function getEffectiveDelta ( delta : number , child : TextRangeWithKind ) {
589
+ function getDelta ( child : TextRangeWithKind ) {
604
590
// Delta value should be zero when the node explicitly prevents indentation of the child node
605
591
return SmartIndenter . nodeWillIndentChild ( node , child , /*indentByDefault*/ true ) ? delta : 0 ;
606
592
}
0 commit comments