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

Method parseBreakStatement

parser/statement.go:960–1000  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

958}
959
960func (self *_parser) parseBreakStatement() ast.Statement {
961 idx := self.expect(token.BREAK)
962 semicolon := self.implicitSemicolon
963 if self.token == token.SEMICOLON {
964 semicolon = true
965 self.next()
966 }
967
968 if semicolon || self.token == token.RIGHT_BRACE {
969 self.implicitSemicolon = false
970 if !self.scope.inIteration && !self.scope.inSwitch {
971 goto illegal
972 }
973 return &ast.BranchStatement{
974 Idx: idx,
975 Token: token.BREAK,
976 }
977 }
978
979 self.tokenToBindingId()
980 if self.token == token.IDENTIFIER {
981 identifier := self.parseIdentifier()
982 if !self.scope.hasLabel(identifier.Name) {
983 self.error(idx, "Undefined label '%s'", identifier.Name)
984 return &ast.BadStatement{From: idx, To: identifier.Idx1()}
985 }
986 self.semicolon()
987 return &ast.BranchStatement{
988 Idx: idx,
989 Token: token.BREAK,
990 Label: identifier,
991 }
992 }
993
994 self.expect(token.IDENTIFIER)
995
996illegal:
997 self.error(idx, "Illegal break statement")
998 self.nextStatement()
999 return &ast.BadStatement{From: idx, To: self.idx}
1000}
1001
1002func (self *_parser) parseContinueStatement() ast.Statement {
1003 idx := self.expect(token.CONTINUE)

Callers 1

parseStatementMethod · 0.95

Calls 9

expectMethod · 0.95
nextMethod · 0.95
tokenToBindingIdMethod · 0.95
parseIdentifierMethod · 0.95
errorMethod · 0.95
semicolonMethod · 0.95
nextStatementMethod · 0.95
hasLabelMethod · 0.80
Idx1Method · 0.65

Tested by

no test coverage detected