@@ -359,6 +359,7 @@ module ts.formatting {
359
359
case SyntaxKind . ModuleBlock :
360
360
case SyntaxKind . ObjectLiteralExpression :
361
361
case SyntaxKind . TypeLiteral :
362
+ case SyntaxKind . TupleType :
362
363
case SyntaxKind . CaseBlock :
363
364
case SyntaxKind . DefaultClause :
364
365
case SyntaxKind . CaseClause :
@@ -370,6 +371,8 @@ module ts.formatting {
370
371
case SyntaxKind . ExportAssignment :
371
372
case SyntaxKind . ReturnStatement :
372
373
case SyntaxKind . ConditionalExpression :
374
+ case SyntaxKind . ArrayBindingPattern :
375
+ case SyntaxKind . ObjectBindingPattern :
373
376
return true ;
374
377
}
375
378
return false ;
@@ -390,6 +393,7 @@ module ts.formatting {
390
393
case SyntaxKind . FunctionExpression :
391
394
case SyntaxKind . MethodDeclaration :
392
395
case SyntaxKind . MethodSignature :
396
+ case SyntaxKind . CallSignature :
393
397
case SyntaxKind . ArrowFunction :
394
398
case SyntaxKind . Constructor :
395
399
case SyntaxKind . GetAccessor :
@@ -431,53 +435,93 @@ module ts.formatting {
431
435
case SyntaxKind . InterfaceDeclaration :
432
436
case SyntaxKind . EnumDeclaration :
433
437
case SyntaxKind . ObjectLiteralExpression :
438
+ case SyntaxKind . ObjectBindingPattern :
439
+ case SyntaxKind . TypeLiteral :
434
440
case SyntaxKind . Block :
435
441
case SyntaxKind . ModuleBlock :
436
442
case SyntaxKind . CaseBlock :
437
443
return nodeEndsWith ( n , SyntaxKind . CloseBraceToken , sourceFile ) ;
438
444
case SyntaxKind . CatchClause :
439
445
return isCompletedNode ( ( < CatchClause > n ) . block , sourceFile ) ;
440
- case SyntaxKind . ParenthesizedExpression :
441
- case SyntaxKind . CallSignature :
446
+ case SyntaxKind . NewExpression :
447
+ if ( ! ( < NewExpression > n ) . arguments ) {
448
+ return true ;
449
+ }
450
+ // fall through
442
451
case SyntaxKind . CallExpression :
443
- case SyntaxKind . ConstructSignature :
452
+ case SyntaxKind . ParenthesizedExpression :
453
+ case SyntaxKind . ParenthesizedType :
444
454
return nodeEndsWith ( n , SyntaxKind . CloseParenToken , sourceFile ) ;
455
+
456
+ case SyntaxKind . FunctionType :
457
+ case SyntaxKind . ConstructorType :
458
+ return isCompletedNode ( ( < SignatureDeclaration > n ) . type , sourceFile ) ;
459
+
460
+ case SyntaxKind . Constructor :
461
+ case SyntaxKind . GetAccessor :
462
+ case SyntaxKind . SetAccessor :
445
463
case SyntaxKind . FunctionDeclaration :
446
464
case SyntaxKind . FunctionExpression :
447
465
case SyntaxKind . MethodDeclaration :
448
466
case SyntaxKind . MethodSignature :
467
+ case SyntaxKind . ConstructSignature :
468
+ case SyntaxKind . CallSignature :
449
469
case SyntaxKind . ArrowFunction :
450
- return ! ( < FunctionLikeDeclaration > n ) . body || isCompletedNode ( ( < FunctionLikeDeclaration > n ) . body , sourceFile ) ;
470
+ if ( ( < FunctionLikeDeclaration > n ) . body ) {
471
+ return isCompletedNode ( ( < FunctionLikeDeclaration > n ) . body , sourceFile ) ;
472
+ }
473
+
474
+ if ( ( < FunctionLikeDeclaration > n ) . type ) {
475
+ return isCompletedNode ( ( < FunctionLikeDeclaration > n ) . type , sourceFile ) ;
476
+ }
477
+
478
+ // Even though type parameters can be unclosed, we can get away with
479
+ // having at least a closing paren.
480
+ return hasChildOfKind ( n , SyntaxKind . CloseParenToken , sourceFile ) ;
481
+
451
482
case SyntaxKind . ModuleDeclaration :
452
483
return ( < ModuleDeclaration > n ) . body && isCompletedNode ( ( < ModuleDeclaration > n ) . body , sourceFile ) ;
484
+
453
485
case SyntaxKind . IfStatement :
454
486
if ( ( < IfStatement > n ) . elseStatement ) {
455
487
return isCompletedNode ( ( < IfStatement > n ) . elseStatement , sourceFile ) ;
456
488
}
457
489
return isCompletedNode ( ( < IfStatement > n ) . thenStatement , sourceFile ) ;
490
+
458
491
case SyntaxKind . ExpressionStatement :
459
492
return isCompletedNode ( ( < ExpressionStatement > n ) . expression , sourceFile ) ;
493
+
460
494
case SyntaxKind . ArrayLiteralExpression :
495
+ case SyntaxKind . ArrayBindingPattern :
496
+ case SyntaxKind . ComputedPropertyName :
497
+ case SyntaxKind . TupleType :
461
498
return nodeEndsWith ( n , SyntaxKind . CloseBracketToken , sourceFile ) ;
499
+
500
+ case SyntaxKind . IndexSignature :
501
+ if ( ( < IndexSignatureDeclaration > n ) . type ) {
502
+ return isCompletedNode ( ( < IndexSignatureDeclaration > n ) . type , sourceFile ) ;
503
+ }
504
+
505
+ return hasChildOfKind ( n , SyntaxKind . CloseBracketToken , sourceFile ) ;
506
+
462
507
case SyntaxKind . CaseClause :
463
508
case SyntaxKind . DefaultClause :
464
- // there is no such thing as terminator token for CaseClause\ DefaultClause so for simplicitly always consider them non-completed
509
+ // there is no such thing as terminator token for CaseClause/ DefaultClause so for simplicitly always consider them non-completed
465
510
return false ;
511
+
466
512
case SyntaxKind . ForStatement :
467
- return isCompletedNode ( ( < ForStatement > n ) . statement , sourceFile ) ;
468
513
case SyntaxKind . ForInStatement :
469
- return isCompletedNode ( ( < ForInStatement > n ) . statement , sourceFile ) ;
470
514
case SyntaxKind . ForOfStatement :
471
- return isCompletedNode ( ( < ForOfStatement > n ) . statement , sourceFile ) ;
472
515
case SyntaxKind . WhileStatement :
473
- return isCompletedNode ( ( < WhileStatement > n ) . statement , sourceFile ) ;
516
+ return isCompletedNode ( ( < IterationStatement > n ) . statement , sourceFile ) ;
474
517
case SyntaxKind . DoStatement :
475
518
// rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')';
476
519
let hasWhileKeyword = findChildOfKind ( n , SyntaxKind . WhileKeyword , sourceFile ) ;
477
520
if ( hasWhileKeyword ) {
478
521
return nodeEndsWith ( n , SyntaxKind . CloseParenToken , sourceFile ) ;
479
522
}
480
523
return isCompletedNode ( ( < DoStatement > n ) . statement , sourceFile ) ;
524
+
481
525
default :
482
526
return true ;
483
527
}
0 commit comments