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

Method parseForOrForInStatement

parser/statement.go:656–769  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

654}
655
656func (self *_parser) parseForOrForInStatement() ast.Statement {
657 idx := self.expect(token.FOR)
658 self.expect(token.LEFT_PARENTHESIS)
659
660 var initializer ast.ForLoopInitializer
661
662 forIn := false
663 forOf := false
664 var into ast.ForInto
665 if self.token != token.SEMICOLON {
666
667 allowIn := self.scope.allowIn
668 self.scope.allowIn = false
669 tok := self.token
670 if tok == token.LET {
671 switch self.peek() {
672 case token.IDENTIFIER, token.LEFT_BRACKET, token.LEFT_BRACE:
673 default:
674 tok = token.IDENTIFIER
675 }
676 }
677 if tok == token.VAR || tok == token.LET || tok == token.CONST {
678 idx := self.idx
679 self.next()
680 var list []*ast.Binding
681 if tok == token.VAR {
682 list = self.parseVarDeclarationList(idx)
683 } else {
684 list = self.parseVariableDeclarationList()
685 }
686 if len(list) == 1 {
687 if self.token == token.IN {
688 self.next() // in
689 forIn = true
690 } else if self.token == token.IDENTIFIER && self.literal == "of" {
691 self.next()
692 forOf = true
693 }
694 }
695 if forIn || forOf {
696 if list[0].Initializer != nil {
697 self.error(list[0].Initializer.Idx0(), "for-in loop variable declaration may not have an initializer")
698 }
699 if tok == token.VAR {
700 into = &ast.ForIntoVar{
701 Binding: list[0],
702 }
703 } else {
704 into = &ast.ForDeclaration{
705 Idx: idx,
706 IsConst: tok == token.CONST,
707 Target: list[0].Target,
708 }
709 }
710 } else {
711 self.ensurePatternInit(list)
712 if tok == token.VAR {
713 initializer = &ast.ForLoopInitializerVarDeclList{

Callers 1

parseStatementMethod · 0.95

Calls 15

expectMethod · 0.95
peekMethod · 0.95
nextMethod · 0.95
errorMethod · 0.95
ensurePatternInitMethod · 0.95
parseExpressionMethod · 0.95
nextStatementMethod · 0.95
parseForInMethod · 0.95

Tested by

no test coverage detected