1
0
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:
amaicode 2023-05-20 08:35:41 -04:00 committed by GitHub
parent fbcfda961e
commit f987875222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -38,6 +38,7 @@ func Walk(v Visitor, n Node) {
Walk(v, n.Right)
}
case *BadExpression:
case *BadStatement:
case *BinaryExpression:
if n != nil {
Walk(v, n.Left)

View File

@ -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)
})
}