mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
fix: panic on BadStatement (#495)
Add BadStatement case to walk.go to fix panic if there's bad code.
This commit is contained in:
parent
fbcfda961e
commit
f987875222
|
@ -38,6 +38,7 @@ func Walk(v Visitor, n Node) {
|
||||||
Walk(v, n.Right)
|
Walk(v, n.Right)
|
||||||
}
|
}
|
||||||
case *BadExpression:
|
case *BadExpression:
|
||||||
|
case *BadStatement:
|
||||||
case *BinaryExpression:
|
case *BinaryExpression:
|
||||||
if n != nil {
|
if n != nil {
|
||||||
Walk(v, n.Left)
|
Walk(v, n.Left)
|
||||||
|
|
|
@ -136,3 +136,22 @@ func Test_issue261(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBadStatement(t *testing.T) {
|
||||||
|
source := `
|
||||||
|
var abc;
|
||||||
|
break; do {
|
||||||
|
} while(true);
|
||||||
|
`
|
||||||
|
program, err := parser.ParseFile(nil, "", source, 0)
|
||||||
|
require.ErrorContains(t, err, "Illegal break statement")
|
||||||
|
|
||||||
|
w := &walker{
|
||||||
|
source: source,
|
||||||
|
seen: make(map[ast.Node]struct{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NotPanics(t, func() {
|
||||||
|
ast.Walk(w, program)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user