@@ -2,8 +2,8 @@ use std::{hash::Hash, sync::Arc};
22
33use napi_derive:: napi;
44use rspack_core:: rspack_sources:: {
5- BoxSource , CachedSource , ConcatSource , MapOptions , OriginalSource , RawBufferSource , RawSource ,
6- RawStringSource , ReplaceSource , Source , SourceExt , SourceMap , SourceMapSource ,
5+ BoxSource , CachedSource , ConcatSource , MapOptions , OriginalSource , RawBufferSource ,
6+ RawStringSource , ReplaceSource , Source , SourceExt , SourceMap , SourceMapSource , SourceValue ,
77 WithoutOriginalOptions ,
88} ;
99use rspack_napi:: napi:: bindgen_prelude:: * ;
@@ -66,20 +66,19 @@ impl TryFrom<&dyn Source> for JsSourceToJs {
6666 type Error = napi:: Error ;
6767
6868 fn try_from ( value : & dyn Source ) -> Result < Self > {
69- if let Some ( raw_buffer_source) = value. as_any ( ) . downcast_ref :: < RawBufferSource > ( ) {
70- let bytes = raw_buffer_source. buffer ( ) . to_vec ( ) ;
71- return Ok ( JsSourceToJs {
72- source : Either :: B ( Buffer :: from ( bytes) ) ,
69+ match value. source ( ) {
70+ SourceValue :: String ( string) => {
71+ let map: Option < String > = to_webpack_map ( value) ?;
72+ Ok ( JsSourceToJs {
73+ source : Either :: A ( string. into_owned ( ) ) ,
74+ map,
75+ } )
76+ }
77+ SourceValue :: Buffer ( bytes) => Ok ( JsSourceToJs {
78+ source : Either :: B ( Buffer :: from ( bytes. to_vec ( ) ) ) ,
7379 map : None ,
74- } ) ;
80+ } ) ,
7581 }
76-
77- let string = value. source ( ) ;
78- let map: Option < String > = to_webpack_map ( value) ?;
79- Ok ( JsSourceToJs {
80- source : Either :: A ( string. into_owned ( ) ) ,
81- map,
82- } )
8382 }
8483}
8584
0 commit comments