Fix some cases of invalid labeled declarations

This commit is contained in:
Brian Ng
2017-08-24 19:00:52 -05:00
parent 5d83e2692f
commit 5e60ad6688
18 changed files with 274 additions and 36 deletions

View File

@@ -576,6 +576,16 @@ export default class StatementParser extends ExpressionParser {
statementStart: this.state.start,
});
node.body = this.parseStatement(true);
if (
node.body.type == "ClassDeclaration" ||
(node.body.type == "VariableDeclaration" && node.body.kind !== "var") ||
(node.body.type == "FunctionDeclaration" &&
(this.state.strict || node.body.generator || node.body.async))
) {
this.raise(node.body.start, "Invalid labeled declaration");
}
this.state.labels.pop();
node.label = expr;
return this.finishNode(node, "LabeledStatement");