@@ -676,6 +676,19 @@ namespace ts {
676676
677677 export function isDeclarationWithTypeParameters ( node : Node ) : node is DeclarationWithTypeParameters ;
678678 export function isDeclarationWithTypeParameters ( node : DeclarationWithTypeParameters ) : node is DeclarationWithTypeParameters {
679+ switch ( node . kind ) {
680+ case SyntaxKind . JSDocCallbackTag :
681+ case SyntaxKind . JSDocTypedefTag :
682+ case SyntaxKind . JSDocSignature :
683+ return true ;
684+ default :
685+ assertType < DeclarationWithTypeParameterChildren > ( node ) ;
686+ return isDeclarationWithTypeParameterChildren ( node ) ;
687+ }
688+ }
689+
690+ export function isDeclarationWithTypeParameterChildren ( node : Node ) : node is DeclarationWithTypeParameterChildren ;
691+ export function isDeclarationWithTypeParameterChildren ( node : DeclarationWithTypeParameterChildren ) : node is DeclarationWithTypeParameterChildren {
679692 switch ( node . kind ) {
680693 case SyntaxKind . CallSignature :
681694 case SyntaxKind . ConstructSignature :
@@ -696,12 +709,9 @@ namespace ts {
696709 case SyntaxKind . SetAccessor :
697710 case SyntaxKind . FunctionExpression :
698711 case SyntaxKind . ArrowFunction :
699- case SyntaxKind . JSDocCallbackTag :
700- case SyntaxKind . JSDocTypedefTag :
701- case SyntaxKind . JSDocSignature :
702712 return true ;
703713 default :
704- assertTypeIsNever ( node ) ;
714+ assertType < never > ( node ) ;
705715 return false ;
706716 }
707717 }
@@ -786,7 +796,7 @@ namespace ts {
786796 return createDiagnosticForNodeInSourceFile ( sourceFile , node , message , arg0 , arg1 , arg2 , arg3 ) ;
787797 }
788798
789- export function createDiagnosticForNodeArray ( sourceFile : SourceFile , nodes : NodeArray < Node > , message : DiagnosticMessage , arg0 ?: string | number , arg1 ?: string | number , arg2 ?: string | number , arg3 ?: string | number ) : Diagnostic {
799+ export function createDiagnosticForNodeArray ( sourceFile : SourceFile , nodes : NodeArray < Node > , message : DiagnosticMessage , arg0 ?: string | number , arg1 ?: string | number , arg2 ?: string | number , arg3 ?: string | number ) : DiagnosticWithLocation {
790800 const start = skipTrivia ( sourceFile . text , nodes . pos ) ;
791801 return createFileDiagnostic ( sourceFile , start , nodes . end - start , message , arg0 , arg1 , arg2 , arg3 ) ;
792802 }
@@ -8128,4 +8138,75 @@ namespace ts {
81288138 }
81298139 return { min, max } ;
81308140 }
8141+
8142+ export interface ReadonlyNodeSet < TNode extends Node > {
8143+ has ( node : TNode ) : boolean ;
8144+ forEach ( cb : ( node : TNode ) => void ) : void ;
8145+ some ( pred : ( node : TNode ) => boolean ) : boolean ;
8146+ }
8147+
8148+ export class NodeSet < TNode extends Node > implements ReadonlyNodeSet < TNode > {
8149+ private map = createMap < TNode > ( ) ;
8150+
8151+ add ( node : TNode ) : void {
8152+ this . map . set ( String ( getNodeId ( node ) ) , node ) ;
8153+ }
8154+ tryAdd ( node : TNode ) : boolean {
8155+ if ( this . has ( node ) ) return false ;
8156+ this . add ( node ) ;
8157+ return true ;
8158+ }
8159+ has ( node : TNode ) : boolean {
8160+ return this . map . has ( String ( getNodeId ( node ) ) ) ;
8161+ }
8162+ forEach ( cb : ( node : TNode ) => void ) : void {
8163+ this . map . forEach ( cb ) ;
8164+ }
8165+ some ( pred : ( node : TNode ) => boolean ) : boolean {
8166+ return forEachEntry ( this . map , pred ) || false ;
8167+ }
8168+ }
8169+
8170+ export interface ReadonlyNodeMap < TNode extends Node , TValue > {
8171+ get ( node : TNode ) : TValue | undefined ;
8172+ has ( node : TNode ) : boolean ;
8173+ }
8174+
8175+ export class NodeMap < TNode extends Node , TValue > implements ReadonlyNodeMap < TNode , TValue > {
8176+ private map = createMap < { node : TNode , value : TValue } > ( ) ;
8177+
8178+ get ( node : TNode ) : TValue | undefined {
8179+ const res = this . map . get ( String ( getNodeId ( node ) ) ) ;
8180+ return res && res . value ;
8181+ }
8182+
8183+ getOrUpdate ( node : TNode , setValue : ( ) => TValue ) : TValue {
8184+ const res = this . get ( node ) ;
8185+ if ( res ) return res ;
8186+ const value = setValue ( ) ;
8187+ this . set ( node , value ) ;
8188+ return value ;
8189+ }
8190+
8191+ set ( node : TNode , value : TValue ) : void {
8192+ this . map . set ( String ( getNodeId ( node ) ) , { node, value } ) ;
8193+ }
8194+
8195+ has ( node : TNode ) : boolean {
8196+ return this . map . has ( String ( getNodeId ( node ) ) ) ;
8197+ }
8198+
8199+ forEach ( cb : ( value : TValue , node : TNode ) => void ) : void {
8200+ this . map . forEach ( ( { node, value } ) => cb ( value , node ) ) ;
8201+ }
8202+ }
8203+
8204+ export function rangeOfNode ( node : Node ) : TextRange {
8205+ return { pos : getTokenPosOfNode ( node ) , end : node . end } ;
8206+ }
8207+
8208+ export function rangeOfTypeParameters ( typeParameters : NodeArray < TypeParameterDeclaration > ) : TextRange {
8209+ // Include the `<>`
8210+ return { pos : typeParameters . pos - 1 , end : typeParameters . end + 1 } ;
8211+ }
81318212}
0 commit comments