@@ -298,35 +298,49 @@ namespace ts.formatting {
298
298
function getLineIndentationWhenExpressionIsInMultiLine ( node : Node , sourceFile : SourceFile , options : EditorOptions ) : number {
299
299
// actual indentation should not be used when:
300
300
// - node is close parenthesis - this is the end of the expression
301
- // - node is property access expression
302
- if ( node . kind !== SyntaxKind . CloseParenToken &&
303
- node . kind !== SyntaxKind . PropertyAccessExpression &&
304
- node . parent && (
301
+ if ( node . kind === SyntaxKind . CloseParenToken ) {
302
+ return Value . Unknown ;
303
+ }
304
+
305
+ if ( node . parent && (
305
306
node . parent . kind === SyntaxKind . CallExpression ||
306
- node . parent . kind === SyntaxKind . NewExpression ) ) {
307
+ node . parent . kind === SyntaxKind . NewExpression ) &&
308
+ ( < CallExpression > node . parent ) . expression !== node ) {
307
309
308
- let parentExpression = ( < CallExpression | NewExpression > node . parent ) . expression ;
309
- let startingExpression = getStartingExpression ( < PropertyAccessExpression | CallExpression | ElementAccessExpression > parentExpression ) ;
310
+ let fullCallOrNewExpression = ( < CallExpression | NewExpression > node . parent ) . expression ;
311
+ let startingExpression = getStartingExpression ( < PropertyAccessExpression | CallExpression | ElementAccessExpression > fullCallOrNewExpression ) ;
310
312
311
- if ( parentExpression === startingExpression ) {
313
+ if ( fullCallOrNewExpression === startingExpression ) {
312
314
return Value . Unknown ;
313
315
}
314
316
315
- let parentExpressionEnd = sourceFile . getLineAndCharacterOfPosition ( parentExpression . end ) ;
317
+ let fullCallOrNewExpressionEnd = sourceFile . getLineAndCharacterOfPosition ( fullCallOrNewExpression . end ) ;
316
318
let startingExpressionEnd = sourceFile . getLineAndCharacterOfPosition ( startingExpression . end ) ;
317
319
318
- if ( parentExpressionEnd . line === startingExpressionEnd . line ) {
320
+ if ( fullCallOrNewExpressionEnd . line === startingExpressionEnd . line ) {
319
321
return Value . Unknown ;
320
322
}
321
323
322
- return findColumnForFirstNonWhitespaceCharacterInLine ( parentExpressionEnd , sourceFile , options ) ;
324
+ return findColumnForFirstNonWhitespaceCharacterInLine ( fullCallOrNewExpressionEnd , sourceFile , options ) ;
323
325
}
326
+
324
327
return Value . Unknown ;
325
328
326
- function getStartingExpression ( expression : PropertyAccessExpression | CallExpression | ElementAccessExpression ) {
327
- while ( expression . expression )
328
- expression = < PropertyAccessExpression | CallExpression | ElementAccessExpression > expression . expression ;
329
- return expression ;
329
+ function getStartingExpression ( node : PropertyAccessExpression | CallExpression | ElementAccessExpression ) {
330
+ while ( true ) {
331
+ switch ( node . kind ) {
332
+ case SyntaxKind . CallExpression :
333
+ case SyntaxKind . NewExpression :
334
+ case SyntaxKind . PropertyAccessExpression :
335
+ case SyntaxKind . ElementAccessExpression :
336
+
337
+ node = < PropertyAccessExpression | CallExpression | ElementAccessExpression | PropertyAccessExpression > node . expression ;
338
+ break ;
339
+ default :
340
+ return node ;
341
+ }
342
+ }
343
+ return node ;
330
344
}
331
345
}
332
346
0 commit comments