@@ -26,7 +26,7 @@ module ts.formatting {
2626 precedingToken . kind === SyntaxKind . TemplateHead ||
2727 precedingToken . kind === SyntaxKind . TemplateMiddle ||
2828 precedingToken . kind === SyntaxKind . TemplateTail ;
29- if ( precedingTokenIsLiteral && precedingToken . getStart ( sourceFile ) <= position && precedingToken . end > position ) {
29+ if ( precedingTokenIsLiteral && precedingToken . getStart ( sourceFile ) <= position && precedingToken . end > position ) {
3030 return 0 ;
3131 }
3232
@@ -110,6 +110,12 @@ module ts.formatting {
110110 if ( actualIndentation !== Value . Unknown ) {
111111 return actualIndentation + indentationDelta ;
112112 }
113+
114+ // check if current node is a block-form item - if yes, take indentation from it
115+ actualIndentation = getActualIndentationForBlockFormItem ( current , sourceFile , options ) ;
116+ if ( actualIndentation !== Value . Unknown ) {
117+ return actualIndentation + indentationDelta ;
118+ }
113119 }
114120 parentStart = getParentStart ( parent , current , sourceFile ) ;
115121 let parentAndChildShareLine =
@@ -277,6 +283,15 @@ module ts.formatting {
277283 return undefined ;
278284 }
279285
286+ function getActualIndentationForBlockFormItem ( node : Node , sourceFile : SourceFile , options : EditorOptions ) : number {
287+ if ( isPassableBlockForm ( node . kind ) ) {
288+ let firstChild = node . getChildAt ( 0 ) ;
289+ let lineAndCharacter = getStartLineAndCharacterForNode ( firstChild , sourceFile ) ;
290+ return findColumnForFirstNonWhitespaceCharacterInLine ( lineAndCharacter , sourceFile , options ) ;
291+ }
292+ return Value . Unknown ;
293+ }
294+
280295 function getActualIndentationForListItem ( node : Node , sourceFile : SourceFile , options : EditorOptions ) : number {
281296 let containingList = getContainingList ( node , sourceFile ) ;
282297 return containingList ? getActualIndentationFromList ( containingList ) : Value . Unknown ;
@@ -400,5 +415,16 @@ module ts.formatting {
400415 return false ;
401416 }
402417 }
418+
419+ export function isPassableBlockForm ( kind : SyntaxKind ) : boolean {
420+ switch ( kind ) {
421+ case SyntaxKind . ArrowFunction :
422+ case SyntaxKind . FunctionExpression :
423+ case SyntaxKind . ArrayLiteralExpression :
424+ case SyntaxKind . ObjectLiteralExpression :
425+ return true ;
426+ }
427+ return false ;
428+ }
403429 }
404430}
0 commit comments