|
7 | 7 | # This is based on the module of the same name by Malcolm Beattie, |
8 | 8 | # but essentially none of his code remains. |
9 | 9 |
|
10 | | -package B::Deparse 1.85; |
| 10 | +package B::Deparse 1.86; |
11 | 11 | use strict; |
12 | 12 | use Carp; |
13 | 13 | use B qw(class main_root main_start main_cv svref_2object opnumber perlstring |
@@ -4034,13 +4034,22 @@ sub pp_cond_expr { |
4034 | 4034 | my $true = $cond->sibling; |
4035 | 4035 | my $false = $true->sibling; |
4036 | 4036 | my $cuddle = $self->{'cuddle'}; |
4037 | | - unless ($cx < 1 and (is_scope($true) and $true->name ne "null") and |
4038 | | - (is_scope($false) || is_ifelse_cont($false)) |
4039 | | - and $self->{'expand'} < 7) { |
4040 | | - $cond = $self->deparse($cond, 8); |
4041 | | - $true = $self->deparse($true, 6); |
4042 | | - $false = $self->deparse($false, 8); |
4043 | | - return $self->maybe_parens("$cond ? $true : $false", $cx, 8); |
| 4037 | + |
| 4038 | + if (class($false) eq "NULL") { # Empty else {} block was optimised away |
| 4039 | + unless ($cx < 1 and (is_scope($true) and $true->name ne "null")) { |
| 4040 | + $cond = $self->deparse($cond, 8); |
| 4041 | + $true = $self->deparse($true, 6); |
| 4042 | + return $self->maybe_parens("$cond ? $true : ()", $cx, 8); |
| 4043 | + } |
| 4044 | + } else { # Both true and false branches are present |
| 4045 | + unless ($cx < 1 and (is_scope($true) and $true->name ne "null") |
| 4046 | + and (is_scope($false) || is_ifelse_cont($false)) |
| 4047 | + and $self->{'expand'} < 7) { |
| 4048 | + $cond = $self->deparse($cond, 8); |
| 4049 | + $true = $self->deparse($true, 6); |
| 4050 | + $false = $self->deparse($false, 8); |
| 4051 | + return $self->maybe_parens("$cond ? $true : $false", $cx, 8); |
| 4052 | + } |
4044 | 4053 | } |
4045 | 4054 |
|
4046 | 4055 | $cond = $self->deparse($cond, 1); |
|
0 commit comments