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.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -568,12 +568,13 @@
(Val::Obj(v), Val::Str(key)) => s.push(
CallLocation::new(loc),
|| format!("field <{}> access", key),
- || {
- if let Some(v) = v.get(s.clone(), key.clone())? {
- Ok(v)
- } else {
- throw!(NoSuchField(key.clone()))
+ || match v.get(s.clone(), key.clone()) {
+ Ok(Some(v)) => Ok(v),
+ Ok(None) => throw!(NoSuchField(key.clone())),
+ Err(e) if matches!(e.error(), MagicThisFileUsed) => {
+ Ok(Val::Str(loc.0.to_string_lossy().into()))
}
+ Err(e) => Err(e),
},
)?,
(Val::Obj(_), n) => throw!(ValueIndexMustBeTypeGot(
@@ -674,6 +675,7 @@
.with(|b| b.get(name).copied())
.ok_or_else(|| IntrinsicNotFound(name.clone()))?,
)),
+ IntrinsicThisFile => return Err(MagicThisFileUsed.into()),
AssertExpr(assert, returned) => {
evaluate_assert(s.clone(), ctx.clone(), assert)?;
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.jsonnetdiffbeforeafterboth2 local std = self,2 local std = self,3 local id = std.id,3 local id = std.id,445 # Magic legacy field6 thisFile:: $intrinsicThisFile,75 # Those functions aren't normally located in stdlib8 # Those functions aren't normally located in stdlib6 length:: $intrinsic(length),9 length:: $intrinsic(length),7 type:: $intrinsic(type),10 type:: $intrinsic(type),