Check that token is AsyncKeyword before calling lookAhead (#8477)

* Check that token is AsyncKeyword before calling lookAhead

* Fix linting errors
This commit is contained in:
Yui 2016-05-05 14:18:12 -07:00
parent 166f95c677
commit 990f1c7c37

View File

@ -2989,11 +2989,14 @@ namespace ts {
}
function tryParseAsyncSimpleArrowFunctionExpression(): ArrowFunction {
const isUnParenthesizedAsyncArrowFunction = lookAhead(isUnParenthesizedAsyncArrowFunctionWorker);
if (isUnParenthesizedAsyncArrowFunction === Tristate.True) {
const asyncModifier = parseModifiersForArrowFunction();
const expr = parseBinaryExpressionOrHigher(/*precedence*/ 0);
return parseSimpleArrowFunctionExpression(<Identifier>expr, asyncModifier);
// We do a check here so that we won't be doing unnecessarily call to "lookAhead"
if (token === SyntaxKind.AsyncKeyword) {
const isUnParenthesizedAsyncArrowFunction = lookAhead(isUnParenthesizedAsyncArrowFunctionWorker);
if (isUnParenthesizedAsyncArrowFunction === Tristate.True) {
const asyncModifier = parseModifiersForArrowFunction();
const expr = parseBinaryExpressionOrHigher(/*precedence*/ 0);
return parseSimpleArrowFunctionExpression(<Identifier>expr, asyncModifier);
}
}
return undefined;
}