@@ -2237,7 +2237,14 @@ namespace ts {
2237
2237
return token ( ) === SyntaxKind . DotDotDotToken ||
2238
2238
isIdentifierOrPattern ( ) ||
2239
2239
isModifierKind ( token ( ) ) ||
2240
- token ( ) === SyntaxKind . AtToken || isStartOfType ( ) ;
2240
+ token ( ) === SyntaxKind . AtToken ||
2241
+ // a jsdoc parameter can start directly with a type, but shouldn't look ahead
2242
+ // in order to avoid confusion between parenthesized types and arrow functions
2243
+ // eg
2244
+ // declare function f(cb: function(number): void): void;
2245
+ // vs
2246
+ // f((n) => console.log(n));
2247
+ isStartOfType ( /*disableLookahead*/ true ) ;
2241
2248
}
2242
2249
2243
2250
function parseParameter ( ) : ParameterDeclaration {
@@ -2698,7 +2705,7 @@ namespace ts {
2698
2705
}
2699
2706
}
2700
2707
2701
- function isStartOfType ( ) : boolean {
2708
+ function isStartOfType ( disableLookahead ?: boolean ) : boolean {
2702
2709
switch ( token ( ) ) {
2703
2710
case SyntaxKind . AnyKeyword :
2704
2711
case SyntaxKind . StringKeyword :
@@ -2728,11 +2735,11 @@ namespace ts {
2728
2735
case SyntaxKind . DotDotDotToken :
2729
2736
return true ;
2730
2737
case SyntaxKind . MinusToken :
2731
- return lookAhead ( nextTokenIsNumericLiteral ) ;
2738
+ return ! disableLookahead && lookAhead ( nextTokenIsNumericLiteral ) ;
2732
2739
case SyntaxKind . OpenParenToken :
2733
2740
// Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier,
2734
2741
// or something that starts a type. We don't want to consider things like '(1)' a type.
2735
- return lookAhead ( isStartOfParenthesizedOrFunctionType ) ;
2742
+ return ! disableLookahead && lookAhead ( isStartOfParenthesizedOrFunctionType ) ;
2736
2743
default :
2737
2744
return isIdentifier ( ) ;
2738
2745
}
0 commit comments