From 9dbec29e0863ec04747f6a36d5c09869bfe9e415 Mon Sep 17 00:00:00 2001 From: 6d7a Date: Tue, 14 May 2024 18:18:38 +0200 Subject: [PATCH] fix: WASM compile function --- rasn-compiler/src/lib.rs | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/rasn-compiler/src/lib.rs b/rasn-compiler/src/lib.rs index 0b2890b..84f4576 100644 --- a/rasn-compiler/src/lib.rs +++ b/rasn-compiler/src/lib.rs @@ -62,22 +62,28 @@ pub struct Generated { #[cfg(target_family = "wasm")] #[wasm_bindgen] -pub fn compile(asn1: &str) -> Result { - 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 { + if backend == "typescript" { + Compiler::::new() + .add_asn_literal(asn1) + .compile_to_string() + } else { + 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())) } /// The rasn compiler