Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.3.4
github.com/charmbracelet/lipgloss v1.0.0
github.com/expr-lang/expr v1.16.9
github.com/expr-lang/expr v1.17.2
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4
github.com/jahvon/glamour v0.8.1-patch3
github.com/jahvon/open-golang v0.0.0-20240522004812-68511c3bc9ef
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI=
github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/expr-lang/expr v1.17.2 h1:o0A99O/Px+/DTjEnQiodAgOIK9PPxL8DtXhBRKC+Iso=
github.com/expr-lang/expr v1.17.2/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4 h1:ygs9POGDQpQGLJPlq4+0LBUmMBNox1N4JSpw+OETcvI=
Expand Down
10 changes: 9 additions & 1 deletion internal/services/expr/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package expr
import (
"fmt"
"path/filepath"
"reflect"
"runtime"
"strconv"
"strings"

"github.com/expr-lang/expr"
"github.com/expr-lang/expr/vm"

"github.com/jahvon/flow/internal/context"
"github.com/jahvon/flow/types/executable"
Expand Down Expand Up @@ -36,7 +38,13 @@ func IsTruthy(ex string, env any) (bool, error) {
}

func Evaluate(ex string, env any) (interface{}, error) {
program, err := expr.Compile(ex, expr.Env(env))
var program *vm.Program
var err error
if env == nil || reflect.ValueOf(env).IsNil() {
program, err = expr.Compile(ex)
} else {
program, err = expr.Compile(ex, expr.Env(env))
}
if err != nil {
return nil, err
}
Expand Down
9 changes: 8 additions & 1 deletion internal/services/expr/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"reflect"
"strconv"
"strings"
"text/template"
Expand Down Expand Up @@ -63,7 +64,13 @@ func (t *Template) compileExpr(expression string) (*vm.Program, error) {
return node, nil
}

compiled, err := expr.Compile(expression, expr.Env(t.data))
var compiled *vm.Program
var err error
if t.data == nil || reflect.ValueOf(t.data).IsNil() {
compiled, err = expr.Compile(expression)
} else {
compiled, err = expr.Compile(expression, expr.Env(t.data))
}
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/templates/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package templates

import "runtime"

type expressionData map[string]interface{}
type expressionData = map[string]interface{}

func newExpressionData(
ws, wsPath, flowfileName, flowfileDir, flowfilePath, templatePath string,
Expand Down
Loading