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.tomldiffbeforeafterboth1[package]2name = "jrsonnet-cli"3description = "Reusable clap-based building blocks for jrsonnet command-line tools"4keywords = ["jsonnet", "cli", "clap"]5categories = ["command-line-interface"]6authors.workspace = true7edition.workspace = true8license.workspace = true9repository.workspace = true10version.workspace = true1112[lints]13workspace = true1415[features]16exp-preserve-order = [17 "jrsonnet-evaluator/exp-preserve-order",18 "jrsonnet-stdlib/exp-preserve-order",19]20exp-bigint = ["jrsonnet-evaluator/exp-bigint", "jrsonnet-stdlib/exp-bigint"]21exp-null-coaelse = [22 "jrsonnet-evaluator/exp-null-coaelse",23 "jrsonnet-stdlib/exp-null-coaelse",24]25exp-regex = ["jrsonnet-stdlib/exp-regex"]2627[dependencies]28jrsonnet-evaluator = { workspace = true, features = ["explaining-traces"] }29jrsonnet-ir.workspace = true30jrsonnet-stdlib.workspace = true31jrsonnet-gcmodule.workspace = true3233clap = { workspace = true, features = ["derive"] }1[package]2name = "jrsonnet-cli"3description = "Reusable clap-based building blocks for jrsonnet command-line tools"4keywords = ["jsonnet", "cli", "clap"]5categories = ["command-line-interface"]6authors.workspace = true7edition.workspace = true8license.workspace = true9repository.workspace = true10version.workspace = true1112[lints]13workspace = true1415[features]16experimental = [17 "exp-preserve-order",18 "exp-bigint",19 "exp-null-coaelse",20 "exp-regex",21]22exp-preserve-order = [23 "jrsonnet-evaluator/exp-preserve-order",24 "jrsonnet-stdlib/exp-preserve-order",25]26exp-bigint = ["jrsonnet-evaluator/exp-bigint", "jrsonnet-stdlib/exp-bigint"]27exp-null-coaelse = [28 "jrsonnet-evaluator/exp-null-coaelse",29 "jrsonnet-stdlib/exp-null-coaelse",30]31exp-regex = ["jrsonnet-stdlib/exp-regex"]3233[dependencies]34jrsonnet-evaluator = { workspace = true, features = ["explaining-traces"] }35jrsonnet-ir.workspace = true36jrsonnet-stdlib.workspace = true37jrsonnet-gcmodule.workspace = true3839clap = { workspace = true, features = ["derive"] }crates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -26,6 +26,13 @@
# Use PEG parser
peg-parser = ["dep:jrsonnet-peg-parser"]
+experimental = [
+ "exp-preserve-order",
+ "exp-destruct",
+ "exp-object-iteration",
+ "exp-bigint",
+ "exp-null-coaelse",
+]
# Allows to preserve field order in objects
exp-preserve-order = []
# Implements field destructuring
crates/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 = []