blib/lib/JavaScript/Minifier.pm

filter: Statementstmt 97.4% 150 / 154 Branchbran 91.1% 93 / 102 Conditioncond 81.6% 169 / 207 MC/DCmcdc 63.1% 65 / 103 Subroutinesub 100% 20 / 20 Podpod 0.0% 0 / 16 totaltotal 82.5% 497 / 602 SCAR 49.5
CC
121
Cov
89%
minify
85.3
putLiteral
9.9
onWhitespaceConditionalComment
9.6
CRAP 140.6
↑ Summary
1 package JavaScript::Minifier;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = '1.15'; # VERSION
7  
8 4 require Exporter;
9 4 our @ISA = qw(Exporter);
10 4 our @EXPORT = qw(minify);
11  
12 # string 'return' as array to handle special case of returning a regexp from a function
13 4 my @return = qw(r e t u r n);
14  
15 #return true if the character is allowed in identifier.
16 sub isAlphanum {
17 432 ▶ return ($_[0] =~ /[\w\$\\]/ || ord($_[0]) > 126);
Subroutine isAlphanum: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$_[0] =~ /[\w\$\\]/ || ord $_[0] > 126
l!l&&r!l&&!r
2540178
MC/DC50%1/2
$_[0] =~ /[\w\$\\]/ || ord $_[0] > 126
$_[0] =~ /[\w\$\\]/ ord $_[0] > 126
Truth table66%2/3
A || B
A= $_[0] =~ /[\w\$\\]/B= ord $_[0] > 126
ABresult
1X1
011
000
18 }
19  
20 sub isEndspace {
21 427 ▶ return ($_[0] eq "\n" || $_[0] eq "\r" || $_[0] eq "\f");
Subroutine isEndspace: called CC=3 SCAR=11.7
Pod undocumented
Condition66%4/6
$_[0] eq "\n" || $_[0] eq "\r" || $_[0] eq "\f"
l!l&&r!l&&!r
1550272
$_[0] eq "\n" or $_[0] eq "\r"
l!l&&r!l&&!r
1550272
MC/DC33%1/3
$_[0] eq "\n" || $_[0] eq "\r" || $_[0] eq "\f"
$_[0] eq "\n" $_[0] eq "\r" $_[0] eq "\f"
Truth table50%2/4
A or B || C
A= $_[0] eq "\n"B= $_[0] eq "\r"C= $_[0] eq "\f"
ABCresult
1XX1
01X1
0011
0000
22 }
23  
24 sub isWhitespace {
25 2537 ▶ return ($_[0] eq ' ' || $_[0] eq "\t" || $_[0] eq "\n"
Subroutine isWhitespace: called CC=5 SCAR=16.7
Pod undocumented
Condition75%9/12
$_[0] eq ' ' || $_[0] eq "\t" || $_[0] eq "\n" || $_[0] eq "\r" || $_[0] eq "\f"
l!l&&r!l&&!r
73201805
$_[0] eq " " or $_[0] eq "\t" or $_[0] eq "\n" or $_[0] eq "\r"
l!l&&r!l&&!r
73201805
$_[0] eq " " or $_[0] eq "\t" or $_[0] eq "\n"
l!l&&r!l&&!r
4532791805
$_[0] eq " " or $_[0] eq "\t"
l!l&&r!l&&!r
45302084
MC/DC40%2/5
$_[0] eq ' ' || $_[0] eq "\t" || $_[0] eq "\n" || $_[0] eq "\r" || $_[0] eq "\f"
$_[0] eq " " $_[0] eq "\t" $_[0] eq "\n" $_[0] eq "\r" $_[0] eq "\f"
Truth table50%3/6
A or B or C or D || E
A= $_[0] eq " "B= $_[0] eq "\t"C= $_[0] eq "\n"D= $_[0] eq "\r"E= $_[0] eq "\f"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
26 || $_[0] eq "\r" || $_[0] eq "\f");
27 }
28  
29 # New line characters before or after these characters can be removed.
30 # Not + - / in this list because they require special care.
31 sub isInfix {
32 58 ▶ $_[0] =~ /[,;:=&%*<>\?\|\n]/;
Subroutine isInfix: called CC=1 SCAR=0.0
Pod undocumented
33 }
34  
35 # New line characters after these characters can be removed.
36 sub isPrefix {
37 31 ▶ return ($_[0] =~ /[\{\(\[!]/ || isInfix($_[0]));
Subroutine isPrefix: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$_[0] =~ /[\{\(\[!]/ || isInfix($_[0])
l!l&&r!l&&!r
01615
MC/DC50%1/2
$_[0] =~ /[\{\(\[!]/ || isInfix($_[0])
$_[0] =~ /[\{\(\[!]/ isInfix($_[0])
Truth table66%2/3
A || B
A= $_[0] =~ /[\{\(\[!]/B= isInfix($_[0])
ABresult
1X1
011
000
38 }
39  
40 # New line characters before these characters can removed.
41 sub isPostfix {
42 41 ▶ return ($_[0] =~ /[\}\)\]]/ || isInfix($_[0]));
Subroutine isPostfix: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$_[0] =~ /[\}\)\]]/ || isInfix($_[0])
l!l&&r!l&&!r
14027
MC/DC50%1/2
$_[0] =~ /[\}\)\]]/ || isInfix($_[0])
$_[0] =~ /[\}\)\]]/ isInfix($_[0])
Truth table66%2/3
A || B
A= $_[0] =~ /[\}\)\]]/B= isInfix($_[0])
ABresult
1X1
011
000
43 }
44  
45 # -----------------------------------------------------------------------------
46  
47 sub _get {
48 1427 ▶ my $s = shift;
Subroutine _get: called CC=5 SCAR=16.2
49  
50 1427 ▶ if ($s->{inputType} eq 'file') {
Branch: 2 branches
BranchTrueFalseTotal
if ($s->{'inputType'} eq 'file') { } 1289 138 1427
elsif ($s->{'inputType'} eq 'string') { } 138 0 138
51 1289 my $char = getc($s->{input});
52 1289 ▶ $s->{last_read_char} = $char
Branch: 1 branch
BranchTrueFalseTotal
if defined $char 1229 60 1289
53 if defined $char;
54  
55 1289 return $char;
56 }
57 elsif ($s->{inputType} eq 'string') {
58 138 ▶ if ($s->{'inputPos'} < length($s->{input})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{'inputPos'} < length $s->{'input'}) { } 118 20 138
59 return $s->{last_read_char}
60 118 = substr($s->{input}, $s->{inputPos}++, 1);
61 }
62 else { # Simulate getc() when off the end of the input string.
63 20 return undef;
64 }
65 }
66 else {
67 0 die "no input";
68 }
69 }
70  
71 sub _put {
72 743 ▶ my $s = shift;
Subroutine _put: called CC=2 SCAR=6.9
73 743 my $x = shift;
74 743 my $outfile = ($s->{outfile});
75 743 ▶ if (defined($s->{outfile})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{'outfile'}) { } 657 86 743
76 657 print $outfile $x;
77 }
78 else {
79 86 $s->{output} .= $x;
80 }
81 }
82  
83 # -----------------------------------------------------------------------------
84  
85 # print a
86 # move b to a
87 # move c to b
88 # move d to c
89 # new d
90 #
91 # i.e. print a and advance
92 sub action1 {
93 575 ▶ my $s = shift;
Subroutine action1: called CC=2 SCAR=6.9
Pod undocumented
94 575 ▶ if (!isWhitespace($s->{a})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (isWhitespace($s->{"a"})) 495 80 575
95 495 $s->{lastnws} = $s->{a};
96 }
97 575 $s->{last} = $s->{a};
98 575 action2($s);
99 }
100  
101 # sneeky output $s->{a} for comments
102 sub action2 {
103 740 ▶ my $s = shift;
Subroutine action2: called CC=1 SCAR=0.0
Pod undocumented
104 740 _put($s, $s->{a});
105 740 action3($s);
106 }
107  
108 # move b to a
109 # move c to b
110 # move d to c
111 # new d
112 #
113 # i.e. delete a
114 sub action3 {
115 1243 ▶ my $s = shift;
Subroutine action3: called CC=1 SCAR=0.0
Pod undocumented
116 1243 $s->{a} = $s->{b};
117 1243 action4($s);
118 }
119  
120 # move c to b
121 # move d to c
122 # new d
123 #
124 # i.e. delete b
125 sub action4 {
126 1342 ▶ my $s = shift;
Subroutine action4: called CC=1 SCAR=0.0
Pod undocumented
127 1342 $s->{b} = $s->{c};
128 1342 $s->{c} = $s->{d};
129 1342 $s->{d} = _get($s);
130 }
131  
132 # -----------------------------------------------------------------------------
133  
134 # put string and regexp literals
135 # when this sub is called, $s->{a} is on the opening delimiter character
136 sub putLiteral {
137 15 ▶ my $s = shift;
Subroutine putLiteral: called CC=8 SCAR=22.9
Pod undocumented
138 15 my $delimiter = $s->{a}; # ', " or /
139 15 action1($s);
140 do {
141 93 ▶ while (defined($s->{a}) && $s->{a} eq '\\') { # escape character only escapes only the next one character
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"a"} and $s->{"a"} eq "\\") 11 93 104
Condition66%2/3
defined $s->{"a"} and $s->{"a"} eq "\\"
!ll&&!rl&&r
09311
MC/DC50%1/2
defined $s->{"a"} and $s->{"a"} eq "\\"
defined $s->{"a"} $s->{"a"} eq "\\"
Truth table66%2/3
A and B
A= defined $s->{"a"}B= $s->{"a"} eq "\\"
ABresult
0X0
100
111
142 11 action1($s);
143 11 action1($s);
144 }
145 93 action1($s);
146 15 ▶ } until ($s->{last} eq $delimiter || !defined($s->{a}));
Branch: 1 branch
BranchTrueFalseTotal
($s->{"last"} eq $delimiter or not defined $s->{"a"}) or do { do { while (defined $s->{"a"} and $s->{"a"} eq "\\") { action1($s); action1($s); } ; action1($s) } } 78 15 93
Condition66%2/3
$s->{"last"} eq $delimiter or not defined $s->{"a"}
l!l&&r!l&&!r
15078
MC/DC50%1/2
$s->{"last"} eq $delimiter or not defined $s->{"a"}
$s->{"last"} eq $delimiter not defined $s->{"a"}
Truth table66%2/3
A or not(B)
A= $s->{"last"} eq $delimiterB= not defined $s->{"a"}
ABresult
1X1
011
000
147 15 ▶ if ($s->{last} ne $delimiter) { # ran off end of file before printing the closing delimiter
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"last"} ne $delimiter) 0 15 15
148 0 ▶ die 'unterminated ' . ($delimiter eq '\'' ? 'single quoted string' : $delimiter eq '"' ? 'double quoted string' : 'regular expression') . ' literal, stopped';
Branch: 2 branches
BranchTrueFalseTotal
$delimiter eq q['] ? : 0 0 0
$delimiter eq '"' ? : 0 0 0
149 }
150 }
151  
152 # -----------------------------------------------------------------------------
153  
154 # If $s->{a} is a whitespace then collapse all following whitespace.
155 # If any of the whitespace is a new line then ensure $s->{a} is a new line
156 # when this function ends.
157 sub collapseWhitespace {
158 420 ▶ my $s = shift;
Subroutine collapseWhitespace: called CC=7 SCAR=19.5
Pod undocumented
159 420 ▶ while (defined($s->{a}) && isWhitespace($s->{a}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"a"} and isWhitespace($s->{"a"}) and defined $s->{"b"} and isWhitespace($s->{"b"})) 99 420 519
Condition100%9/9
defined $s->{"a"} and isWhitespace($s->{"a"}) and defined $s->{"b"} and isWhitespace($s->{"b"})
!ll&&!rl&&r
23718399
defined $s->{"a"} and isWhitespace($s->{"a"}) and defined $s->{"b"}
!ll&&!rl&&r
2334282
defined $s->{"a"} and isWhitespace($s->{"a"})
!ll&&!rl&&r
10223286
MC/DC100%4/4
defined $s->{"a"} and isWhitespace($s->{"a"}) and defined $s->{"b"} and isWhitespace($s->{"b"})
defined $s->{"a"} isWhitespace($s->{"a"}) defined $s->{"b"} isWhitespace($s->{"b"})
Truth table100%5/5
A and B and C and D
A= defined $s->{"a"}B= isWhitespace($s->{"a"})C= defined $s->{"b"}D= isWhitespace($s->{"b"})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
160 defined($s->{b}) && isWhitespace($s->{b})) {
161 99 ▶ if (isEndspace($s->{a}) || isEndspace($s->{b})) {
Branch: 1 branch
BranchTrueFalseTotal
if (isEndspace($s->{"a"}) or isEndspace($s->{"b"})) 82 17 99
Condition100%3/3
isEndspace($s->{"a"}) or isEndspace($s->{"b"})
l!l&&r!l&&!r
622017
MC/DC100%2/2
isEndspace($s->{"a"}) or isEndspace($s->{"b"})
isEndspace($s->{"a"}) isEndspace($s->{"b"})
Truth table100%3/3
A or B
A= isEndspace($s->{"a"})B= isEndspace($s->{"b"})
ABresult
1X1
011
000
162 82 $s->{a} = "\n";
163 }
164 99 action4($s); # delete b
165 }
166 }
167  
168 # Advance $s->{a} to non-whitespace or end of file.
169 # Doesn't print any of this whitespace.
170 sub skipWhitespace {
171 241 ▶ my $s = shift;
Subroutine skipWhitespace: called CC=3 SCAR=11.0
Pod undocumented
172 241 ▶ while (defined($s->{a}) && isWhitespace($s->{a})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"a"} and isWhitespace($s->{"a"})) 193 241 434
Condition100%3/3
defined $s->{"a"} and isWhitespace($s->{"a"})
!ll&&!rl&&r
14227193
MC/DC100%2/2
defined $s->{"a"} and isWhitespace($s->{"a"})
defined $s->{"a"} isWhitespace($s->{"a"})
Truth table100%3/3
A and B
A= defined $s->{"a"}B= isWhitespace($s->{"a"})
ABresult
0X0
100
111
173 193 action3($s);
174 }
175 }
176  
177 # Advance $s->{a} to non-whitespace or end of file
178 # If any of the whitespace is a new line then print one new line.
179 sub preserveEndspace {
180 125 ▶ my $s = shift;
Subroutine preserveEndspace: called CC=5 SCAR=16.1
Pod undocumented
181 125 collapseWhitespace($s);
182 125 ▶ if (defined($s->{a}) && isEndspace($s->{a}) && defined($s->{b}) && !isPostfix($s->{b}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"a"} and isEndspace($s->{"a"}) and defined $s->{"b"} and not isPostfix($s->{"b"})) 27 98 125
Condition100%9/9
defined $s->{"a"} and isEndspace($s->{"a"}) and defined $s->{"b"} and not isPostfix($s->{"b"})
!ll&&!rl&&r
841427
defined $s->{"a"} and isEndspace($s->{"a"}) and defined $s->{"b"}
!ll&&!rl&&r
82241
defined $s->{"a"} and isEndspace($s->{"a"})
!ll&&!rl&&r
47843
MC/DC100%4/4
defined $s->{"a"} and isEndspace($s->{"a"}) and defined $s->{"b"} and not isPostfix($s->{"b"})
defined $s->{"a"} isEndspace($s->{"a"}) defined $s->{"b"} not isPostfix($s->{"b"})
Truth table100%5/5
A and B and C and not(D)
A= defined $s->{"a"}B= isEndspace($s->{"a"})C= defined $s->{"b"}D= not isPostfix($s->{"b"})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
183 27 action1($s);
184 }
185 125 skipWhitespace($s);
186 }
187  
188 sub onWhitespaceConditionalComment {
189 28 ▶ my $s = shift;
Subroutine onWhitespaceConditionalComment: called CC=9 SCAR=22.6
Pod undocumented
190 return (defined($s->{a}) && isWhitespace($s->{a}) &&
191 defined($s->{b}) && $s->{b} eq '/' &&
192 defined($s->{c}) && ($s->{c} eq '/' || $s->{c} eq '*') &&
193 28 ▶ defined($s->{d}) && $s->{d} eq '@');
Condition79%19/24
defined $s->{'a'} && isWhitespace($s->{'a'}) && defined $s->{'b'} && $s->{'b'} eq '/' && defined $s->{'c'} && ($s->{'c'} eq '/' || $s->{'c'} eq '*') && defined $s->{'d'} && $s->{'d'} eq '@'
!ll&&!rl&&r
2044
defined $s->{"a"} and isWhitespace($s->{"a"}) and defined $s->{"b"} and $s->{"b"} eq "/" and defined $s->{"c"} and $s->{"c"} eq "/" || $s->{"c"} eq "*" and defined $s->{"d"}
!ll&&!rl&&r
2008
defined $s->{"a"} and isWhitespace($s->{"a"}) and defined $s->{"b"} and $s->{"b"} eq "/" and defined $s->{"c"} and $s->{"c"} eq "/" || $s->{"c"} eq "*"
!ll&&!rl&&r
2008
defined $s->{"a"} and isWhitespace($s->{"a"}) and defined $s->{"b"} and $s->{"b"} eq "/" and defined $s->{"c"}
!ll&&!rl&&r
2008
defined $s->{"a"} and isWhitespace($s->{"a"}) and defined $s->{"b"} and $s->{"b"} eq "/"
!ll&&!rl&&r
1378
defined $s->{"a"} and isWhitespace($s->{"a"}) and defined $s->{"b"}
!ll&&!rl&&r
12115
defined $s->{"a"} and isWhitespace($s->{"a"})
!ll&&!rl&&r
01216
$s->{"c"} eq "/" or $s->{"c"} eq "*"
l!l&&r!l&&!r
440
MC/DC44%4/9
defined $s->{'a'} && isWhitespace($s->{'a'}) && defined $s->{'b'} && $s->{'b'} eq '/' && defined $s->{'c'} && ($s->{'c'} eq '/' || $s->{'c'} eq '*') && defined $s->{'d'} && $s->{'d'} eq '@'
defined $s->{"a"} isWhitespace($s->{"a"}) defined $s->{"b"} $s->{"b"} eq "/" defined $s->{"c"} $s->{"c"} eq "/" $s->{"c"} eq "*" defined $s->{"d"} $s->{'d'} eq '@'
Truth table58%7/12
A and B and C and D and E and F or G and H && I
A= defined $s->{"a"}B= isWhitespace($s->{"a"})C= defined $s->{"b"}D= $s->{"b"} eq "/"E= defined $s->{"c"}F= $s->{"c"} eq "/"G= $s->{"c"} eq "*"H= defined $s->{"d"}I= $s->{'d'} eq '@'
ABCDEFGHIresult
0XXXXXXXX0
10XXXXXXX0
110XXXXXX0
1110XXXXX0
11110XXXX0
1111100XX0
111111X0X0
11111010X0
111111X100
1111101100
111111X111
1111101111
194 }
195  
196 # -----------------------------------------------------------------------------
197  
198 sub minify {
199 20 ▶ my %h = @_;
Subroutine minify: called CC=79 SCAR=44.5
Pod undocumented
200 # Immediately turn hash into a hash reference so that notation is the same in this function
201 # as others. Easier refactoring.
202 20 my $s = \%h; # hash reference for "state". This module is functional programming and the state is passed between functions.
203  
204 # determine if the the input is a string or a file handle.
205 20 my $ref = \$s->{input};
206 20 ▶ if (defined($ref) && ref($ref) eq 'SCALAR'){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref and ref $ref eq 'SCALAR') { } 5 15 20
Condition66%2/3
defined $ref and ref $ref eq "SCALAR"
!ll&&!rl&&r
0155
MC/DC50%1/2
defined $ref and ref $ref eq "SCALAR"
defined $ref ref $ref eq "SCALAR"
Truth table66%2/3
A and B
A= defined $refB= ref $ref eq "SCALAR"
ABresult
0X0
100
111
207 5 $s->{inputPos} = 0;
208 5 $s->{inputType} = 'string';
209 }
210 else {
211 15 $s->{inputType} = 'file';
212 }
213  
214 # Determine if the output is to a string or a file.
215 20 ▶ if (!defined($s->{outfile})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s->{"outfile"}) 5 15 20
216 5 $s->{output} = '';
217 }
218  
219 # Print the copyright notice first
220 20 ▶ if ($s->{copyright}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"copyright"}) 1 19 20
221 1 _put($s, '/* ' . $s->{copyright} . ' */');
222 }
223  
224 # Initialize the buffer.
225 do {
226 25 $s->{a} = _get($s);
227 20 ▶ } while (defined($s->{a}) && isWhitespace($s->{a}));
Branch: 1 branch
BranchTrueFalseTotal
defined $s->{"a"} and isWhitespace($s->{"a"}) and do { do { $s->{"a"} = _get($s) } } 5 20 25
Condition66%2/3
defined $s->{"a"} and isWhitespace($s->{"a"})
!ll&&!rl&&r
0205
MC/DC50%1/2
defined $s->{"a"} and isWhitespace($s->{"a"})
defined $s->{"a"} isWhitespace($s->{"a"})
Truth table66%2/3
A and B
A= defined $s->{"a"}B= isWhitespace($s->{"a"})
ABresult
0X0
100
111
228 20 $s->{b} = _get($s);
229 20 $s->{c} = _get($s);
230 20 $s->{d} = _get($s);
231 20 $s->{return_flag} = 0;
232 20 $s->{return_string} = '';
233 20 $s->{last} = undef; # assign for safety
234 20 $s->{lastnws} = undef; # assign for safety
235  
236 # local variables
237 20 my $ccFlag; # marks if a comment is an Internet Explorer conditional comment and should be printed to output
238  
239 20 ▶ while (defined($s->{a})) { # on this line $s->{a} should always be a non-whitespace character or undef (i.e. end of file)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"a"}) 460 20 480
240  
241 460 ▶ if (isWhitespace($s->{a})) { # check that this program is running correctly
Branch: 1 branch
BranchTrueFalseTotal
if (isWhitespace($s->{"a"})) 0 460 460
242 0 die 'minifier bug: minify while loop starting with whitespace, stopped';
243 }
244  
245 # track 'return' operator
246 460 ▶ if ($s->{a} ne '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"a"} ne "/") 365 95 460
247 365 ▶ $s->{return_flag} = defined($return[length($s->{return_string})]) && $s->{a} eq $return[length($s->{return_string})];
Condition66%2/3
defined $return[length $s->{'return_string'}] && $s->{'a'} eq $return[length $s->{'return_string'}]
!ll&&!rl&&r
034718
MC/DC50%1/2
defined $return[length $s->{'return_string'}] && $s->{'a'} eq $return[length $s->{'return_string'}]
defined $return[length $s->{'return_string'}] $s->{'a'} eq $return[length $s->{'return_string'}]
Truth table66%2/3
A && B
A= defined $return[length $s->{'return_string'}]B= $s->{'a'} eq $return[length $s->{'return_string'}]
ABresult
0X0
100
111
248 365 ▶ $s->{return_string} = $s->{return_flag} ? $s->{return_string} . $s->{a} : '';
Branch: 1 branch
BranchTrueFalseTotal
$s->{'return_flag'} ? : 18 347 365
249 }
250  
251 # Each branch handles trailing whitespace and ensures $s->{a} is on non-whitespace or undef when branch finishes
252 460 ▶ if ($s->{a} eq '/') { # a division, comment, or regexp literal
Branch: 6 branches
BranchTrueFalseTotal
if ($s->{'a'} eq '/') { } 95 365 460
elsif ($s->{'a'} eq q['] or $s->{'a'} eq '"') { } 6 359 365
elsif ($s->{'a'} eq '+' or $s->{'a'} eq '-') { } 31 328 359
elsif (isAlphanum($s->{'a'})) { } 213 115 328
elsif ($s->{'a'} eq ']' or $s->{'a'} eq '}' or $s->{'a'} eq ')') { } 31 84 115
elsif ($s->{'stripDebug'} and $s->{'a'} eq ';' and defined $s->{'b'} and $s->{'b'} eq ';' and defined $s->{'c'} and $s->{'c'} eq ';') { } 1 83 84
253 95 ▶ if (defined($s->{b}) && $s->{b} eq '/') { # slash-slash comment
Branch: 3 branches
BranchTrueFalseTotal
if (defined $s->{'b'} and $s->{'b'} eq '/') { } 29 66 95
elsif (defined $s->{'b'} and $s->{'b'} eq '*') { } 38 28 66
elsif (defined $s->{'lastnws'} and $s->{'lastnws'} eq ')' || $s->{'lastnws'} eq ']' || $s->{'lastnws'} eq '.' || isAlphanum($s->{'lastnws'}) and !$s->{'return_flag'} || length $s->{'return_string'} != scalar @return) { } 19 9 28
Condition66%2/3
defined $s->{"b"} and $s->{"b"} eq "/"
!ll&&!rl&&r
06629
MC/DC50%1/2
defined $s->{"b"} and $s->{"b"} eq "/"
defined $s->{"b"} $s->{"b"} eq "/"
Truth table66%2/3
A and B
A= defined $s->{"b"}B= $s->{"b"} eq "/"
ABresult
0X0
100
111
254 29 ▶ $ccFlag = defined($s->{c}) && $s->{c} eq '@'; # tests in IE7 show no space allowed between slashes and at symbol
Condition66%2/3
defined $s->{'c'} && $s->{'c'} eq '@'
!ll&&!rl&&r
01514
MC/DC50%1/2
defined $s->{'c'} && $s->{'c'} eq '@'
defined $s->{'c'} $s->{'c'} eq '@'
Truth table66%2/3
A && B
A= defined $s->{'c'}B= $s->{'c'} eq '@'
ABresult
0X0
100
111
255 do {
256 156 ▶ $ccFlag ? action2($s) : action3($s);
Branch: 1 branch
BranchTrueFalseTotal
$ccFlag ? : 68 88 156
257 29 ▶ } until (!defined($s->{a}) || isEndspace($s->{a}));
Branch: 1 branch
BranchTrueFalseTotal
(not defined $s->{"a"} or isEndspace($s->{"a"})) or do { do { $ccFlag ? action2($s) : action3($s) } } 127 29 156
Condition66%2/3
not defined $s->{"a"} or isEndspace($s->{"a"})
l!l&&r!l&&!r
029127
MC/DC50%1/2
not defined $s->{"a"} or isEndspace($s->{"a"})
not defined $s->{"a"} isEndspace($s->{"a"})
Truth table66%2/3
not(A) or B
A= not defined $s->{"a"}B= isEndspace($s->{"a"})
ABresult
1X1
011
000
258 29 ▶ if (defined($s->{a})) { # $s->{a} is a new line
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"a"}) 29 0 29
259 29 ▶ if ($ccFlag) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ccFlag) { } 14 15 29
elsif (defined $s->{'last'} and not isEndspace($s->{'last'}) and not isPrefix($s->{'last'})) { } 8 7 15
260 14 action1($s); # cannot use preserveEndspace($s) here because it might not print the new line
261 14 skipWhitespace($s);
262 }
263 ▶ elsif (defined($s->{last}) && !isEndspace($s->{last}) && !isPrefix($s->{last})) {
Condition100%6/6
defined $s->{"last"} and not isEndspace($s->{"last"}) and not isPrefix($s->{"last"})
!ll&&!rl&&r
258
defined $s->{"last"} and not isEndspace($s->{"last"})
!ll&&!rl&&r
1113
MC/DC100%3/3
defined $s->{"last"} and not isEndspace($s->{"last"}) and not isPrefix($s->{"last"})
defined $s->{"last"} not isEndspace($s->{"last"}) not isPrefix($s->{"last"})
Truth table100%4/4
A and not(B) and not(C)
A= defined $s->{"last"}B= not isEndspace($s->{"last"})C= not isPrefix($s->{"last"})
ABCresult
0XX0
10X0
1100
1111
264 8 preserveEndspace($s);
265 }
266 else {
267 7 skipWhitespace($s);
268 }
269 }
270 }
271 ▶ elsif (defined($s->{b}) && $s->{b} eq '*') { # slash-star comment
Condition66%2/3
defined $s->{"b"} and $s->{"b"} eq "*"
!ll&&!rl&&r
02838
MC/DC50%1/2
defined $s->{"b"} and $s->{"b"} eq "*"
defined $s->{"b"} $s->{"b"} eq "*"
Truth table66%2/3
A and B
A= defined $s->{"b"}B= $s->{"b"} eq "*"
ABresult
0X0
100
111
272 38 ▶ $ccFlag = defined($s->{c}) && $s->{c} eq '@'; # test in IE7 shows no space allowed between star and at symbol
Condition66%2/3
defined $s->{'c'} && $s->{'c'} eq '@'
!ll&&!rl&&r
02315
MC/DC50%1/2
defined $s->{'c'} && $s->{'c'} eq '@'
defined $s->{'c'} $s->{'c'} eq '@'
Truth table66%2/3
A && B
A= defined $s->{'c'}B= $s->{'c'} eq '@'
ABresult
0X0
100
111
273 do {
274 265 ▶ $ccFlag ? action2($s) : action3($s);
Branch: 1 branch
BranchTrueFalseTotal
$ccFlag ? : 67 198 265
275 38 ▶ } until (!defined($s->{b}) || ($s->{a} eq '*' && $s->{b} eq '/'));
Branch: 1 branch
BranchTrueFalseTotal
(not defined $s->{"b"} or $s->{"a"} eq "*" and $s->{"b"} eq "/") or do { do { $ccFlag ? action2($s) : action3($s) } } 227 38 265
Condition83%5/6
not defined $s->{"b"} or $s->{"a"} eq "*" and $s->{"b"} eq "/"
l!l&&r!l&&!r
0143122
$s->{"a"} eq "*" and $s->{"b"} eq "/"
!ll&&!rl&&r
1854238
MC/DC33%1/3
not defined $s->{"b"} or $s->{"a"} eq "*" and $s->{"b"} eq "/"
not defined $s->{"b"} $s->{"a"} eq "*" $s->{"b"} eq "/"
Truth table50%2/4
not(A) or B and C
A= not defined $s->{"b"}B= $s->{"a"} eq "*"C= $s->{"b"} eq "/"
ABCresult
1XX1
0111
00X0
0100
276 38 ▶ if (defined($s->{b})) { # $s->{a} is asterisk and $s->{b} is foreslash
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{'b'}) { } 38 0 38
277 38 ▶ if ($ccFlag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ccFlag) { } 15 23 38
278 15 action2($s); # the *
279 15 action2($s); # the /
280 # inside the conditional comment there may be a missing terminal semi-colon
281 15 preserveEndspace($s);
282 }
283 else { # the comment is being removed
284 23 action3($s); # the *
285 23 $s->{a} = ' '; # the /
286 23 collapseWhitespace($s);
287 23 ▶ if (defined($s->{last}) && defined($s->{b}) &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $s->{'last'} and defined $s->{'b'} and isAlphanum($s->{'last'}) && (isAlphanum($s->{'b'}) || $s->{'b'} eq '.') || $s->{'last'} eq '+' && $s->{'b'} eq '+' || $s->{'last'} eq '-' && $s->{'b'} eq '-') { } 4 19 23
elsif (defined $s->{'last'} and not isPrefix($s->{'last'})) { } 7 12 19
Condition87%21/24
defined $s->{"last"} and defined $s->{"b"} and isAlphanum($s->{"last"}) && (isAlphanum($s->{"b"}) || $s->{"b"} eq ".") || $s->{"last"} eq "+" && $s->{"b"} eq "+" || $s->{"last"} eq "-" && $s->{"b"} eq "-"
!ll&&!rl&&r
1184
defined $s->{"last"} and defined $s->{"b"}
!ll&&!rl&&r
1022
isAlphanum($s->{"last"}) and isAlphanum($s->{"b"}) || $s->{"b"} eq "." or $s->{"last"} eq "+" and $s->{"b"} eq "+" or $s->{"last"} eq "-" and $s->{"b"} eq "-"
l!l&&r!l&&!r
3118
isAlphanum($s->{"last"}) and isAlphanum($s->{"b"}) || $s->{"b"} eq "." or $s->{"last"} eq "+" and $s->{"b"} eq "+"
l!l&&r!l&&!r
2119
isAlphanum($s->{"last"}) and isAlphanum($s->{"b"}) || $s->{"b"} eq "."
!ll&&!rl&&r
1642
isAlphanum($s->{"b"}) or $s->{"b"} eq "."
l!l&&r!l&&!r
114
$s->{"last"} eq "+" and $s->{"b"} eq "+"
!ll&&!rl&&r
1901
$s->{"last"} eq "-" and $s->{"b"} eq "-"
!ll&&!rl&&r
1801
MC/DC66%6/9
defined $s->{"last"} and defined $s->{"b"} and isAlphanum($s->{"last"}) && (isAlphanum($s->{"b"}) || $s->{"b"} eq ".") || $s->{"last"} eq "+" && $s->{"b"} eq "+" || $s->{"last"} eq "-" && $s->{"b"} eq "-"
defined $s->{"last"} defined $s->{"b"} isAlphanum($s->{"last"}) isAlphanum($s->{"b"}) $s->{"b"} eq "." $s->{"last"} eq "+" $s->{"b"} eq "+" $s->{"last"} eq "-" $s->{"b"} eq "-"
Truth table38%7/18
A and B and C and D or E or F and G or H and I
A= defined $s->{"last"}B= defined $s->{"b"}C= isAlphanum($s->{"last"})D= isAlphanum($s->{"b"})E= $s->{"b"} eq "."F= $s->{"last"} eq "+"G= $s->{"b"} eq "+"H= $s->{"last"} eq "-"I= $s->{"b"} eq "-"
ABCDEFGHIresult
0XXXXXXXX0
10XXXXXXX0
110XX0X0X0
110XX0X100
110XX100X0
110XX10100
111000X0X0
111000X100
11100100X0
1110010100
1111XXXXX1
11101XXXX1
110XX11XX1
1110011XX1
110XX0X111
110XX10111
111000X111
1110010111
288 ((isAlphanum($s->{last}) && (isAlphanum($s->{b})||$s->{b} eq '.')) ||
289 ($s->{last} eq '+' && $s->{b} eq '+') || ($s->{last} eq '-' && $s->{b} eq '-'))) { # for a situation like 5-/**/-2 or a/**/a
290 # When entering this block $s->{a} is whitespace.
291 # The comment represented whitespace that cannot be removed. Therefore replace the now gone comment with a whitespace.
292 4 action1($s);
293 }
294 ▶ elsif (defined($s->{last}) && !isPrefix($s->{last})) {
Condition100%3/3
defined $s->{"last"} and not isPrefix($s->{"last"})
!ll&&!rl&&r
1117
MC/DC100%2/2
defined $s->{"last"} and not isPrefix($s->{"last"})
defined $s->{"last"} not isPrefix($s->{"last"})
Truth table100%3/3
A and not(B)
A= defined $s->{"last"}B= not isPrefix($s->{"last"})
ABresult
0X0
100
111
295 7 preserveEndspace($s);
296 }
297 else {
298 12 skipWhitespace($s);
299 }
300 }
301 }
302 else {
303 0 die 'unterminated comment, stopped';
304 }
305 }
306 ▶ elsif ((defined($s->{lastnws}) && ($s->{lastnws} eq ')' || $s->{lastnws} eq ']' ||
Condition66%12/18
defined $s->{"lastnws"} and $s->{"lastnws"} eq ")" || $s->{"lastnws"} eq "]" || $s->{"lastnws"} eq "." || isAlphanum($s->{"lastnws"}) and !$s->{"return_flag"} || length $s->{"return_string"} != scalar @return
!ll&&!rl&&r
9019
defined $s->{"lastnws"} and $s->{"lastnws"} eq ")" || $s->{"lastnws"} eq "]" || $s->{"lastnws"} eq "." || isAlphanum($s->{"lastnws"})
!ll&&!rl&&r
0919
$s->{"lastnws"} eq ")" or $s->{"lastnws"} eq "]" or $s->{"lastnws"} eq "." or isAlphanum($s->{"lastnws"})
l!l&&r!l&&!r
1189
$s->{"lastnws"} eq ")" or $s->{"lastnws"} eq "]" or $s->{"lastnws"} eq "."
l!l&&r!l&&!r
1027
$s->{"lastnws"} eq ")" or $s->{"lastnws"} eq "]"
l!l&&r!l&&!r
0127
not $s->{"return_flag"} or length $s->{"return_string"} != scalar @return
l!l&&r!l&&!r
1900
MC/DC28%2/7
defined $s->{"lastnws"} and $s->{"lastnws"} eq ")" || $s->{"lastnws"} eq "]" || $s->{"lastnws"} eq "." || isAlphanum($s->{"lastnws"}) and !$s->{"return_flag"} || length $s->{"return_string"} != scalar @return
defined $s->{"lastnws"} $s->{"lastnws"} eq ")" $s->{"lastnws"} eq "]" $s->{"lastnws"} eq "." isAlphanum($s->{"lastnws"}) not $s->{"return_flag"} length $s->{"return_string"} != scalar @return
Truth table21%3/14
A and B or C or D or E and not(F) or G
A= defined $s->{"lastnws"}B= $s->{"lastnws"} eq ")"C= $s->{"lastnws"} eq "]"D= $s->{"lastnws"} eq "."E= isAlphanum($s->{"lastnws"})F= not $s->{"return_flag"}G= length $s->{"return_string"} != scalar @return
ABCDEFGresult
0XXXXXX0
10000XX0
11XXX000
101XX000
1001X000
10001000
11XXX1X1
11XXX011
101XX1X1
101XX011
1001X1X1
1001X011
100011X1
10001011
307 $s->{lastnws} eq '.' || isAlphanum($s->{lastnws}))) && (!$s->{return_flag} || length($s->{return_string}) != scalar(@return))) { # division
308  
309 19 action1($s);
310 19 collapseWhitespace($s);
311 # don't want a division to become a slash-slash comment with following conditional comment
312 19 ▶ onWhitespaceConditionalComment($s) ? action1($s) : preserveEndspace($s);
Branch: 1 branch
BranchTrueFalseTotal
onWhitespaceConditionalComment($s) ? : 2 17 19
313 }
314 else { # regexp literal
315 9 putLiteral($s);
316 9 collapseWhitespace($s);
317 # don't want closing delimiter to become a slash-slash comment with following conditional comment
318 9 ▶ onWhitespaceConditionalComment($s) ? action1($s) : preserveEndspace($s);
Branch: 1 branch
BranchTrueFalseTotal
onWhitespaceConditionalComment($s) ? : 2 7 9
319 }
320 }
321 ▶ elsif ($s->{a} eq '\'' || $s->{a} eq '"' ) { # string literal
Condition100%3/3
$s->{"a"} eq "'" or $s->{"a"} eq "\""
l!l&&r!l&&!r
15359
MC/DC100%2/2
$s->{"a"} eq "'" or $s->{"a"} eq "\""
$s->{"a"} eq "'" $s->{"a"} eq "\""
Truth table100%3/3
A or B
A= $s->{"a"} eq "'"B= $s->{"a"} eq "\""
ABresult
1X1
011
000
322 6 putLiteral($s);
323 6 preserveEndspace($s);
324 }
325 ▶ elsif ($s->{a} eq '+' || $s->{a} eq '-') { # careful with + + and - -
Condition100%3/3
$s->{"a"} eq "+" or $s->{"a"} eq "-"
l!l&&r!l&&!r
1516328
MC/DC100%2/2
$s->{"a"} eq "+" or $s->{"a"} eq "-"
$s->{"a"} eq "+" $s->{"a"} eq "-"
Truth table100%3/3
A or B
A= $s->{"a"} eq "+"B= $s->{"a"} eq "-"
ABresult
1X1
011
000
326 31 action1($s);
327 31 collapseWhitespace($s);
328 31 ▶ if (defined($s->{a}) && isWhitespace($s->{a})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"a"} and isWhitespace($s->{"a"})) 4 27 31
Condition100%3/3
defined $s->{"a"} and isWhitespace($s->{"a"})
!ll&&!rl&&r
1264
MC/DC100%2/2
defined $s->{"a"} and isWhitespace($s->{"a"})
defined $s->{"a"} isWhitespace($s->{"a"})
Truth table100%3/3
A and B
A= defined $s->{"a"}B= isWhitespace($s->{"a"})
ABresult
0X0
100
111
329 4 ▶ (defined($s->{b}) && $s->{b} eq $s->{last}) ? action1($s) : preserveEndspace($s);
Branch: 1 branch
BranchTrueFalseTotal
defined $s->{'b'} && $s->{'b'} eq $s->{'last'} ? : 2 2 4
Condition66%2/3
defined $s->{"b"} and $s->{"b"} eq $s->{"last"}
!ll&&!rl&&r
022
MC/DC50%1/2
defined $s->{"b"} and $s->{"b"} eq $s->{"last"}
defined $s->{"b"} $s->{"b"} eq $s->{"last"}
Truth table66%2/3
A and B
A= defined $s->{"b"}B= $s->{"b"} eq $s->{"last"}
ABresult
0X0
100
111
330 }
331 }
332 elsif (isAlphanum($s->{a})) { # keyword, identifiers, numbers
333 213 action1($s);
334 213 collapseWhitespace($s);
335 213 ▶ if (defined($s->{a}) && isWhitespace($s->{a})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"a"} and isWhitespace($s->{"a"})) 49 164 213
Condition100%3/3
defined $s->{"a"} and isWhitespace($s->{"a"})
!ll&&!rl&&r
515949
MC/DC100%2/2
defined $s->{"a"} and isWhitespace($s->{"a"})
defined $s->{"a"} isWhitespace($s->{"a"})
Truth table100%3/3
A and B
A= defined $s->{"a"}B= isWhitespace($s->{"a"})
ABresult
0X0
100
111
336 # if $s->{b} is '.' could be (12 .toString()) which is property invocation. If space removed becomes decimal point and error.
337 49 ▶ (defined($s->{b}) && (isAlphanum($s->{b}) || $s->{b} eq '.')) ? action1($s) : preserveEndspace($s);
Branch: 1 branch
BranchTrueFalseTotal
defined $s->{'b'} && (isAlphanum($s->{'b'}) || $s->{'b'} eq '.') ? : 17 32 49
Condition83%5/6
defined $s->{"b"} and isAlphanum($s->{"b"}) || $s->{"b"} eq "."
!ll&&!rl&&r
03217
isAlphanum($s->{"b"}) or $s->{"b"} eq "."
l!l&&r!l&&!r
16132
MC/DC66%2/3
defined $s->{"b"} and isAlphanum($s->{"b"}) || $s->{"b"} eq "."
defined $s->{"b"} isAlphanum($s->{"b"}) $s->{"b"} eq "."
Truth table75%3/4
A and B or C
A= defined $s->{"b"}B= isAlphanum($s->{"b"})C= $s->{"b"} eq "."
ABCresult
0XX0
1000
11X1
1011
338 }
339 }
340 ▶ elsif ($s->{a} eq ']' || $s->{a} eq '}' || $s->{a} eq ')') { # no need to be followed by space but maybe needs following new line
Condition100%6/6
$s->{"a"} eq "]" or $s->{"a"} eq "}" or $s->{"a"} eq ")"
l!l&&r!l&&!r
171484
$s->{"a"} eq "]" or $s->{"a"} eq "}"
l!l&&r!l&&!r
71098
MC/DC100%3/3
$s->{"a"} eq "]" or $s->{"a"} eq "}" or $s->{"a"} eq ")"
$s->{"a"} eq "]" $s->{"a"} eq "}" $s->{"a"} eq ")"
Truth table100%4/4
A or B or C
A= $s->{"a"} eq "]"B= $s->{"a"} eq "}"C= $s->{"a"} eq ")"
ABCresult
1XX1
01X1
0011
0000
341 31 action1($s);
342 31 preserveEndspace($s);
343 }
344 ▶ elsif ($s->{stripDebug} && $s->{a} eq ';' &&
Condition86%13/15
$s->{"stripDebug"} and $s->{"a"} eq ";" and defined $s->{"b"} and $s->{"b"} eq ";" and defined $s->{"c"} and $s->{"c"} eq ";"
!ll&&!rl&&r
8301
$s->{"stripDebug"} and $s->{"a"} eq ";" and defined $s->{"b"} and $s->{"b"} eq ";" and defined $s->{"c"}
!ll&&!rl&&r
8301
$s->{"stripDebug"} and $s->{"a"} eq ";" and defined $s->{"b"} and $s->{"b"} eq ";"
!ll&&!rl&&r
8211
$s->{"stripDebug"} and $s->{"a"} eq ";" and defined $s->{"b"}
!ll&&!rl&&r
8112
$s->{"stripDebug"} and $s->{"a"} eq ";"
!ll&&!rl&&r
7923
MC/DC66%4/6
$s->{"stripDebug"} and $s->{"a"} eq ";" and defined $s->{"b"} and $s->{"b"} eq ";" and defined $s->{"c"} and $s->{"c"} eq ";"
$s->{"stripDebug"} $s->{"a"} eq ";" defined $s->{"b"} $s->{"b"} eq ";" defined $s->{"c"} $s->{"c"} eq ";"
Truth table71%5/7
A and B and C and D and E and F
A= $s->{"stripDebug"}B= $s->{"a"} eq ";"C= defined $s->{"b"}D= $s->{"b"} eq ";"E= defined $s->{"c"}F= $s->{"c"} eq ";"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
345 defined($s->{b}) && $s->{b} eq ';' &&
346 defined($s->{c}) && $s->{c} eq ';') {
347 1 action3($s); # delete one of the semi-colons
348 1 $s->{a} = '/'; # replace the other two semi-colons
349 1 $s->{b} = '/'; # so the remainder of line is removed
350 }
351 else { # anything else just prints and trailing whitespace discarded
352 83 action1($s);
353 83 skipWhitespace($s);
354 }
355 }
356  
357 20 ▶ if ( defined $s->{last_read_char} and $s->{last_read_char} =~ /\n/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"last_read_char"} and $s->{"last_read_char"} =~ /\n/) 2 18 20
Condition66%2/3
defined $s->{"last_read_char"} and $s->{"last_read_char"} =~ /\n/
!ll&&!rl&&r
0182
MC/DC50%1/2
defined $s->{"last_read_char"} and $s->{"last_read_char"} =~ /\n/
defined $s->{"last_read_char"} $s->{"last_read_char"} =~ /\n/
Truth table66%2/3
A and B
A= defined $s->{"last_read_char"}B= $s->{"last_read_char"} =~ /\n/
ABresult
0X0
100
111
358 2 _put($s, "\n");
359 }
360  
361 20 ▶ if (!defined($s->{outfile})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $s->{"outfile"}) 5 15 20
362 5 return $s->{output};
363 }
364  
365 } # minify()
366  
367 4 1;
368 __END__
↑ Summary