Disable lookahead in isStartOfParameter/isStartOfType

This commit is contained in:
Nathan Shively-Sanders
2017-09-06 13:11:35 -07:00
parent d790f1d9d3
commit 7c69dd84b9
2 changed files with 12 additions and 5 deletions

View File

@@ -1283,7 +1283,7 @@ namespace ts {
args[i] = arguments[i];
}
return t => reduceLeft<(t: T) => T, T>(args, (u, f) => f(u), t);
return t => reduceLeft(args, (u, f) => f(u), t);
}
else if (d) {
return t => d(c(b(a(t))));

View File

@@ -2237,7 +2237,14 @@ namespace ts {
return token() === SyntaxKind.DotDotDotToken ||
isIdentifierOrPattern() ||
isModifierKind(token()) ||
token() === SyntaxKind.AtToken || isStartOfType();
token() === SyntaxKind.AtToken ||
// a jsdoc parameter can start directly with a type, but shouldn't look ahead
// in order to avoid confusion between parenthesized types and arrow functions
// eg
// declare function f(cb: function(number): void): void;
// vs
// f((n) => console.log(n));
isStartOfType(/*disableLookahead*/ true);
}
function parseParameter(): ParameterDeclaration {
@@ -2698,7 +2705,7 @@ namespace ts {
}
}
function isStartOfType(): boolean {
function isStartOfType(disableLookahead?: boolean): boolean {
switch (token()) {
case SyntaxKind.AnyKeyword:
case SyntaxKind.StringKeyword:
@@ -2728,11 +2735,11 @@ namespace ts {
case SyntaxKind.DotDotDotToken:
return true;
case SyntaxKind.MinusToken:
return lookAhead(nextTokenIsNumericLiteral);
return !disableLookahead && lookAhead(nextTokenIsNumericLiteral);
case SyntaxKind.OpenParenToken:
// Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier,
// or something that starts a type. We don't want to consider things like '(1)' a type.
return lookAhead(isStartOfParenthesizedOrFunctionType);
return !disableLookahead && lookAhead(isStartOfParenthesizedOrFunctionType);
default:
return isIdentifier();
}