Improve parsing in await and yield context (#44680)

* Improve parsing in await and yield context

* Avoid yield and await check in identifier

* Revert "Avoid yield and awaitt check in identifier"

This reverts commit 9644859f29.

* Add some comments
This commit is contained in:
Wenlu Wang
2021-06-22 08:30:55 +08:00
committed by GitHub
parent 9708022537
commit fafe3ff0b4
6 changed files with 388 additions and 3 deletions

View File

@@ -1501,6 +1501,8 @@ namespace ts {
if (token() === SyntaxKind.Identifier) {
return true;
}
// `let await`/`let yield` in [Yield] or [Await] are allowed here and disallowed in the binder.
return token() > SyntaxKind.LastReservedWord;
}
@@ -6122,15 +6124,15 @@ namespace ts {
}
}
function nextTokenIsIdentifierOrStartOfDestructuring() {
function nextTokenIsBindingIdentifierOrStartOfDestructuring() {
nextToken();
return isIdentifier() || token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.OpenBracketToken;
return isBindingIdentifier() || token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.OpenBracketToken;
}
function isLetDeclaration() {
// In ES6 'let' always starts a lexical declaration if followed by an identifier or {
// or [.
return lookAhead(nextTokenIsIdentifierOrStartOfDestructuring);
return lookAhead(nextTokenIsBindingIdentifierOrStartOfDestructuring);
}
function parseStatement(): Statement {