diff --git a/parser/parser.go b/parser/parser.go index 370a83d..d3563b0 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -814,6 +814,10 @@ func (p *parser) registerInfix(tokenType token.Type, fn infixParseFn) { } func (p *parser) confrimIfCondition(v ast.Expression) (returnData bool) { + if v == nil { + p.invalidIfCondition("missing condition in if statement") + return + } _, ok := v.(ast.Comparable) if !ok { p.invalidIfCondition(v.String()) diff --git a/parser/parser_test.go b/parser/parser_test.go index ec57e55..7fe220e 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -1114,6 +1114,14 @@ func Test_Break_IfCondtion(t *testing.T) { r.Error(err) } +func Test_Empty_IfCondtion(t *testing.T) { + r := require.New(t) + input := `<% if() { v } %>` + + _, err := Parse(input) + r.Error(err) +} + func Test_Continue_Function(t *testing.T) { r := require.New(t) input := `<% fn(x, y) { continue } %>`