Skip to content

Commit 990f1c7

Browse files
committed
Check that token is AsyncKeyword before calling lookAhead (#8477)
* Check that token is AsyncKeyword before calling lookAhead * Fix linting errors
1 parent 166f95c commit 990f1c7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/compiler/parser.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,11 +2989,14 @@ namespace ts {
29892989
}
29902990

29912991
function tryParseAsyncSimpleArrowFunctionExpression(): ArrowFunction {
2992-
const isUnParenthesizedAsyncArrowFunction = lookAhead(isUnParenthesizedAsyncArrowFunctionWorker);
2993-
if (isUnParenthesizedAsyncArrowFunction === Tristate.True) {
2994-
const asyncModifier = parseModifiersForArrowFunction();
2995-
const expr = parseBinaryExpressionOrHigher(/*precedence*/ 0);
2996-
return parseSimpleArrowFunctionExpression(<Identifier>expr, asyncModifier);
2992+
// We do a check here so that we won't be doing unnecessarily call to "lookAhead"
2993+
if (token === SyntaxKind.AsyncKeyword) {
2994+
const isUnParenthesizedAsyncArrowFunction = lookAhead(isUnParenthesizedAsyncArrowFunctionWorker);
2995+
if (isUnParenthesizedAsyncArrowFunction === Tristate.True) {
2996+
const asyncModifier = parseModifiersForArrowFunction();
2997+
const expr = parseBinaryExpressionOrHigher(/*precedence*/ 0);
2998+
return parseSimpleArrowFunctionExpression(<Identifier>expr, asyncModifier);
2999+
}
29973000
}
29983001
return undefined;
29993002
}

0 commit comments

Comments
 (0)