@@ -6,10 +6,7 @@ use oxc_span::GetSpan;
66use oxc_syntax:: scope:: ScopeFlags ;
77use oxc_traverse:: { Ancestor , ReusableTraverseCtx , Traverse , traverse_mut_with_ctx} ;
88
9- use crate :: {
10- CompressOptions ,
11- ctx:: { Ctx , MinifierState , TraverseCtx } ,
12- } ;
9+ use crate :: ctx:: { Ctx , MinifierState , TraverseCtx } ;
1310
1411#[ derive( Default ) ]
1512pub struct NormalizeOptions {
@@ -38,7 +35,6 @@ pub struct NormalizeOptions {
3835/// <https://github.com/google/closure-compiler/blob/v20240609/src/com/google/javascript/jscomp/Normalize.java>
3936pub struct Normalize {
4037 options : NormalizeOptions ,
41- compress_options : CompressOptions ,
4238}
4339
4440impl < ' a > Normalize {
@@ -52,11 +48,11 @@ impl<'a> Normalize {
5248}
5349
5450impl < ' a > Traverse < ' a , MinifierState < ' a > > for Normalize {
55- fn exit_statements ( & mut self , stmts : & mut Vec < ' a , Statement < ' a > > , _ctx : & mut TraverseCtx < ' a > ) {
51+ fn exit_statements ( & mut self , stmts : & mut Vec < ' a , Statement < ' a > > , ctx : & mut TraverseCtx < ' a > ) {
5652 stmts. retain ( |stmt| {
5753 !( matches ! ( stmt, Statement :: EmptyStatement ( _) )
58- || self . drop_debugger ( stmt)
59- || self . drop_console ( stmt) )
54+ || Self :: drop_debugger ( stmt, ctx )
55+ || Self :: drop_console ( stmt, ctx ) )
6056 } ) ;
6157 }
6258
@@ -90,10 +86,10 @@ impl<'a> Traverse<'a, MinifierState<'a>> for Normalize {
9086 None
9187 }
9288 Expression :: ArrowFunctionExpression ( e) => {
93- self . recover_arrow_expression_after_drop_console ( e) ;
89+ Self :: recover_arrow_expression_after_drop_console ( e, ctx ) ;
9490 None
9591 }
96- Expression :: CallExpression ( _) if self . compress_options . drop_console => {
92+ Expression :: CallExpression ( _) if ctx . state . options . drop_console => {
9793 self . compress_console ( expr, ctx)
9894 }
9995 Expression :: StaticMemberExpression ( e) => Self :: fold_number_nan_to_nan ( e, ctx) ,
@@ -113,33 +109,36 @@ impl<'a> Traverse<'a, MinifierState<'a>> for Normalize {
113109}
114110
115111impl < ' a > Normalize {
116- pub fn new ( options : NormalizeOptions , compress_options : CompressOptions ) -> Self {
117- Self { options, compress_options }
112+ pub fn new ( options : NormalizeOptions ) -> Self {
113+ Self { options }
118114 }
119115
120116 /// Drop `drop_debugger` statement.
121117 ///
122118 /// Enabled by `compress.drop_debugger`
123- fn drop_debugger ( & self , stmt : & Statement < ' a > ) -> bool {
124- matches ! ( stmt, Statement :: DebuggerStatement ( _) ) && self . compress_options . drop_debugger
119+ fn drop_debugger ( stmt : & Statement < ' a > , ctx : & TraverseCtx < ' a > ) -> bool {
120+ matches ! ( stmt, Statement :: DebuggerStatement ( _) ) && ctx . state . options . drop_debugger
125121 }
126122
127123 fn compress_console (
128124 & self ,
129125 expr : & Expression < ' a > ,
130126 ctx : & TraverseCtx < ' a > ,
131127 ) -> Option < Expression < ' a > > {
132- debug_assert ! ( self . compress_options . drop_console) ;
128+ debug_assert ! ( ctx . state . options . drop_console) ;
133129 Self :: is_console ( expr) . then ( || ctx. ast . void_0 ( expr. span ( ) ) )
134130 }
135131
136- fn drop_console ( & self , stmt : & Statement < ' a > ) -> bool {
137- self . compress_options . drop_console
132+ fn drop_console ( stmt : & Statement < ' a > , ctx : & TraverseCtx < ' a > ) -> bool {
133+ ctx . state . options . drop_console
138134 && matches ! ( stmt, Statement :: ExpressionStatement ( expr) if Self :: is_console( & expr. expression) )
139135 }
140136
141- fn recover_arrow_expression_after_drop_console ( & self , expr : & mut ArrowFunctionExpression < ' a > ) {
142- if self . compress_options . drop_console && expr. expression && expr. body . is_empty ( ) {
137+ fn recover_arrow_expression_after_drop_console (
138+ expr : & mut ArrowFunctionExpression < ' a > ,
139+ ctx : & TraverseCtx < ' a > ,
140+ ) {
141+ if ctx. state . options . drop_console && expr. expression && expr. body . is_empty ( ) {
143142 expr. expression = false ;
144143 }
145144 }
0 commit comments