Skip to content

Commit

Permalink
fix: WASM compile function
Browse files Browse the repository at this point in the history
  • Loading branch information
6d7a committed May 14, 2024
1 parent 7ebd524 commit 9dbec29
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions rasn-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,28 @@ pub struct Generated {

#[cfg(target_family = "wasm")]
#[wasm_bindgen]
pub fn compile(asn1: &str) -> Result<Generated, JsValue> {
Compiler::new()
.add_asn_literal(asn1)
.compile_to_string()
.map(|result| Generated {
rust: result.generated,
warnings: result
.warnings
.into_iter()
.fold(String::new(), |mut acc, w| {
acc += &w.to_string();
acc += "\n";
acc
}),
})
.map_err(|e| JsValue::from(e.to_string()))
pub fn compile(asn1: &str, backend: &str) -> Result<Generated, JsValue> {
if backend == "typescript" {
Compiler::<crate::prelude::TypescriptBackend, _>::new()
.add_asn_literal(asn1)
.compile_to_string()
} else {
Compiler::<crate::prelude::RasnBackend, _>::new()
.add_asn_literal(asn1)
.compile_to_string()
}
.map(|result| Generated {
rust: result.generated,
warnings: result
.warnings
.into_iter()
.fold(String::new(), |mut acc, w| {
acc += &w.to_string();
acc += "\n";
acc
}),
})
.map_err(|e| JsValue::from(e.to_string()))
}

/// The rasn compiler
Expand Down

0 comments on commit 9dbec29

Please sign in to comment.