@@ -445,7 +445,7 @@ namespace ts {
445
445
return position < candidate . end || ! isCompletedNode ( candidate , sourceFile ) ;
446
446
}
447
447
448
- export function isCompletedNode ( n : Node , sourceFile : SourceFile ) : boolean {
448
+ function isCompletedNode ( n : Node , sourceFile : SourceFile ) : boolean {
449
449
if ( nodeIsMissing ( n ) ) {
450
450
return false ;
451
451
}
@@ -512,7 +512,7 @@ namespace ts {
512
512
513
513
case SyntaxKind . ExpressionStatement :
514
514
return isCompletedNode ( ( < ExpressionStatement > n ) . expression , sourceFile ) ||
515
- hasChildOfKind ( n , SyntaxKind . SemicolonToken ) ;
515
+ hasChildOfKind ( n , SyntaxKind . SemicolonToken , sourceFile ) ;
516
516
517
517
case SyntaxKind . ArrayLiteralExpression :
518
518
case SyntaxKind . ArrayBindingPattern :
@@ -540,11 +540,9 @@ namespace ts {
540
540
return isCompletedNode ( ( < IterationStatement > n ) . statement , sourceFile ) ;
541
541
case SyntaxKind . DoStatement :
542
542
// rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')';
543
- const hasWhileKeyword = findChildOfKind ( n , SyntaxKind . WhileKeyword , sourceFile ) ;
544
- if ( hasWhileKeyword ) {
545
- return nodeEndsWith ( n , SyntaxKind . CloseParenToken , sourceFile ) ;
546
- }
547
- return isCompletedNode ( ( < DoStatement > n ) . statement , sourceFile ) ;
543
+ return hasChildOfKind ( n , SyntaxKind . WhileKeyword , sourceFile )
544
+ ? nodeEndsWith ( n , SyntaxKind . CloseParenToken , sourceFile )
545
+ : isCompletedNode ( ( < DoStatement > n ) . statement , sourceFile ) ;
548
546
549
547
case SyntaxKind . TypeQuery :
550
548
return isCompletedNode ( ( < TypeQueryNode > n ) . exprName , sourceFile ) ;
@@ -619,12 +617,12 @@ namespace ts {
619
617
} ;
620
618
}
621
619
622
- export function hasChildOfKind ( n : Node , kind : SyntaxKind , sourceFile ? : SourceFile ) : boolean {
620
+ export function hasChildOfKind ( n : Node , kind : SyntaxKind , sourceFile : SourceFile ) : boolean {
623
621
return ! ! findChildOfKind ( n , kind , sourceFile ) ;
624
622
}
625
623
626
- export function findChildOfKind ( n : Node , kind : SyntaxKind , sourceFile ? : SourceFileLike ) : Node | undefined {
627
- return forEach ( n . getChildren ( sourceFile ) , c => c . kind === kind && c ) ;
624
+ export function findChildOfKind < T extends Node > ( n : Node , kind : T [ "kind" ] , sourceFile : SourceFileLike ) : T | undefined {
625
+ return find ( n . getChildren ( sourceFile ) , ( c ) : c is T => c . kind === kind ) ;
628
626
}
629
627
630
628
export function findContainingList ( node : Node ) : SyntaxList | undefined {
@@ -1113,10 +1111,6 @@ namespace ts {
1113
1111
export function singleElementArray < T > ( t : T | undefined ) : T [ ] {
1114
1112
return t === undefined ? undefined : [ t ] ;
1115
1113
}
1116
-
1117
- export function getFirstChildOfKind ( node : Node , sourceFile : SourceFile , kind : SyntaxKind ) : Node | undefined {
1118
- return find ( node . getChildren ( sourceFile ) , c => c . kind === kind ) ;
1119
- }
1120
1114
}
1121
1115
1122
1116
// Display-part writer helpers
0 commit comments