@@ -26,10 +26,22 @@ namespace ts.GoToDefinition {
2626 return label ? [ createDefinitionInfoFromName ( typeChecker , label , ScriptElementKind . label , node . text , /*containerName*/ undefined ! ) ] : undefined ; // TODO: GH#18217
2727 }
2828
29- if ( node . kind === SyntaxKind . ReturnKeyword ) {
30- const functionDeclaration = findAncestor ( node . parent , n =>
31- isClassStaticBlockDeclaration ( n ) ? "quit" : isFunctionLikeDeclaration ( n ) ) as FunctionLikeDeclaration | undefined ;
32- return functionDeclaration ? [ createDefinitionFromSignatureDeclaration ( typeChecker , functionDeclaration ) ] : undefined ;
29+ switch ( node . kind ) {
30+ case SyntaxKind . ReturnKeyword :
31+ const functionDeclaration = findAncestor ( node . parent , n =>
32+ isClassStaticBlockDeclaration ( n ) ? "quit" : isFunctionLikeDeclaration ( n ) ) as FunctionLikeDeclaration | undefined ;
33+ return functionDeclaration ? [ createDefinitionFromSignatureDeclaration ( typeChecker , functionDeclaration ) ] : undefined ;
34+ case SyntaxKind . DefaultKeyword :
35+ if ( ! isDefaultClause ( node . parent ) ) {
36+ break ;
37+ }
38+ // falls through
39+ case SyntaxKind . CaseKeyword :
40+ const switchStatement = findAncestor ( node . parent , isSwitchStatement ) ;
41+ if ( switchStatement ) {
42+ return [ createDefinitionInfoFromStatement ( switchStatement , SyntaxKind . SwitchKeyword , sourceFile , "switch" ) ] ;
43+ }
44+ break ;
3345 }
3446
3547 if ( isStaticModifier ( node ) && isClassStaticBlockDeclaration ( node . parent ) ) {
@@ -510,4 +522,25 @@ namespace ts.GoToDefinition {
510522 return false ;
511523 }
512524 }
525+
526+ interface StatementWithExpression extends Statement {
527+ readonly expression : Expression
528+ }
529+
530+ function createDefinitionInfoFromStatement < K extends KeywordSyntaxKind > ( statement : StatementWithExpression , keywordKind : K , sourceFile : SourceFile , name : string ) : DefinitionInfo {
531+ const keyword = find ( statement . getChildren ( sourceFile ) , ( node ) : node is Token < K > => node . kind === keywordKind ) ! ;
532+ return {
533+ fileName : sourceFile . fileName ,
534+ textSpan : createTextSpanFromNode ( keyword , sourceFile ) ,
535+ kind : ScriptElementKind . keyword ,
536+ name,
537+ containerKind : undefined ! ,
538+ containerName : "" ,
539+ contextSpan : createTextSpanFromNode ( statement . expression , sourceFile ) ,
540+ isLocal : true ,
541+ isAmbient : false ,
542+ unverified : false ,
543+ failedAliasResolution : undefined ,
544+ } ;
545+ }
513546}
0 commit comments