difftreelog
feat wire jrsonnet-web for experimental features
in: master
11 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2695,6 +2695,7 @@
"jrsonnet-stdlib",
"jrsonnet-types",
"js-sys",
+ "num-bigint",
"rustc-hash 2.1.2",
"url",
"wasm-bindgen",
bindings/jrsonnet-web/Cargo.tomldiffbeforeafterboth--- a/bindings/jrsonnet-web/Cargo.toml
+++ b/bindings/jrsonnet-web/Cargo.toml
@@ -9,6 +9,19 @@
repository.workspace = true
version.workspace = true
+[features]
+experimental = ["exp-preserve-order", "exp-bigint"]
+exp-preserve-order = [
+ "jrsonnet-evaluator/exp-preserve-order",
+ "jrsonnet-stdlib/exp-preserve-order",
+]
+exp-bigint = [
+ "dep:num-bigint",
+ "jrsonnet-evaluator/exp-bigint",
+ "jrsonnet-stdlib/exp-bigint",
+ "jrsonnet-types/exp-bigint",
+]
+
[dependencies]
console_error_panic_hook.workspace = true
getrandom = { workspace = true, features = ["wasm_js"] }
@@ -19,6 +32,7 @@
jrsonnet-stdlib.workspace = true
jrsonnet-types.workspace = true
js-sys.workspace = true
+num-bigint = { workspace = true, optional = true }
rustc-hash.workspace = true
url.workspace = true
wasm-bindgen.workspace = true
bindings/jrsonnet-web/src/lib.rsdiffbeforeafterboth--- a/bindings/jrsonnet-web/src/lib.rs
+++ b/bindings/jrsonnet-web/src/lib.rs
@@ -31,6 +31,7 @@
Arr,
Obj,
Func,
+ BigInt,
}
thread_local! {
@@ -132,6 +133,8 @@
ValType::Arr => Self::Arr,
ValType::Obj => Self::Obj,
ValType::Func => Self::Func,
+ #[cfg(feature = "exp-bigint")]
+ ValType::BigInt => Self::BigInt,
}
}
}
@@ -182,6 +185,26 @@
pub fn string(s: String) -> Self {
Self::new(Val::string(s))
}
+ pub fn bigint(value: js_sys::BigInt) -> Result<Self, JsError> {
+ #[cfg(feature = "exp-bigint")]
+ {
+ let s: String = value
+ .to_string(10)
+ .map_err(|_| JsError::new("invalid bigint"))?
+ .into();
+ let bi = s
+ .parse::<num_bigint::BigInt>()
+ .map_err(|e| JsError::new(&format!("failed to parse bigint: {e}")))?;
+ Ok(Self::new(Val::BigInt(Box::new(bi))))
+ }
+ #[cfg(not(feature = "exp-bigint"))]
+ {
+ let _ = value;
+ Err(JsError::new(
+ "bigint support is not enabled in this build (exp-bigint feature)",
+ ))
+ }
+ }
pub fn arr(items: Vec<WasmVal>) -> Self {
Self::new(Val::arr(
items.into_iter().map(|v| v.val).collect::<Vec<_>>(),
@@ -212,6 +235,24 @@
pub fn as_num(&self) -> Option<f64> {
self.val.as_num()
}
+ #[wasm_bindgen(js_name = asBigint)]
+ pub fn as_bigint(&self) -> Result<Option<js_sys::BigInt>, JsError> {
+ #[cfg(feature = "exp-bigint")]
+ {
+ let Some(bi) = self.val.as_bigint() else {
+ return Ok(None);
+ };
+ let big = js_sys::BigInt::new(&JsValue::from_str(&bi.to_string()))
+ .map_err(|e| JsError::new(&format!("{e:?}")))?;
+ Ok(Some(big))
+ }
+ #[cfg(not(feature = "exp-bigint"))]
+ {
+ Err(JsError::new(
+ "bigint support is not enabled in this build (exp-bigint feature)",
+ ))
+ }
+ }
#[wasm_bindgen(js_name = asString)]
pub fn as_string(&self) -> Option<String> {
self.val.as_str().map(|s| s.to_string())
@@ -259,7 +300,11 @@
#[wasm_bindgen(js_name = manifestJson)]
pub fn manifest_json(&self, indent: u32) -> Result<String, JsValue> {
- self.manifest_with(JsonFormat::cli(indent as usize))
+ self.manifest_with(JsonFormat::cli(
+ indent as usize,
+ #[cfg(feature = "exp-preserve-order")]
+ false,
+ ))
}
#[wasm_bindgen(js_name = manifestToString)]
pub fn manifest_to_string(&self) -> Result<String, JsValue> {
@@ -271,7 +316,12 @@
}
#[wasm_bindgen(js_name = manifestYaml)]
pub fn manifest_yaml(&self, indent: u32, quote_keys: bool) -> Result<String, JsValue> {
- self.manifest_with(YamlFormat::std_to_yaml(indent != 0, quote_keys))
+ self.manifest_with(YamlFormat::std_to_yaml(
+ indent != 0,
+ quote_keys,
+ #[cfg(feature = "exp-preserve-order")]
+ false,
+ ))
}
#[wasm_bindgen(js_name = manifestYamlStream)]
pub fn manifest_yaml_stream(
@@ -281,7 +331,12 @@
c_document_end: bool,
) -> Result<String, JsValue> {
self.manifest_with(YamlStreamFormat::std_yaml_stream(
- YamlFormat::std_to_yaml(indent != 0, quote_keys),
+ YamlFormat::std_to_yaml(
+ indent != 0,
+ quote_keys,
+ #[cfg(feature = "exp-preserve-order")]
+ false,
+ ),
c_document_end,
))
}
@@ -291,11 +346,18 @@
}
#[wasm_bindgen(js_name = manifestToml)]
pub fn manifest_toml(&self, indent: u32) -> Result<String, JsValue> {
- self.manifest_with(TomlFormat::std_to_toml(" ".repeat(indent as usize)))
+ self.manifest_with(TomlFormat::std_to_toml(
+ " ".repeat(indent as usize),
+ #[cfg(feature = "exp-preserve-order")]
+ false,
+ ))
}
#[wasm_bindgen(js_name = manifestIni)]
pub fn manifest_ini(&self) -> Result<String, JsValue> {
- self.manifest_with(IniFormat::std())
+ self.manifest_with(IniFormat::std(
+ #[cfg(feature = "exp-preserve-order")]
+ false,
+ ))
}
}
@@ -340,7 +402,10 @@
impl WasmObjValue {
pub fn keys(&self) -> Vec<String> {
self.obj
- .fields()
+ .fields(
+ #[cfg(feature = "exp-preserve-order")]
+ false,
+ )
.into_iter()
.map(|s| s.to_string())
.collect()
crates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-cli/Cargo.toml
+++ b/crates/jrsonnet-cli/Cargo.toml
@@ -13,6 +13,12 @@
workspace = true
[features]
+experimental = [
+ "exp-preserve-order",
+ "exp-bigint",
+ "exp-null-coaelse",
+ "exp-regex",
+]
exp-preserve-order = [
"jrsonnet-evaluator/exp-preserve-order",
"jrsonnet-stdlib/exp-preserve-order",
crates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth1[package]2name = "jrsonnet-evaluator"3description = "Rust implementation of the jsonnet language interpreter"4keywords = ["jsonnet", "interpreter", "config"]5categories = ["compilers", "template-engine", "config"]6readme = "README.adoc"7authors.workspace = true8edition.workspace = true9license.workspace = true10repository.workspace = true11version.workspace = true1213build = "build.rs"1415[lints]16workspace = true1718[features]19default = ["explaining-traces", "ir-parser", "wasm-bindgen"]20# Rustc-like trace visualization21explaining-traces = ["hi-doc"]22# Allows library authors to throw custom errors23anyhow-error = ["anyhow"]24# Use hand-written recursive descent parser25ir-parser = ["dep:jrsonnet-ir-parser"]26# Use PEG parser27peg-parser = ["dep:jrsonnet-peg-parser"]2829experimental = [30 "exp-preserve-order",31 "exp-destruct",32 "exp-object-iteration",33 "exp-bigint",34 "exp-null-coaelse",35]36# Allows to preserve field order in objects37exp-preserve-order = []38# Implements field destructuring39exp-destruct = [40 "jrsonnet-peg-parser?/exp-destruct",41 "jrsonnet-ir-parser?/exp-destruct",42]43# Iteration over objects yields [key, value] elements44exp-object-iteration = []45# Bigint type46exp-bigint = ["num-bigint", "jrsonnet-types/exp-bigint"]47# obj?.field, obj?.['field']48exp-null-coaelse = [49 "jrsonnet-peg-parser?/exp-null-coaelse",50 "jrsonnet-ir-parser?/exp-null-coaelse",51]52wasm-bindgen = ["dep:wasm-bindgen"]5354[dependencies]55jrsonnet-interner.workspace = true56jrsonnet-ir.workspace = true57jrsonnet-peg-parser = { workspace = true, optional = true }58jrsonnet-ir-parser = { workspace = true, optional = true }59jrsonnet-types.workspace = true60jrsonnet-macros.workspace = true61jrsonnet-gcmodule.workspace = true6263pathdiff.workspace = true64static_assertions.workspace = true6566rustc-hash.workspace = true6768thiserror.workspace = true69# Friendly errors70strsim.workspace = true7172serde.workspace = true7374anyhow = { workspace = true, optional = true }75# Better explaining traces76hi-doc = { workspace = true, optional = true }77# Bigint78num-bigint = { workspace = true, features = ["serde"], optional = true }7980stacker.workspace = true81educe = { workspace = true, features = [82 "Clone",83 "Debug",84 "Eq",85 "Hash",86 "PartialEq",87] }88smallvec.workspace = true89drop_bomb.workspace = true90wasm-bindgen = { workspace = true, optional = true }9192[build-dependencies]93rustversion.workspace = true9495[dev-dependencies]96insta.workspace = true97strip-ansi-escapes.workspace = truecrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -42,7 +42,9 @@
use jrsonnet_gcmodule::{Cc, Trace, cc_dyn};
pub use jrsonnet_interner::{IBytes, IStr};
use jrsonnet_ir::Expr;
-pub use jrsonnet_ir::{NumValue, Source, SourcePath, SourceUrl, SourceVirtual, Span};
+pub use jrsonnet_ir::{
+ NumValue, Source, SourceDefaultIgnoreJpath, SourcePath, SourceUrl, SourceVirtual, Span,
+};
#[doc(hidden)]
pub use jrsonnet_macros;
crates/jrsonnet-ir-parser/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-ir-parser/Cargo.toml
+++ b/crates/jrsonnet-ir-parser/Cargo.toml
@@ -10,6 +10,8 @@
version.workspace = true
[features]
+default = []
+experimental = ["exp-null-coaelse", "exp-destruct"]
exp-null-coaelse = ["jrsonnet-ir/exp-null-coaelse"]
exp-destruct = ["jrsonnet-ir/exp-destruct"]
crates/jrsonnet-ir/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-ir/Cargo.toml
+++ b/crates/jrsonnet-ir/Cargo.toml
@@ -12,6 +12,7 @@
[features]
default = []
+experimental = ["exp-destruct", "exp-null-coaelse"]
exp-destruct = []
exp-null-coaelse = []
crates/jrsonnet-peg-parser/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-peg-parser/Cargo.toml
+++ b/crates/jrsonnet-peg-parser/Cargo.toml
@@ -22,5 +22,6 @@
[features]
default = []
+experimental = ["exp-destruct", "exp-null-coaelse"]
exp-destruct = ["jrsonnet-ir/exp-destruct"]
exp-null-coaelse = ["jrsonnet-ir/exp-null-coaelse"]
crates/jrsonnet-stdlib/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-stdlib/Cargo.toml
+++ b/crates/jrsonnet-stdlib/Cargo.toml
@@ -13,6 +13,12 @@
workspace = true
[features]
+experimental = [
+ "exp-preserve-order",
+ "exp-bigint",
+ "exp-null-coaelse",
+ "exp-regex",
+]
# Add order preservation flag to some functions
exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order"]
# Bigint type
crates/jrsonnet-types/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-types/Cargo.toml
+++ b/crates/jrsonnet-types/Cargo.toml
@@ -18,4 +18,5 @@
peg.workspace = true
[features]
+experimental = ["exp-bigint"]
exp-bigint = []