()
| 2469 | } |
| 2470 | |
| 2471 | parseSwitchStatement(): Node.SwitchStatement { |
| 2472 | const node = this.createNode(); |
| 2473 | this.expectKeyword('switch'); |
| 2474 | |
| 2475 | this.expect('('); |
| 2476 | const discriminant = this.parseExpression(); |
| 2477 | this.expect(')'); |
| 2478 | |
| 2479 | const previousInSwitch = this.context.inSwitch; |
| 2480 | this.context.inSwitch = true; |
| 2481 | |
| 2482 | const cases: Node.SwitchCase[] = []; |
| 2483 | let defaultFound = false; |
| 2484 | this.expect('{'); |
| 2485 | while (true) { |
| 2486 | if (this.match('}')) { |
| 2487 | break; |
| 2488 | } |
| 2489 | const clause = this.parseSwitchCase(); |
| 2490 | if (clause.test === null) { |
| 2491 | if (defaultFound) { |
| 2492 | this.throwError(Messages.MultipleDefaultsInSwitch); |
| 2493 | } |
| 2494 | defaultFound = true; |
| 2495 | } |
| 2496 | cases.push(clause); |
| 2497 | } |
| 2498 | this.expect('}'); |
| 2499 | |
| 2500 | this.context.inSwitch = previousInSwitch; |
| 2501 | |
| 2502 | return this.finalize(node, new Node.SwitchStatement(discriminant, cases)); |
| 2503 | } |
| 2504 | |
| 2505 | // https://tc39.github.io/ecma262/#sec-labelled-statements |
| 2506 |
no test coverage detected