()
| 2505 | // https://tc39.github.io/ecma262/#sec-labelled-statements |
| 2506 | |
| 2507 | parseLabelledStatement(): Node.LabeledStatement | Node.ExpressionStatement { |
| 2508 | const node = this.createNode(); |
| 2509 | const expr = this.parseExpression(); |
| 2510 | |
| 2511 | let statement: Node.ExpressionStatement | Node.LabeledStatement; |
| 2512 | if ((expr.type === Syntax.Identifier) && this.match(':')) { |
| 2513 | this.nextToken(); |
| 2514 | |
| 2515 | const id = expr as Node.Identifier; |
| 2516 | const key = '$' + id.name; |
| 2517 | if (Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) { |
| 2518 | this.throwError(Messages.Redeclaration, 'Label', id.name); |
| 2519 | } |
| 2520 | |
| 2521 | this.context.labelSet[key] = true; |
| 2522 | let body: Node.Statement; |
| 2523 | if (this.matchKeyword('class')) { |
| 2524 | this.tolerateUnexpectedToken(this.lookahead); |
| 2525 | body = this.parseClassDeclaration(); |
| 2526 | } else if (this.matchKeyword('function')) { |
| 2527 | const token = this.lookahead; |
| 2528 | const declaration = this.parseFunctionDeclaration(); |
| 2529 | if (this.context.strict) { |
| 2530 | this.tolerateUnexpectedToken(token, Messages.StrictFunction); |
| 2531 | } else if (declaration.generator) { |
| 2532 | this.tolerateUnexpectedToken(token, Messages.GeneratorInLegacyContext); |
| 2533 | } |
| 2534 | body = declaration; |
| 2535 | } else { |
| 2536 | body = this.parseStatement(); |
| 2537 | } |
| 2538 | delete this.context.labelSet[key]; |
| 2539 | |
| 2540 | statement = new Node.LabeledStatement(id, body); |
| 2541 | } else { |
| 2542 | this.consumeSemicolon(); |
| 2543 | statement = new Node.ExpressionStatement(expr); |
| 2544 | } |
| 2545 | |
| 2546 | return this.finalize(node, statement); |
| 2547 | } |
| 2548 | |
| 2549 | // https://tc39.github.io/ecma262/#sec-throw-statement |
| 2550 |
no test coverage detected