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.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.tomldiffbeforeafterboth1[package]2name = "jrsonnet-stdlib"3description = "Jsonnet standard library implementation for jrsonnet"4keywords = ["jsonnet", "stdlib"]5categories = ["template-engine"]6authors.workspace = true7edition.workspace = true8license.workspace = true9repository.workspace = true10version.workspace = true1112[lints]13workspace = true1415[features]16# Add order preservation flag to some functions17exp-preserve-order = ["jrsonnet-evaluator/exp-preserve-order"]18# Bigint type19exp-bigint = ["dep:num-bigint", "jrsonnet-evaluator/exp-bigint"]2021exp-null-coaelse = ["jrsonnet-evaluator/exp-null-coaelse"]22# std.regexMatch and other helpers23exp-regex = ["dep:regex", "dep:lru", "dep:rustc-hash"]2425[dependencies]26jrsonnet-evaluator.workspace = true27jrsonnet-macros.workspace = true28jrsonnet-gcmodule.workspace = true2930# Used for std.parseJson/std.parseYaml31serde.workspace = true3233# std.md534md5.workspace = true35# std.sha136sha1.workspace = true37# std.sha256, std.sha51238sha2.workspace = true39# std.sha340sha3.workspace = true41# std.base6442base64.workspace = true43# std.parseJson44serde_json.workspace = true45# std.parseYaml46serde-saphyr.workspace = true4748hex.workspace = true49num-bigint = { workspace = true, optional = true }5051# regex52regex = { workspace = true, optional = true }53lru = { workspace = true, optional = true }54rustc-hash = { workspace = true, optional = true }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 = []