File tree 4 files changed +124
-5
lines changed
4 files changed +124
-5
lines changed Original file line number Diff line number Diff line change @@ -1653,6 +1653,7 @@ Compressor.prototype.compress = function(node) {
1653
1653
function reset_flags(node) {
1654
1654
node._squeezed = false;
1655
1655
node._optimized = false;
1656
+ node.single_use = false;
1656
1657
if (node instanceof AST_BlockScope) node._var_names = undefined;
1657
1658
if (node instanceof AST_SymbolRef) node.fixed = undefined;
1658
1659
}
@@ -14178,6 +14179,7 @@ Compressor.prototype.compress = function(node) {
14178
14179
var fn = call.expression;
14179
14180
if (!(fn instanceof AST_LambdaExpression)) return;
14180
14181
if (fn.name) return;
14182
+ if (fn.single_use) return;
14181
14183
if (fn.uses_arguments) return;
14182
14184
if (fn.pinned()) return;
14183
14185
if (is_generator(fn)) return;
Original file line number Diff line number Diff line change @@ -8706,10 +8706,9 @@ single_use_inline_collision: {
8706
8706
expect: {
8707
8707
var a = "PASS" ;
8708
8708
( function ( ) {
8709
- ( function ( ) {
8709
+ void function ( ) {
8710
8710
while ( console . log ( a ) ) ;
8711
- return ;
8712
- } ) ( ) ;
8711
+ } ( ) ;
8713
8712
( function ( a ) {
8714
8713
a || a ( "FAIL" ) ;
8715
8714
} ) ( console . log ) ;
Original file line number Diff line number Diff line change @@ -801,3 +801,71 @@ issue_5638_4: {
801
801
}
802
802
expect_stdout: "foo 42"
803
803
}
804
+
805
+ issue_5884_1: {
806
+ options = {
807
+ hoist_vars : true ,
808
+ inline : true ,
809
+ join_vars : true ,
810
+ reduce_vars : true ,
811
+ sequences : true ,
812
+ toplevel : true ,
813
+ unused : true ,
814
+ }
815
+ input: {
816
+ try {
817
+ var f = function ( ) {
818
+ var a = [ "PASS" ] ;
819
+ for ( b in a )
820
+ console . log ( a [ b ] ) ;
821
+ } ;
822
+ f ( ) ;
823
+ } finally {
824
+ var b ;
825
+ }
826
+ }
827
+ expect: {
828
+ var b ;
829
+ try {
830
+ ( function ( ) {
831
+ var a = [ "PASS" ] ;
832
+ for ( b in a )
833
+ console . log ( a [ b ] ) ;
834
+ } ) ( ) ;
835
+ } finally { }
836
+ }
837
+ expect_stdout: "PASS"
838
+ }
839
+
840
+ issue_5884_2: {
841
+ options = {
842
+ hoist_vars : true ,
843
+ inline : true ,
844
+ join_vars : true ,
845
+ passes : 2 ,
846
+ reduce_vars : true ,
847
+ sequences : true ,
848
+ toplevel : true ,
849
+ unused : true ,
850
+ }
851
+ input: {
852
+ try {
853
+ var f = function ( ) {
854
+ var a = [ "PASS" ] ;
855
+ for ( b in a )
856
+ console . log ( a [ b ] ) ;
857
+ } ;
858
+ f ( ) ;
859
+ } finally {
860
+ var b ;
861
+ }
862
+ }
863
+ expect: {
864
+ try {
865
+ var a = [ "PASS" ] ;
866
+ for ( var b in a )
867
+ console . log ( a [ b ] ) ;
868
+ } finally { }
869
+ }
870
+ expect_stdout: "PASS"
871
+ }
Original file line number Diff line number Diff line change @@ -669,7 +669,7 @@ inlined_assignments: {
669
669
expect_stdout: "PASS"
670
670
}
671
671
672
- inline_for : {
672
+ single_use_for : {
673
673
options = {
674
674
inline : true ,
675
675
join_vars : true ,
@@ -683,16 +683,66 @@ inline_for: {
683
683
} ;
684
684
a ( ) ;
685
685
}
686
+ expect: {
687
+ ( function ( ) {
688
+ for ( ; console . log ( "PASS" ) ; ) ;
689
+ } ) ( ) ;
690
+ }
691
+ expect_stdout: "PASS"
692
+ }
693
+
694
+ single_use_for_inline: {
695
+ options = {
696
+ inline : true ,
697
+ join_vars : true ,
698
+ passes : 2 ,
699
+ reduce_vars : true ,
700
+ toplevel : true ,
701
+ unused : true ,
702
+ }
703
+ input: {
704
+ var a = function ( ) {
705
+ for ( ; console . log ( "PASS" ) ; ) ;
706
+ } ;
707
+ a ( ) ;
708
+ }
686
709
expect: {
687
710
for ( ; console . log ( "PASS" ) ; ) ;
688
711
}
689
712
expect_stdout: "PASS"
690
713
}
691
714
692
- inline_var: {
715
+ single_use_var: {
716
+ options = {
717
+ inline : true ,
718
+ join_vars : true ,
719
+ reduce_vars : true ,
720
+ toplevel : true ,
721
+ unused : true ,
722
+ }
723
+ input: {
724
+ A = "PASS" ;
725
+ var a = function ( ) {
726
+ var b = A ;
727
+ for ( b in console . log ( b ) ) ;
728
+ } ;
729
+ a ( ) ;
730
+ }
731
+ expect: {
732
+ A = "PASS" ;
733
+ ( function ( ) {
734
+ var b = A ;
735
+ for ( b in console . log ( b ) ) ;
736
+ } ) ( ) ;
737
+ }
738
+ expect_stdout: "PASS"
739
+ }
740
+
741
+ single_use_var_inline: {
693
742
options = {
694
743
inline : true ,
695
744
join_vars : true ,
745
+ passes : 2 ,
696
746
reduce_vars : true ,
697
747
toplevel : true ,
698
748
unused : true ,
You can’t perform that action at this time.
0 commit comments