From 3e1d3979f00fc96c667306f16dd183cb59e6bc05 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 06 May 2026 03:51:51 +0000 Subject: [PATCH] feat: wire jrsonnet-web for experimental features --- --- 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", --- 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 --- 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 { + #[cfg(feature = "exp-bigint")] + { + let s: String = value + .to_string(10) + .map_err(|_| JsError::new("invalid bigint"))? + .into(); + let bi = s + .parse::() + .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) -> Self { Self::new(Val::arr( items.into_iter().map(|v| v.val).collect::>(), @@ -212,6 +235,24 @@ pub fn as_num(&self) -> Option { self.val.as_num() } + #[wasm_bindgen(js_name = asBigint)] + pub fn as_bigint(&self) -> Result, 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 { 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 { - 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 { @@ -271,7 +316,12 @@ } #[wasm_bindgen(js_name = manifestYaml)] pub fn manifest_yaml(&self, indent: u32, quote_keys: bool) -> Result { - 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 { 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 { - 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 { - 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 { self.obj - .fields() + .fields( + #[cfg(feature = "exp-preserve-order")] + false, + ) .into_iter() .map(|s| s.to_string()) .collect() --- 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", --- 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 --- 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; --- 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"] --- 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 = [] --- 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"] --- 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 --- 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 = [] -- gitstuff