File tree 2 files changed +59
-2
lines changed
2 files changed +59
-2
lines changed Original file line number Diff line number Diff line change @@ -601,6 +601,19 @@ Compressor.prototype.compress = function(node) {
601
601
fn.enclosed.forEach(function(d) {
602
602
if (fn.variables.get(d.name) === d) return;
603
603
if (safe_to_read(tw, d)) return;
604
+ d.single_use = false;
605
+ var fixed = d.fixed;
606
+ if (typeof fixed == "function") fixed = fixed();
607
+ if (fixed instanceof AST_Lambda) {
608
+ var safe_ids = fixed.safe_ids;
609
+ switch (safe_ids) {
610
+ case null:
611
+ case false:
612
+ return;
613
+ default:
614
+ if (safe_ids && safe_ids.seq !== tw.safe_ids.seq) return;
615
+ }
616
+ }
604
617
d.fixed = false;
605
618
});
606
619
}
@@ -648,6 +661,7 @@ Compressor.prototype.compress = function(node) {
648
661
tw.defined_ids = defined_ids;
649
662
var safe_ids = Object.create(tw.safe_ids);
650
663
if (!sequential) safe_ids.seq = {};
664
+ if (conditional) safe_ids.cond = true;
651
665
tw.safe_ids = safe_ids;
652
666
}
653
667
@@ -1009,7 +1023,7 @@ Compressor.prototype.compress = function(node) {
1009
1023
walk_assign();
1010
1024
right.parent_scope.resolve().fn_defs.push(right);
1011
1025
right.safe_ids = null;
1012
- if (!ld.fixed || !node.write_only) mark_fn_def(tw, ld, right);
1026
+ if (!ld.fixed || !node.write_only || tw.safe_ids.cond ) mark_fn_def(tw, ld, right);
1013
1027
return true;
1014
1028
}
1015
1029
if (scan) {
Original file line number Diff line number Diff line change @@ -1716,7 +1716,7 @@ issue_5856: {
1716
1716
expect_stdout: "PASS"
1717
1717
}
1718
1718
1719
- issue_5917 : {
1719
+ issue_5917_1 : {
1720
1720
options = {
1721
1721
pure_getters : "strict" ,
1722
1722
reduce_vars : true ,
@@ -1751,3 +1751,46 @@ issue_5917: {
1751
1751
}
1752
1752
expect_stdout: "PASS"
1753
1753
}
1754
+
1755
+ issue_5917_2: {
1756
+ options = {
1757
+ passes : 2 ,
1758
+ pure_getters : "strict" ,
1759
+ reduce_vars : true ,
1760
+ side_effects : true ,
1761
+ toplevel : true ,
1762
+ }
1763
+ input: {
1764
+ var b ;
1765
+ if ( ! console ) {
1766
+ b = function ( ) { } ;
1767
+ FAIL ( f ) ;
1768
+ }
1769
+ function f ( ) {
1770
+ b . p ;
1771
+ }
1772
+ try {
1773
+ f ( ) ;
1774
+ console . log ( "FAIL" ) ;
1775
+ } catch ( e ) {
1776
+ console . log ( "PASS" ) ;
1777
+ }
1778
+ }
1779
+ expect: {
1780
+ var b ;
1781
+ if ( ! console ) {
1782
+ b = function ( ) { } ;
1783
+ FAIL ( f ) ;
1784
+ }
1785
+ function f ( ) {
1786
+ b . p ;
1787
+ }
1788
+ try {
1789
+ f ( ) ;
1790
+ console . log ( "FAIL" ) ;
1791
+ } catch ( e ) {
1792
+ console . log ( "PASS" ) ;
1793
+ }
1794
+ }
1795
+ expect_stdout: "PASS"
1796
+ }
You can’t perform that action at this time.
0 commit comments