difftreelog
feat support legacy std.thisFile
in: master
5 files changed
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -140,6 +140,11 @@
#[error("sort error: {0}")]
Sort(#[from] SortError),
+ /// Thrown as error, as this is legacy feature, and error here
+ /// is acceptable for defeating object field cache
+ #[error("should not reach outside: std.thisFile")]
+ MagicThisFileUsed,
+
#[cfg(feature = "anyhow-error")]
#[error(transparent)]
Other(Rc<anyhow::Error>),
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth568 (Val::Obj(v), Val::Str(key)) => s.push(568 (Val::Obj(v), Val::Str(key)) => s.push(569 CallLocation::new(loc),569 CallLocation::new(loc),570 || format!("field <{}> access", key),570 || format!("field <{}> access", key),571 || {571 || match v.get(s.clone(), key.clone()) {572 if let Some(v) = v.get(s.clone(), key.clone())? {573 Ok(v)572 Ok(Some(v)) => Ok(v),574 } else {575 throw!(NoSuchField(key.clone()))573 Ok(None) => throw!(NoSuchField(key.clone())),576 }574 Err(e) if matches!(e.error(), MagicThisFileUsed) => {577 },575 Ok(Val::Str(loc.0.to_string_lossy().into()))576 }577 Err(e) => Err(e),578 },578 )?,579 )?,579 (Val::Obj(_), n) => throw!(ValueIndexMustBeTypeGot(580 (Val::Obj(_), n) => throw!(ValueIndexMustBeTypeGot(580 ValType::Obj,581 ValType::Obj,674 .with(|b| b.get(name).copied())675 .with(|b| b.get(name).copied())675 .ok_or_else(|| IntrinsicNotFound(name.clone()))?,676 .ok_or_else(|| IntrinsicNotFound(name.clone()))?,676 )),677 )),678 IntrinsicThisFile => return Err(MagicThisFileUsed.into()),677 AssertExpr(assert, returned) => {679 AssertExpr(assert, returned) => {678 evaluate_assert(s.clone(), ctx.clone(), assert)?;680 evaluate_assert(s.clone(), ctx.clone(), assert)?;679 evaluate(s, ctx, returned)?681 evaluate(s, ctx, returned)?crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -296,6 +296,8 @@
Index(LocExpr, LocExpr),
/// function(x) x
Function(ParamsDesc, LocExpr),
+ /// std.thisFile
+ IntrinsicThisFile,
/// std.primitiveEquals
Intrinsic(IStr),
/// if true == false then 1 else 2
crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -210,6 +210,7 @@
pub rule expr_basic(s: &ParserSettings) -> Expr
= literal(s)
+ / quiet!{"$intrinsicThisFile" {Expr::IntrinsicThisFile}}
/ quiet!{"$intrinsic(" name:$(id()) ")" {Expr::Intrinsic(name.into())}}
/ string_expr(s) / number_expr(s)
crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/std.jsonnet
+++ b/crates/jrsonnet-stdlib/src/std.jsonnet
@@ -2,6 +2,9 @@
local std = self,
local id = std.id,
+ # Magic legacy field
+ thisFile:: $intrinsicThisFile,
+
# Those functions aren't normally located in stdlib
length:: $intrinsic(length),
type:: $intrinsic(type),