@@ -30,20 +30,16 @@ use napi::bindgen_prelude::*;
3030use rustc_hash:: FxHashMap ;
3131use serde:: Deserialize ;
3232use swc_core:: {
33- base:: { config:: JsMinifyOptions , try_with_handler, BoolOrDataConfig , TransformOutput } ,
33+ base:: { config:: JsMinifyOptions , try_with_handler, TransformOutput } ,
3434 common:: { errors:: ColorConfig , sync:: Lrc , FileName , SourceFile , SourceMap , GLOBALS } ,
35- ecma:: minifier:: option:: {
36- terser:: { TerserCompressorOptions , TerserInlineOption } ,
37- MangleOptions ,
38- } ,
3935} ;
4036
4137use crate :: { get_compiler, util:: MapErr } ;
4238
4339pub struct MinifyTask {
4440 c : swc_core:: base:: Compiler ,
4541 code : MinifyTarget ,
46- opts : swc_core :: base :: config :: JsMinifyOptions ,
42+ opts : JsMinifyOptions ,
4743}
4844
4945#[ derive( Deserialize ) ]
@@ -104,43 +100,14 @@ impl Task for MinifyTask {
104100 }
105101}
106102
107- /// **NOTE** `inline: 3` breaks some codes.
108- ///
109- /// <https://github.com/vercel/next.js/pull/57904>
110- fn patch_opts ( opts : & mut JsMinifyOptions ) {
111- opts. compress = BoolOrDataConfig :: from_obj ( TerserCompressorOptions {
112- inline : Some ( TerserInlineOption :: Num ( 2 ) ) ,
113- global_defs : [ (
114- "process.env.__NEXT_PRIVATE_MINIMIZE_MACRO_FALSE" . into ( ) ,
115- false . into ( ) ,
116- ) ]
117- . iter ( )
118- . cloned ( )
119- . collect ( ) ,
120- ..Default :: default ( )
121- } ) ;
122-
123- if !opts. mangle . is_false ( ) {
124- let mut mangle = std:: mem:: take ( & mut opts. mangle ) ;
125- if mangle. is_true ( ) {
126- mangle = BoolOrDataConfig :: from_obj ( MangleOptions :: default ( ) ) ;
127- }
128- opts. mangle = mangle. map ( |mut mangle_opts| {
129- mangle_opts. reserved . push ( "AbortSignal" . into ( ) ) ;
130- mangle_opts
131- } ) ;
132- }
133- }
134-
135103#[ napi]
136104pub fn minify (
137105 input : Buffer ,
138106 opts : Buffer ,
139107 signal : Option < AbortSignal > ,
140108) -> napi:: Result < AsyncTask < MinifyTask > > {
141109 let code = serde_json:: from_slice ( & input) ?;
142- let mut opts = serde_json:: from_slice ( & opts) ?;
143- patch_opts ( & mut opts) ;
110+ let opts = serde_json:: from_slice ( & opts) ?;
144111
145112 let c = get_compiler ( ) ;
146113
@@ -152,8 +119,7 @@ pub fn minify(
152119#[ napi]
153120pub fn minify_sync ( input : Buffer , opts : Buffer ) -> napi:: Result < TransformOutput > {
154121 let code: MinifyTarget = serde_json:: from_slice ( & input) ?;
155- let mut opts = serde_json:: from_slice ( & opts) ?;
156- patch_opts ( & mut opts) ;
122+ let opts = serde_json:: from_slice ( & opts) ?;
157123
158124 let c = get_compiler ( ) ;
159125
0 commit comments