Skip to content

Commit d3ce606

Browse files
committed
Disable lookahead in isStartOfParameter/isStartOfType
1 parent 655145c commit d3ce606

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ namespace ts {
12571257
args[i] = arguments[i];
12581258
}
12591259

1260-
return t => reduceLeft<(t: T) => T, T>(args, (u, f) => f(u), t);
1260+
return t => reduceLeft(args, (u, f) => f(u), t);
12611261
}
12621262
else if (d) {
12631263
return t => d(c(b(a(t))));

src/compiler/parser.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,14 @@ namespace ts {
22372237
return token() === SyntaxKind.DotDotDotToken ||
22382238
isIdentifierOrPattern() ||
22392239
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);
22412248
}
22422249

22432250
function parseParameter(): ParameterDeclaration {
@@ -2696,7 +2703,7 @@ namespace ts {
26962703
}
26972704
}
26982705

2699-
function isStartOfType(): boolean {
2706+
function isStartOfType(disableLookahead?: boolean): boolean {
27002707
switch (token()) {
27012708
case SyntaxKind.AnyKeyword:
27022709
case SyntaxKind.StringKeyword:
@@ -2723,11 +2730,11 @@ namespace ts {
27232730
case SyntaxKind.AsteriskToken:
27242731
return true;
27252732
case SyntaxKind.MinusToken:
2726-
return lookAhead(nextTokenIsNumericLiteral);
2733+
return !disableLookahead && lookAhead(nextTokenIsNumericLiteral);
27272734
case SyntaxKind.OpenParenToken:
27282735
// Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier,
27292736
// 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);
27312738
default:
27322739
return isIdentifier();
27332740
}

0 commit comments

Comments
 (0)