1- use oxc_allocator:: TakeIn ;
21use oxc_ast:: ast:: * ;
32
43use crate :: { CompressOptionsUnused , ctx:: Ctx } ;
@@ -48,38 +47,38 @@ impl<'a> PeepholeOptimizations {
4847
4948 pub fn remove_unused_assignment_expression (
5049 & self ,
51- e : & mut Expression < ' a > ,
52- state : & mut State ,
53- ctx : & mut Ctx < ' a , ' _ > ,
50+ _e : & mut Expression < ' a > ,
51+ _state : & mut State ,
52+ _ctx : & mut Ctx < ' a , ' _ > ,
5453 ) -> bool {
55- let Expression :: AssignmentExpression ( assign_expr) = e else { return false } ;
56- if matches ! (
57- ctx. state. options. unused,
58- CompressOptionsUnused :: Keep | CompressOptionsUnused :: KeepAssign
59- ) {
60- return false ;
61- }
62- let Some ( SimpleAssignmentTarget :: AssignmentTargetIdentifier ( ident) ) =
63- assign_expr. left . as_simple_assignment_target ( )
64- else {
65- return false ;
66- } ;
67- if Self :: keep_top_level_var_in_script_mode ( ctx) {
68- return false ;
69- }
70- let Some ( reference_id) = ident. reference_id . get ( ) else { return false } ;
71- let Some ( symbol_id) = ctx. scoping ( ) . get_reference ( reference_id) . symbol_id ( ) else {
72- return false ;
73- } ;
74- // Keep error for assigning to `const foo = 1; foo = 2`.
75- if ctx. scoping ( ) . symbol_flags ( symbol_id) . is_const_variable ( ) {
76- return false ;
77- }
78- if !ctx. scoping ( ) . get_resolved_references ( symbol_id) . all ( |r| !r. flags ( ) . is_read ( ) ) {
79- return false ;
80- }
81- * e = assign_expr. right . take_in ( ctx. ast ) ;
82- state. changed = true ;
54+ // let Expression::AssignmentExpression(assign_expr) = e else { return false };
55+ // if matches!(
56+ // ctx.state.options.unused,
57+ // CompressOptionsUnused::Keep | CompressOptionsUnused::KeepAssign
58+ // ) {
59+ // return false;
60+ // }
61+ // let Some(SimpleAssignmentTarget::AssignmentTargetIdentifier(ident)) =
62+ // assign_expr.left.as_simple_assignment_target()
63+ // else {
64+ // return false;
65+ // };
66+ // if Self::keep_top_level_var_in_script_mode(ctx) {
67+ // return false;
68+ // }
69+ // let Some(reference_id) = ident.reference_id.get() else { return false };
70+ // let Some(symbol_id) = ctx.scoping().get_reference(reference_id).symbol_id() else {
71+ // return false;
72+ // };
73+ // // Keep error for assigning to `const foo = 1; foo = 2`.
74+ // if ctx.scoping().symbol_flags(symbol_id).is_const_variable() {
75+ // return false;
76+ // }
77+ // if !ctx.scoping().get_resolved_references(symbol_id).all(|r| !r.flags().is_read()) {
78+ // return false;
79+ // }
80+ // *e = assign_expr.right.take_in(ctx.ast);
81+ // state.changed = true;
8382 false
8483 }
8584
@@ -121,11 +120,13 @@ mod test {
121120 }
122121
123122 #[ test]
123+ #[ ignore]
124124 fn remove_unused_assignment_expression ( ) {
125125 let options = CompressOptions :: smallest ( ) ;
126126 test_options ( "var x = 1; x = 2;" , "" , & options) ;
127127 test_options ( "var x = 1; x = 2;" , "" , & options) ;
128128 test_options ( "var x = 1; x = foo();" , "foo()" , & options) ;
129+ test_same_options ( "export let foo; foo = 0;" , & options) ;
129130 test_same_options ( "var x = 1; x = 2, foo(x)" , & options) ;
130131 test_same_options ( "function foo() { return t = x(); } foo();" , & options) ;
131132 test_options (
@@ -141,6 +142,7 @@ mod test {
141142 }
142143
143144 #[ test]
145+ #[ ignore]
144146 fn keep_in_script_mode ( ) {
145147 let options = CompressOptions :: smallest ( ) ;
146148 let source_type = SourceType :: cjs ( ) ;
0 commit comments