`yield` 和 `await` 生产参数如何扩展为标识符前的 `*` 和 `async`

How does `yield` and `await` production parameters expand into `*` and `async` before identifiers

任何人都可以解释以下产品如何扩展为 *async 关键字:

BindingIdentifier[Yield, Await]:
   Identifier
   [~Yield]yield
   [~Await]await

根据 TypeScript 解析代码,我看到它检查 *async 关键字,所以我在这里假设 BindingIdentifier_Yield 匹配 *identifierBindingIdentifier_Await 匹配 async identifier 但我似乎无法使用上述语法跟踪该扩展。

我知道我可以根据规范扩展标识符 [Yield, Await]

A production may be parameterized by a subscripted annotation of the form “[parameters]”... A parameterized production is shorthand for a set of productions defining all combinations of the parameter names, preceded by an underscore, appended to the parameterized nonterminal symbol

所以上面展开为:

BindingIdentifier:
   Identifier
   [~Yield]yield
   [~Await]await

BindingIdentifier_Yield:
   Identifier
   [~Yield]yield
   [~Await]await

BindingIdentifier_Await:
   Identifier
   [~Yield]yield
   [~Await]await

但是BindingIdentifier_YieldBindingIdentifier_Await如何扩展为*async呢?我怀疑解释在这里:

[~Yield]yield
[~Await]await

但我不确定。欢迎任何帮助!

检查 * 令牌 in Typescript 存在以处理两者

14.1:

FunctionExpression[Yield, Await, Default]:
    function BindingIdentifier[?Yield, ?Await]opt ( FormalParameters[~Yield, ~Await] ) { FunctionBody[~Yield, ~Await] }

14.4:

GeneratorExpression[Yield, Await, Default]:
    function* BindingIdentifier[?Yield, ?Await]opt ( FormalParameters[+Yield, ~Await] ) { GeneratorBody }

因为函数和生成器表达式都可以从 PrimaryExpression 展开:

PrimaryExpression:
    this
    Literal
    ArrayLiteral
    ObjectLiteral
    FunctionExpression       <---------
    ClassExpression 
    GeneratorExpression      <---------
    AsyncFunctionExpression
    RegularExpressionLiteral
    TemplateLiteral

这些检查也与函数声明和方法语法重叠。

制作

BindingIdentifier [Yield, Await]:
    Identifier
    [~Yield] yield
    [~Await] await

扩展到

BindingIdentifier:
    Identifier
    yield
    await

BindingIdentifier_Yield:
    Identifier
    await

BindingIdentifier_Await:
    Identifier
    yield

BindingIdentifier_Yield_Await:
    Identifier

因此,在语法中使用了 +Yield and/or +Await 的情况下,不允许使用 yieldawait 标识符。你可以在上面的例子中看到,他们使用

FormalParameters[~Yield, ~Await]
FunctionBody[~Yield, ~Await]

而生成器使用

FormalParameters[+Yield, ~Await]
FunctionBody[+Yield, ~Await]

由于生成器说 +Yield 而不是 ~Yield,这意味着

function foo(){ var yield; } // works
function* foo(){ var yield; } // not allowed