MCPcopy
hub / github.com/jquery/esprima / parseSwitchStatement

Method parseSwitchStatement

src/parser.ts:2471–2503  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

parseStatementMethod · 0.95

Calls 9

createNodeMethod · 0.95
expectKeywordMethod · 0.95
expectMethod · 0.95
parseExpressionMethod · 0.95
matchMethod · 0.95
parseSwitchCaseMethod · 0.95
throwErrorMethod · 0.95
finalizeMethod · 0.95
pushMethod · 0.80

Tested by

no test coverage detected