@@ -22,13 +22,10 @@ import (
22
22
// contain metadata such as column type and if a value is specifically a NULL value.
23
23
//
24
24
// Use it directly as an Option to expr.Compile()
25
- var ValueGetter = func () expr.Option {
26
- vPatcher := patcher {}
27
- return func (c * conf.Config ) {
28
- c .Visitors = append (c .Visitors , vPatcher )
29
- getValueFunc (c )
30
- }
31
- }()
25
+ var ValueGetter = expr .Option (func (c * conf.Config ) {
26
+ c .Visitors = append (c .Visitors , patcher {})
27
+ getValueFunc (c )
28
+ })
32
29
33
30
// A AnyValuer provides a generic function for a custom type to return standard go values.
34
31
// It allows for returning a `nil` value but does not provide any type checking at expression compile.
@@ -136,21 +133,17 @@ var supportedInterfaces = []reflect.Type{
136
133
type patcher struct {}
137
134
138
135
func (patcher ) Visit (node * ast.Node ) {
139
- id , ok := (* node ).(* ast.IdentifierNode )
140
- if ! ok {
141
- return
142
- }
143
-
144
- nodeType := id .Type ()
145
-
146
- for _ , t := range supportedInterfaces {
147
- if nodeType .Implements (t ) {
148
- callnode := & ast.CallNode {
149
- Callee : & ast.IdentifierNode {Value : "$patcher_value_getter" },
150
- Arguments : []ast.Node {id },
136
+ switch id := (* node ).(type ) {
137
+ case * ast.IdentifierNode , * ast.MemberNode :
138
+ nodeType := id .Type ()
139
+ for _ , t := range supportedInterfaces {
140
+ if nodeType .Implements (t ) {
141
+ ast .Patch (node , & ast.CallNode {
142
+ Callee : & ast.IdentifierNode {Value : "$patcher_value_getter" },
143
+ Arguments : []ast.Node {id },
144
+ })
145
+ return
151
146
}
152
-
153
- ast .Patch (node , callnode )
154
147
}
155
148
}
156
149
}
0 commit comments