| @@ 196-213 (lines=18) @@ | ||
| 193 | /** |
|
| 194 | * Strip comments from source code. |
|
| 195 | */ |
|
| 196 | protected function stripComments() |
|
| 197 | { |
|
| 198 | // PHP only supports $this inside anonymous functions since 5.4 |
|
| 199 | $minifier = $this; |
|
| 200 | $callback = function ($match) use ($minifier) { |
|
| 201 | $count = count($minifier->extracted); |
|
| 202 | $placeholder = '/*'.$count.'*/'; |
|
| 203 | $minifier->extracted[$placeholder] = $match[0]; |
|
| 204 | ||
| 205 | return $placeholder; |
|
| 206 | }; |
|
| 207 | // multi-line comments |
|
| 208 | $this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback); |
|
| 209 | $this->registerPattern('/\/\*.*?\*\//s', ''); |
|
| 210 | ||
| 211 | // single-line comments |
|
| 212 | $this->registerPattern('/\/\/.*$/m', ''); |
|
| 213 | } |
|
| 214 | ||
| 215 | /** |
|
| 216 | * JS can have /-delimited regular expressions, like: /ab+c/.match(string). |
|
| @@ 629-643 (lines=15) @@ | ||
| 626 | /** |
|
| 627 | * Strip comments from source code. |
|
| 628 | */ |
|
| 629 | protected function stripComments() |
|
| 630 | { |
|
| 631 | // PHP only supports $this inside anonymous functions since 5.4 |
|
| 632 | $minifier = $this; |
|
| 633 | $callback = function ($match) use ($minifier) { |
|
| 634 | $count = count($minifier->extracted); |
|
| 635 | $placeholder = '/*'.$count.'*/'; |
|
| 636 | $minifier->extracted[$placeholder] = $match[0]; |
|
| 637 | ||
| 638 | return $placeholder; |
|
| 639 | }; |
|
| 640 | $this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback); |
|
| 641 | ||
| 642 | $this->registerPattern('/\/\*.*?\*\//s', ''); |
|
| 643 | } |
|
| 644 | ||
| 645 | /** |
|
| 646 | * Strip whitespace. |
|