Treat $this param as a special case

This commit is contained in:
Tobie Morgan Hitchcock 2022-04-06 00:11:33 +01:00
parent 892fc99527
commit cf20cd4396

View file

@ -37,7 +37,21 @@ impl Param {
// Find a base variable by name
match self.name.parts.first() {
// The first part will be a field
Some(Part::Field(v)) => match ctx.value::<Value>(&v.name) {
Some(Part::Field(v)) => match &v.name[..] {
"this" => match doc {
// The base document exists
Some(v) => {
// Get the path parts
let pth: &[Part] = &self.name;
// Process the paramater value
let res = v.compute(ctx, opt, txn, doc).await?;
// Return the desired field
res.get(ctx, opt, txn, pth.next()).await
}
// The base document does not exist
None => Ok(Value::None),
},
_ => match ctx.value::<Value>(&v.name) {
// The base variable exists
Some(v) => {
// Get the path parts
@ -50,6 +64,7 @@ impl Param {
// The base variable does not exist
None => Ok(Value::None),
},
},
_ => unreachable!(),
}
}