mirror of
https://github.com/MontFerret/ferret.git
synced 2025-08-13 19:52:52 +02:00
Added support for params as segments in member expression path
This commit is contained in:
@@ -95,4 +95,22 @@ func TestParam(t *testing.T) {
|
|||||||
|
|
||||||
So(string(out), ShouldEqual, `"bar"`)
|
So(string(out), ShouldEqual, `"bar"`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("Should be possible to use in member expression as segments", t, func() {
|
||||||
|
prog := compiler.New().
|
||||||
|
MustCompile(`
|
||||||
|
LET doc = { foo: { bar: "baz" } }
|
||||||
|
|
||||||
|
RETURN doc.@attr.@subattr
|
||||||
|
`)
|
||||||
|
|
||||||
|
out := prog.MustRun(
|
||||||
|
context.Background(),
|
||||||
|
runtime.WithParam("attr", "foo"),
|
||||||
|
runtime.WithParam("subattr", "bar"),
|
||||||
|
)
|
||||||
|
|
||||||
|
So(string(out), ShouldEqual, `"baz"`)
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@@ -889,7 +889,7 @@ func (v *visitor) doVisitObjectLiteral(ctx *fql.ObjectLiteralContext, scope *sco
|
|||||||
return literals.NewObjectLiteralWith(props...), nil
|
return literals.NewObjectLiteralWith(props...), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *visitor) doVisitPropertyNameContext(ctx *fql.PropertyNameContext, _ *scope) (core.Expression, error) {
|
func (v *visitor) doVisitPropertyNameContext(ctx *fql.PropertyNameContext, scope *scope) (core.Expression, error) {
|
||||||
var name string
|
var name string
|
||||||
|
|
||||||
identifier := ctx.Identifier()
|
identifier := ctx.Identifier()
|
||||||
@@ -902,6 +902,14 @@ func (v *visitor) doVisitPropertyNameContext(ctx *fql.PropertyNameContext, _ *sc
|
|||||||
if stringLiteral != nil {
|
if stringLiteral != nil {
|
||||||
runes := []rune(stringLiteral.GetText())
|
runes := []rune(stringLiteral.GetText())
|
||||||
name = string(runes[1 : len(runes)-1])
|
name = string(runes[1 : len(runes)-1])
|
||||||
|
} else {
|
||||||
|
param, err := v.doVisitParamContext(ctx.Param().(*fql.ParamContext), scope)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return param, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -195,6 +195,7 @@ computedPropertyName
|
|||||||
propertyName
|
propertyName
|
||||||
: Identifier
|
: Identifier
|
||||||
| stringLiteral
|
| stringLiteral
|
||||||
|
| param
|
||||||
;
|
;
|
||||||
|
|
||||||
expressionGroup
|
expressionGroup
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user