From 0dc29195d9925ac96ee44babeed694c2a30909c7 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 5 May 2016 10:17:49 -0700 Subject: [PATCH 1/2] Check that token is AsyncKeyword before calling lookAhead --- 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 8d3eacc3dfe39..1fa3a0e32c9f2 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; } From 6b540117ff66c09006a2fc819d11d55c19f58b73 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 5 May 2016 10:46:03 -0700 Subject: [PATCH 2/2] Fix linting errors --- src/compiler/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1fa3a0e32c9f2..b4995a103f4e1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2991,7 +2991,7 @@ namespace ts { function tryParseAsyncSimpleArrowFunctionExpression(): ArrowFunction { // We do a check here so that we won't be doing unnecessarily call to "lookAhead" if (token === SyntaxKind.AsyncKeyword) { - const isUnParenthesizedAsyncArrowFunction = lookAhead(isUnParenthesizedAsyncArrowFunctionWorker); + const isUnParenthesizedAsyncArrowFunction = lookAhead(isUnParenthesizedAsyncArrowFunctionWorker); if (isUnParenthesizedAsyncArrowFunction === Tristate.True) { const asyncModifier = parseModifiersForArrowFunction(); const expr = parseBinaryExpressionOrHigher(/*precedence*/ 0);