1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-03-05 15:16:07 +02:00

Added support for params as segments in member expression path

This commit is contained in:
Tim Voronov 2019-09-07 01:57:33 -04:00
parent 0a2fd478cd
commit 04eea23e52
5 changed files with 411 additions and 366 deletions

View File

@ -95,4 +95,22 @@ func TestParam(t *testing.T) {
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"`)
})
}

View File

@ -889,7 +889,7 @@ func (v *visitor) doVisitObjectLiteral(ctx *fql.ObjectLiteralContext, scope *sco
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
identifier := ctx.Identifier()
@ -902,6 +902,14 @@ func (v *visitor) doVisitPropertyNameContext(ctx *fql.PropertyNameContext, _ *sc
if stringLiteral != nil {
runes := []rune(stringLiteral.GetText())
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
}
}

View File

@ -195,6 +195,7 @@ computedPropertyName
propertyName
: Identifier
| stringLiteral
| param
;
expressionGroup

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff