github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/compiler/analysis/break.go (about) 1 package analysis 2 3 import ( 4 "go/ast" 5 "go/token" 6 ) 7 8 func HasBreak(n ast.Node) bool { 9 v := hasBreakVisitor{} 10 ast.Walk(&v, n) 11 return v.hasBreak 12 } 13 14 type hasBreakVisitor struct { 15 hasBreak bool 16 } 17 18 func (v *hasBreakVisitor) Visit(node ast.Node) (w ast.Visitor) { 19 if v.hasBreak { 20 return nil 21 } 22 switch n := node.(type) { 23 case *ast.BranchStmt: 24 if n.Tok == token.BREAK && n.Label == nil { 25 v.hasBreak = true 26 return nil 27 } 28 case *ast.ForStmt, *ast.RangeStmt, *ast.SwitchStmt, *ast.TypeSwitchStmt, *ast.SelectStmt, ast.Expr: 29 return nil 30 } 31 return v 32 }