git.delta.rocks / jrsonnet / refs/commits / 3e1d3979f00f

difftreelog

feat wire jrsonnet-web for experimental features

mqyzspnqYaroslav Bolyukin2026-05-06parent: #7324ad9.patch.diff
in: master

11 files changed

modifiedCargo.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",
modifiedbindings/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
modifiedbindings/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()
modifiedcrates/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",
modifiedcrates/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
modifiedcrates/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;
 
modifiedcrates/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"]
 
modifiedcrates/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 = []
 
modifiedcrates/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"]
modifiedcrates/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
modifiedcrates/jrsonnet-types/Cargo.tomldiffbeforeafterboth
18peg.workspace = true18peg.workspace = true
1919
20[features]20[features]
21experimental = ["exp-bigint"]
21exp-bigint = []22exp-bigint = []
2223