MCPcopy Create free account
hub / github.com/dop251/goja / parseSwitchStatement

Method parseSwitchStatement

parser/statement.go:513–549  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

511}
512
513func (self *_parser) parseSwitchStatement() ast.Statement {
514 idx := self.expect(token.SWITCH)
515 self.expect(token.LEFT_PARENTHESIS)
516 node := &ast.SwitchStatement{
517 Switch: idx,
518 Discriminant: self.parseExpression(),
519 Default: -1,
520 }
521 self.expect(token.RIGHT_PARENTHESIS)
522
523 self.expect(token.LEFT_BRACE)
524
525 inSwitch := self.scope.inSwitch
526 self.scope.inSwitch = true
527 defer func() {
528 self.scope.inSwitch = inSwitch
529 }()
530
531 for index := 0; self.token != token.EOF; index++ {
532 if self.token == token.RIGHT_BRACE {
533 node.RightBrace = self.idx
534 self.next()
535 break
536 }
537
538 clause := self.parseCaseStatement()
539 if clause.Test == nil {
540 if node.Default != -1 {
541 self.error(clause.Case, "Already saw a default in switch")
542 }
543 node.Default = index
544 }
545 node.Body = append(node.Body, clause)
546 }
547
548 return node
549}
550
551func (self *_parser) parseWithStatement() ast.Statement {
552 node := &ast.WithStatement{}

Callers 1

parseStatementMethod · 0.95

Calls 5

expectMethod · 0.95
parseExpressionMethod · 0.95
nextMethod · 0.95
parseCaseStatementMethod · 0.95
errorMethod · 0.95

Tested by

no test coverage detected