Skip to content

Commit dc20a3f

Browse files
chore: Bump github.com/expr-lang/expr from 1.16.9 to 1.17.0 (#221)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jahvon Dockery <[email protected]>
1 parent 5421f12 commit dc20a3f

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/charmbracelet/bubbles v0.20.0
99
github.com/charmbracelet/bubbletea v1.3.4
1010
github.com/charmbracelet/lipgloss v1.0.0
11-
github.com/expr-lang/expr v1.16.9
11+
github.com/expr-lang/expr v1.17.2
1212
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4
1313
github.com/jahvon/glamour v0.8.1-patch3
1414
github.com/jahvon/open-golang v0.0.0-20240522004812-68511c3bc9ef

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
5656
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
5757
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
5858
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
59-
github.com/expr-lang/expr v1.16.9 h1:WUAzmR0JNI9JCiF0/ewwHB1gmcGw5wW7nWt8gc6PpCI=
60-
github.com/expr-lang/expr v1.16.9/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
59+
github.com/expr-lang/expr v1.17.2 h1:o0A99O/Px+/DTjEnQiodAgOIK9PPxL8DtXhBRKC+Iso=
60+
github.com/expr-lang/expr v1.17.2/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
6161
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
6262
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
6363
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4 h1:ygs9POGDQpQGLJPlq4+0LBUmMBNox1N4JSpw+OETcvI=

internal/services/expr/expr.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package expr
33
import (
44
"fmt"
55
"path/filepath"
6+
"reflect"
67
"runtime"
78
"strconv"
89
"strings"
910

1011
"github.com/expr-lang/expr"
12+
"github.com/expr-lang/expr/vm"
1113

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

3840
func Evaluate(ex string, env any) (interface{}, error) {
39-
program, err := expr.Compile(ex, expr.Env(env))
41+
var program *vm.Program
42+
var err error
43+
if env == nil || reflect.ValueOf(env).IsNil() {
44+
program, err = expr.Compile(ex)
45+
} else {
46+
program, err = expr.Compile(ex, expr.Env(env))
47+
}
4048
if err != nil {
4149
return nil, err
4250
}

internal/services/expr/template.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7+
"reflect"
78
"strconv"
89
"strings"
910
"text/template"
@@ -63,7 +64,13 @@ func (t *Template) compileExpr(expression string) (*vm.Program, error) {
6364
return node, nil
6465
}
6566

66-
compiled, err := expr.Compile(expression, expr.Env(t.data))
67+
var compiled *vm.Program
68+
var err error
69+
if t.data == nil || reflect.ValueOf(t.data).IsNil() {
70+
compiled, err = expr.Compile(expression)
71+
} else {
72+
compiled, err = expr.Compile(expression, expr.Env(t.data))
73+
}
6774
if err != nil {
6875
return nil, err
6976
}

internal/templates/expression.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package templates
22

33
import "runtime"
44

5-
type expressionData map[string]interface{}
5+
type expressionData = map[string]interface{}
66

77
func newExpressionData(
88
ws, wsPath, flowfileName, flowfileDir, flowfilePath, templatePath string,

0 commit comments

Comments
 (0)