Skip to content

Commit 7c69dd8

Browse files
committed
Disable lookahead in isStartOfParameter/isStartOfType
1 parent d790f1d commit 7c69dd8

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
@@ -1283,7 +1283,7 @@ namespace ts {
12831283
args[i] = arguments[i];
12841284
}
12851285

1286-
return t => reduceLeft<(t: T) => T, T>(args, (u, f) => f(u), t);
1286+
return t => reduceLeft(args, (u, f) => f(u), t);
12871287
}
12881288
else if (d) {
12891289
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 {
@@ -2698,7 +2705,7 @@ namespace ts {
26982705
}
26992706
}
27002707

2701-
function isStartOfType(): boolean {
2708+
function isStartOfType(disableLookahead?: boolean): boolean {
27022709
switch (token()) {
27032710
case SyntaxKind.AnyKeyword:
27042711
case SyntaxKind.StringKeyword:
@@ -2728,11 +2735,11 @@ namespace ts {
27282735
case SyntaxKind.DotDotDotToken:
27292736
return true;
27302737
case SyntaxKind.MinusToken:
2731-
return lookAhead(nextTokenIsNumericLiteral);
2738+
return !disableLookahead && lookAhead(nextTokenIsNumericLiteral);
27322739
case SyntaxKind.OpenParenToken:
27332740
// Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier,
27342741
// 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);
27362743
default:
27372744
return isIdentifier();
27382745
}

0 commit comments

Comments
 (0)