From 09336b18552d7942a9bc92ab834979ec19c4174a Mon Sep 17 00:00:00 2001 From: Лач Date: Thu, 25 Jun 2020 11:27:17 +0000 Subject: [PATCH] fix(evaluator): use context with globals for `into_json` --- --- a/crates/jsonnet-evaluator/src/val.rs +++ b/crates/jsonnet-evaluator/src/val.rs @@ -174,24 +174,28 @@ }) } pub fn into_json(self, padding: usize) -> Result { - let ctx = Context::new().with_var("__tmp__to_json__".to_owned(), self)?; - if let Val::Str(result) = evaluate( - ctx, - &el!(Expr::Apply( - el!(Expr::Index( - el!(Expr::Var("std".to_owned())), - el!(Expr::Str("manifestJsonEx".to_owned())) + with_state(|s| { + let ctx = s + .create_default_context()? + .with_var("__tmp__to_json__".to_owned(), self)?; + if let Val::Str(result) = evaluate( + &ctx, + &el!(Expr::Apply( + el!(Expr::Index( + el!(Expr::Var("std".to_owned())), + el!(Expr::Str("manifestJsonEx".to_owned())) + )), + ArgsDesc(vec![ + Arg(None, el!(Expr::Var("__tmp__to_json__".to_owned()))), + Arg(None, el!(Expr::Str(" ".repeat(padding)))) + ]), + false )), - ArgsDesc(vec![ - Arg(None, el!(Expr::Var("__tmp__to_json__".to_owned()))), - Arg(None, el!(Expr::Str(" ".repeat(padding)))) - ]), - false - )), - )? { - Ok(result) - } else { - unreachable!() - } + )? { + Ok(result) + } else { + unreachable!() + } + }) } } -- gitstuff