Switch to using JSON for wasm.
Some checks failed
rust-build Build rust-build has failed
clippy Build clippy has failed
rustfmt Build rustfmt has succeeded
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-test Build rust-test has succeeded

serde_wasm_bindgen was silently dropping many attributes (I suspect it is triggered by serde flatten) so this switches to serializing to JSON for passing values from wasm to js.
This commit is contained in:
Tom Alexander 2024-01-27 16:13:17 -05:00
parent 64bb597908
commit 8406d37991
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 7 additions and 5 deletions

View File

@ -52,6 +52,7 @@ path = "src/lib.rs"
[dependencies]
futures = { version = "0.3.28", optional = true }
gloo-utils = "0.2.0"
nom = "7.1.1"
opentelemetry = { version = "0.20.0", optional = true, default-features = false, features = ["trace", "rt-tokio"] }
opentelemetry-otlp = { version = "0.13.0", optional = true }

View File

@ -1,3 +1,6 @@
use gloo_utils::format::JsValueSerdeExt;
use wasm_bindgen::JsValue;
use crate::parser::parse_with_settings;
use crate::settings::GlobalSettings;
use crate::wasm::ParseResult;
@ -8,17 +11,15 @@ pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
let rust_parsed = match parse_with_settings(org_contents, &GlobalSettings::default()) {
Ok(document) => document,
Err(err) => {
return serde_wasm_bindgen::to_value(&ParseResult::Error(format!("{:?}", err)))
.unwrap();
return JsValue::from_serde(&ParseResult::Error(format!("{:?}", err))).unwrap();
}
};
let to_wasm_context = ToWasmContext::new(org_contents);
let wasm_document = match rust_parsed.to_wasm(to_wasm_context) {
Ok(document) => document,
Err(err) => {
return serde_wasm_bindgen::to_value(&ParseResult::Error(format!("{:?}", err)))
.unwrap();
return JsValue::from_serde(&ParseResult::Error(format!("{:?}", err))).unwrap();
}
};
serde_wasm_bindgen::to_value(&ParseResult::Success(wasm_document)).unwrap()
JsValue::from_serde(&ParseResult::Success(wasm_document)).unwrap()
}