@@ -2290,25 +2290,27 @@ namespace ts {
2290
2290
signature . typeParameters = parseTypeParameters ( ) ;
2291
2291
}
2292
2292
signature . parameters = parseParameterList ( flags ) ;
2293
+ signature . type = parseReturnType ( returnToken , ! ! ( flags & SignatureFlags . Type ) ) ;
2294
+ }
2293
2295
2294
- const returnTokenRequired = returnToken === SyntaxKind . EqualsGreaterThanToken ;
2295
- if ( returnTokenRequired ) {
2296
+ function parseReturnType ( returnToken : SyntaxKind . ColonToken | SyntaxKind . EqualsGreaterThanToken , isType : boolean ) : TypeNode | undefined {
2297
+ return shouldParseReturnType ( returnToken , isType ) ? parseTypeOrTypePredicate ( ) : undefined ;
2298
+ }
2299
+ function shouldParseReturnType ( returnToken : SyntaxKind . ColonToken | SyntaxKind . EqualsGreaterThanToken , isType : boolean ) : boolean {
2300
+ if ( returnToken === SyntaxKind . EqualsGreaterThanToken ) {
2296
2301
parseExpected ( returnToken ) ;
2297
- signature . type = parseTypeOrTypePredicate ( ) ;
2302
+ return true ;
2298
2303
}
2299
- else if ( parseOptional ( returnToken ) ) {
2300
- signature . type = parseTypeOrTypePredicate ( ) ;
2304
+ else if ( parseOptional ( SyntaxKind . ColonToken ) ) {
2305
+ return true ;
2301
2306
}
2302
- else if ( flags & SignatureFlags . Type ) {
2303
- const start = scanner . getTokenPos ( ) ;
2304
- const length = scanner . getTextPos ( ) - start ;
2305
- const backwardToken = parseOptional ( returnToken === SyntaxKind . ColonToken ? SyntaxKind . EqualsGreaterThanToken : SyntaxKind . ColonToken ) ;
2306
- if ( backwardToken ) {
2307
- // This is easy to get backward, especially in type contexts, so parse the type anyway
2308
- signature . type = parseTypeOrTypePredicate ( ) ;
2309
- parseErrorAtPosition ( start , length , Diagnostics . _0_expected , tokenToString ( returnToken ) ) ;
2310
- }
2307
+ else if ( isType && token ( ) === SyntaxKind . EqualsGreaterThanToken ) {
2308
+ // This is easy to get backward, especially in type contexts, so parse the type anyway
2309
+ parseErrorAtCurrentToken ( Diagnostics . _0_expected , tokenToString ( SyntaxKind . ColonToken ) ) ;
2310
+ nextToken ( ) ;
2311
+ return true ;
2311
2312
}
2313
+ return false ;
2312
2314
}
2313
2315
2314
2316
function parseParameterList ( flags : SignatureFlags ) {
0 commit comments