@@ -31,17 +31,17 @@ use turbopack_core::{
31
31
use crate :: parse:: generate_js_source_map;
32
32
33
33
#[ instrument( level = Level :: INFO , skip_all) ]
34
- pub fn minify ( code : & Code , source_maps : bool , mangle : Option < MangleType > ) -> Result < Code > {
34
+ pub fn minify ( code : Code , source_maps : bool , mangle : Option < MangleType > ) -> Result < Code > {
35
35
let source_maps = source_maps
36
36
. then ( || code. generate_source_map_ref ( ) )
37
37
. transpose ( ) ?;
38
38
39
+ let source_code = code. into_source_code ( ) . into_bytes ( ) ?. into_owned ( ) ;
40
+ let source_code = String :: from_utf8 ( source_code) ?;
41
+
39
42
let cm = Arc :: new ( SwcSourceMap :: new ( FilePathMapping :: empty ( ) ) ) ;
40
43
let ( src, mut src_map_buf) = {
41
- let fm = cm. new_source_file (
42
- FileName :: Anon . into ( ) ,
43
- code. source_code ( ) . to_str ( ) ?. into_owned ( ) ,
44
- ) ;
44
+ let fm = cm. new_source_file ( FileName :: Anon . into ( ) , source_code) ;
45
45
46
46
let lexer = Lexer :: new (
47
47
Syntax :: default ( ) ,
@@ -57,10 +57,7 @@ pub fn minify(code: &Code, source_maps: bool, mangle: Option<MangleType>) -> Res
57
57
Ok ( program) => program,
58
58
Err ( err) => {
59
59
err. into_diagnostic ( handler) . emit ( ) ;
60
- bail ! (
61
- "failed to parse source code\n {}" ,
62
- code. source_code( ) . to_str( ) ?
63
- )
60
+ bail ! ( "failed to parse source code\n {}" , fm. src)
64
61
}
65
62
} ;
66
63
let comments = SingleThreadedComments :: default ( ) ;
0 commit comments