@@ -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 {
@@ -2696,7 +2703,7 @@ namespace ts {
2696
2703
}
2697
2704
}
2698
2705
2699
- function isStartOfType ( ) : boolean {
2706
+ function isStartOfType ( disableLookahead ?: boolean ) : boolean {
2700
2707
switch ( token ( ) ) {
2701
2708
case SyntaxKind . AnyKeyword :
2702
2709
case SyntaxKind . StringKeyword :
@@ -2723,11 +2730,11 @@ namespace ts {
2723
2730
case SyntaxKind . AsteriskToken :
2724
2731
return true ;
2725
2732
case SyntaxKind . MinusToken :
2726
- return lookAhead ( nextTokenIsNumericLiteral ) ;
2733
+ return ! disableLookahead && lookAhead ( nextTokenIsNumericLiteral ) ;
2727
2734
case SyntaxKind . OpenParenToken :
2728
2735
// Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier,
2729
2736
// or something that starts a type. We don't want to consider things like '(1)' a type.
2730
- return lookAhead ( isStartOfParenthesizedOrFunctionType ) ;
2737
+ return ! disableLookahead && lookAhead ( isStartOfParenthesizedOrFunctionType ) ;
2731
2738
default :
2732
2739
return isIdentifier ( ) ;
2733
2740
}
0 commit comments