File tree 5 files changed +30
-0
lines changed
tests/fixture/issues/9263
swc_ecma_usage_analyzer/src/analyzer
5 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ swc_ecma_usage_analyzer : patch
3
+ swc_ecma_minifier : patch
4
+ ---
5
+
6
+ fix(es/minifier): Fix analysis of for-in/of
Original file line number Diff line number Diff line change @@ -337,6 +337,7 @@ impl Optimizer<'_> {
337
337
&& usage. declared
338
338
&& may_remove
339
339
&& !usage. reassigned
340
+ && !usage. declared_as_for_init
340
341
&& usage. assign_count == 1
341
342
&& ref_count == 1
342
343
{
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+ const k = ( function ( ) {
3
+ var x = 42 ;
4
+ for ( var x in [ 4242 ] ) break ;
5
+ return x ;
6
+ } ) ( ) ;
7
+
8
+
9
+ export { k } ;
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+ const k = function ( ) {
3
+ for ( var x in [
4
+ 4242
5
+ ] ) break ;
6
+ return 42 ;
7
+ } ( ) ;
8
+ export { k } ;
Original file line number Diff line number Diff line change @@ -783,6 +783,9 @@ where
783
783
self . with_child ( SyntaxContext :: empty ( ) , ScopeKind :: Block , |child| {
784
784
let head_ctx = Ctx {
785
785
in_left_of_for_loop : true ,
786
+ is_id_ref : true ,
787
+ executed_multiple_time : true ,
788
+ in_cond : true ,
786
789
..child. ctx
787
790
} ;
788
791
n. left . visit_with ( & mut * child. with_ctx ( head_ctx) ) ;
@@ -810,6 +813,9 @@ where
810
813
self . with_child ( SyntaxContext :: empty ( ) , ScopeKind :: Block , |child| {
811
814
let head_ctx = Ctx {
812
815
in_left_of_for_loop : true ,
816
+ is_id_ref : true ,
817
+ executed_multiple_time : true ,
818
+ in_cond : true ,
813
819
..child. ctx
814
820
} ;
815
821
n. left . visit_with ( & mut * child. with_ctx ( head_ctx) ) ;
You can’t perform that action at this time.
0 commit comments