Skip to content

Commit 397ff2f

Browse files
committed
Accept owned instance from minify
1 parent 6801924 commit 397ff2f

File tree

1 file changed

+6
-9
lines changed
  • turbopack/crates/turbopack-ecmascript/src

1 file changed

+6
-9
lines changed

turbopack/crates/turbopack-ecmascript/src/minify.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ use turbopack_core::{
3131
use crate::parse::generate_js_source_map;
3232

3333
#[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> {
3535
let source_maps = source_maps
3636
.then(|| code.generate_source_map_ref())
3737
.transpose()?;
3838

39+
let source_code = code.into_source_code().into_bytes()?.into_owned();
40+
let source_code = String::from_utf8(source_code)?;
41+
3942
let cm = Arc::new(SwcSourceMap::new(FilePathMapping::empty()));
4043
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);
4545

4646
let lexer = Lexer::new(
4747
Syntax::default(),
@@ -57,10 +57,7 @@ pub fn minify(code: &Code, source_maps: bool, mangle: Option<MangleType>) -> Res
5757
Ok(program) => program,
5858
Err(err) => {
5959
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)
6461
}
6562
};
6663
let comments = SingleThreadedComments::default();

0 commit comments

Comments
 (0)