scope.go 1005 B

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