Fix await in function name and parameters (#7727)

* Disallow await in function parameters

* Fix await as function name

* Update test whitelists
This commit is contained in:
Nicolò Ribaudo
2018-11-06 08:30:06 +01:00
committed by GitHub
parent 2194842d11
commit 2fa1984635
33 changed files with 963 additions and 51 deletions

View File

@@ -842,6 +842,7 @@ export default class StatementParser extends ExpressionParser {
): T {
const oldInFunc = this.state.inFunction;
const oldInMethod = this.state.inMethod;
const oldInAsync = this.state.inAsync;
const oldInGenerator = this.state.inGenerator;
const oldInClassProperty = this.state.inClassProperty;
this.state.inFunction = true;
@@ -872,11 +873,18 @@ export default class StatementParser extends ExpressionParser {
// valid because yield is parsed as if it was outside the generator.
// Therefore, this.state.inGenerator is set before or after parsing the
// function id according to the "isStatement" parameter.
if (!isStatement) this.state.inGenerator = node.generator;
// The same applies to await & async functions.
if (!isStatement) {
this.state.inAsync = isAsync;
this.state.inGenerator = node.generator;
}
if (this.match(tt.name) || this.match(tt._yield)) {
node.id = this.parseBindingIdentifier();
}
if (isStatement) this.state.inGenerator = node.generator;
if (isStatement) {
this.state.inAsync = isAsync;
this.state.inGenerator = node.generator;
}
this.parseFunctionParams(node);
this.parseFunctionBodyAndFinish(
@@ -887,6 +895,7 @@ export default class StatementParser extends ExpressionParser {
this.state.inFunction = oldInFunc;
this.state.inMethod = oldInMethod;
this.state.inAsync = oldInAsync;
this.state.inGenerator = oldInGenerator;
this.state.inClassProperty = oldInClassProperty;