File tree Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -3567,7 +3567,7 @@ Compressor.prototype.compress = function(node) {
3567
3567
continue;
3568
3568
}
3569
3569
// if (foo()) return bar() ? x : void 0; ---> return foo() && bar() ? x : void 0;
3570
- // if (foo()) return bar() ? void 0 : x; ---> return foo() || bar() ? void 0 : x;
3570
+ // if (foo()) return bar() ? void 0 : x; ---> return ! foo() || bar() ? void 0 : x;
3571
3571
var or;
3572
3572
if (value instanceof AST_Conditional
3573
3573
&& ((or = is_undefined(value.consequent, compressor))
@@ -3577,7 +3577,7 @@ Compressor.prototype.compress = function(node) {
3577
3577
ret.value = value.clone();
3578
3578
ret.value.condition = make_node(AST_Binary, stat, {
3579
3579
operator: or ? "||" : "&&",
3580
- left: stat.condition,
3580
+ left: or ? stat.condition.negate(compressor) : stat.condition,
3581
3581
right: value.condition,
3582
3582
});
3583
3583
statements.splice(i, 1, ret.transform(compressor));
Original file line number Diff line number Diff line change @@ -254,7 +254,7 @@ if_return_cond_void_2: {
254
254
}
255
255
expect: {
256
256
function f ( a ) {
257
- return a || console . log ( "foo" ) ? void 0 : console . log ( "bar" ) ;
257
+ return ! a || console . log ( "foo" ) ? void 0 : console . log ( "bar" ) ;
258
258
}
259
259
f ( ) ;
260
260
f ( 42 ) ;
@@ -1827,3 +1827,47 @@ issue_5586: {
1827
1827
"baz" ,
1828
1828
]
1829
1829
}
1830
+
1831
+ issue_5587_1: {
1832
+ options = {
1833
+ if_return : true ,
1834
+ }
1835
+ input: {
1836
+ function f ( a ) {
1837
+ if ( console )
1838
+ return a ? void 0 : console . log ( "PASS" ) ;
1839
+ }
1840
+ f ( ) ;
1841
+ f ( 42 ) ;
1842
+ }
1843
+ expect: {
1844
+ function f ( a ) {
1845
+ return ! console || a ? void 0 : console . log ( "PASS" ) ;
1846
+ }
1847
+ f ( ) ;
1848
+ f ( 42 ) ;
1849
+ }
1850
+ expect_stdout: "PASS"
1851
+ }
1852
+
1853
+ issue_5587_2: {
1854
+ options = {
1855
+ if_return : true ,
1856
+ }
1857
+ input: {
1858
+ function f ( a ) {
1859
+ if ( console )
1860
+ return a ? console . log ( "PASS" ) : void 0 ;
1861
+ }
1862
+ f ( ) ;
1863
+ f ( 42 ) ;
1864
+ }
1865
+ expect: {
1866
+ function f ( a ) {
1867
+ return console && a ? console . log ( "PASS" ) : void 0 ;
1868
+ }
1869
+ f ( ) ;
1870
+ f ( 42 ) ;
1871
+ }
1872
+ expect_stdout: "PASS"
1873
+ }
You can’t perform that action at this time.
0 commit comments