From 990f1c7c37533e63fa828b1b816efde7411ce012 Mon Sep 17 00:00:00 2001 From: Yui Date: Thu, 5 May 2016 14:18:12 -0700 Subject: [PATCH] Check that token is AsyncKeyword before calling lookAhead (#8477) * Check that token is AsyncKeyword before calling lookAhead * Fix linting errors --- src/compiler/parser.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8d3eacc3dfe..b4995a103f4 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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(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(expr, asyncModifier); + } } return undefined; }