File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ use wasm_bindgen::prelude::*;
3131pub fn transform ( config_val : JsValue ) -> Result < JsValue , JsValue > {
3232 let config: Config = from_value ( config_val) . map_err ( JsValue :: from) ?;
3333 let code = unsafe { std:: str:: from_utf8_unchecked ( & config. code ) } ;
34- let res = compile ( code, & config) . unwrap ( ) ;
34+ let res = compile ( code, & config) ? ;
3535 let serializer = Serializer :: new ( ) . serialize_maps_as_objects ( true ) ;
3636 res. serialize ( & serializer) . map_err ( JsValue :: from)
3737}
@@ -195,6 +195,7 @@ impl<'i> From<parcel_sourcemap::SourceMapError> for CompileError<'i> {
195195 }
196196}
197197
198+ #[ cfg( not( target_arch = "wasm32" ) ) ]
198199impl < ' i > From < CompileError < ' i > > for napi:: Error {
199200 fn from ( e : CompileError ) -> napi:: Error {
200201 match e {
@@ -204,6 +205,16 @@ impl<'i> From<CompileError<'i>> for napi::Error {
204205 }
205206}
206207
208+ #[ cfg( target_arch = "wasm32" ) ]
209+ impl < ' i > From < CompileError < ' i > > for wasm_bindgen:: JsValue {
210+ fn from ( e : CompileError ) -> wasm_bindgen:: JsValue {
211+ match e {
212+ CompileError :: SourceMapError ( e) => e. into ( ) ,
213+ _ => js_sys:: Error :: new ( & e. reason ( ) ) . into ( )
214+ }
215+ }
216+ }
217+
207218#[ cfg( test) ]
208219mod tests {
209220 use super :: * ;
You can’t perform that action at this time.
0 commit comments