Add coalescing operator
This commit is contained in:
10
salix.go
10
salix.go
@@ -218,6 +218,8 @@ func (t *Template) getValue(node ast.Node, local map[string]any) (any, error) {
|
||||
return t.execMethodCall(node, local)
|
||||
case ast.Ternary:
|
||||
return t.evalTernary(node, local)
|
||||
case ast.VariableOr:
|
||||
return t.evalVariableOr(node, local)
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
@@ -448,6 +450,14 @@ func (t *Template) evalTernary(tr ast.Ternary, local map[string]any) (any, error
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Template) evalVariableOr(vo ast.VariableOr, local map[string]any) (any, error) {
|
||||
val, err := t.getVar(vo.Variable, local)
|
||||
if err != nil {
|
||||
return t.getValue(vo.Or, local)
|
||||
}
|
||||
return val.Interface(), nil
|
||||
}
|
||||
|
||||
func (t *Template) posError(n ast.Node, format string, v ...any) error {
|
||||
return ast.PosError(n, t.name, format, v...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user