go.ketch.com/lib/goja@v0.0.1/parser/scope.go (about) 1 package parser 2 3 import ( 4 "go.ketch.com/lib/goja/ast" 5 "go.ketch.com/lib/goja/unistring" 6 ) 7 8 type _scope struct { 9 outer *_scope 10 allowIn bool 11 allowLet bool 12 inIteration bool 13 inSwitch bool 14 inFunction bool 15 declarationList []*ast.VariableDeclaration 16 17 labels []unistring.String 18 } 19 20 func (self *_parser) openScope() { 21 self.scope = &_scope{ 22 outer: self.scope, 23 allowIn: true, 24 } 25 } 26 27 func (self *_parser) closeScope() { 28 self.scope = self.scope.outer 29 } 30 31 func (self *_scope) declare(declaration *ast.VariableDeclaration) { 32 self.declarationList = append(self.declarationList, declaration) 33 } 34 35 func (self *_scope) hasLabel(name unistring.String) bool { 36 for _, label := range self.labels { 37 if label == name { 38 return true 39 } 40 } 41 if self.outer != nil && !self.inFunction { 42 // Crossing a function boundary to look for a label is verboten 43 return self.outer.hasLabel(name) 44 } 45 return false 46 }