Unverified Commit 949b8d8e authored by Donny/강동윤's avatar Donny/강동윤 Committed by GitHub

refactor(turbopack): Simplify `minify()` (#76139)

### What?

Simplify `minify()` of turbopack. `swc::Compiler` is not required for the minification, considering that we are not using the minification API of it.

### Why?

It has some tiny overheads, and it disturbs future refactoring for source maps.
parent ec1fefca
...@@ -2,7 +2,7 @@ use std::{io::Write, sync::Arc}; ...@@ -2,7 +2,7 @@ use std::{io::Write, sync::Arc};
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use swc_core::{ use swc_core::{
base::{try_with_handler, Compiler}, base::try_with_handler,
common::{ common::{
comments::{Comments, SingleThreadedComments}, comments::{Comments, SingleThreadedComments},
BytePos, FileName, FilePathMapping, LineCol, Mark, SourceMap as SwcSourceMap, GLOBALS, BytePos, FileName, FilePathMapping, LineCol, Mark, SourceMap as SwcSourceMap, GLOBALS,
...@@ -41,8 +41,7 @@ pub async fn minify( ...@@ -41,8 +41,7 @@ pub async fn minify(
let cm = Arc::new(SwcSourceMap::new(FilePathMapping::empty())); let cm = Arc::new(SwcSourceMap::new(FilePathMapping::empty()));
let (src, mut src_map_buf) = { let (src, mut src_map_buf) = {
let compiler = Arc::new(Compiler::new(cm.clone())); let fm = cm.new_source_file(
let fm = compiler.cm.new_source_file(
FileName::Custom(path.path.to_string()).into(), FileName::Custom(path.path.to_string()).into(),
code.source_code().to_str()?.into_owned(), code.source_code().to_str()?.into_owned(),
); );
...@@ -71,7 +70,6 @@ pub async fn minify( ...@@ -71,7 +70,6 @@ pub async fn minify(
let unresolved_mark = Mark::new(); let unresolved_mark = Mark::new();
let top_level_mark = Mark::new(); let top_level_mark = Mark::new();
Ok(compiler.run_transform(handler, false, || {
let program = program.apply(paren_remover(Some(&comments))); let program = program.apply(paren_remover(Some(&comments)));
let mut program = program.apply(swc_core::ecma::transforms::base::resolver( let mut program = program.apply(swc_core::ecma::transforms::base::resolver(
...@@ -109,10 +107,9 @@ pub async fn minify( ...@@ -109,10 +107,9 @@ pub async fn minify(
}, },
); );
program.apply(ecma::transforms::base::fixer::fixer(Some( Ok(program.apply(ecma::transforms::base::fixer::fixer(Some(
&comments as &dyn Comments, &comments as &dyn Comments,
))) ))))
}))
}) })
})?; })?;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment