File tree 5 files changed +47
-70
lines changed
matthiasmullie-minify/src
5 files changed +47
-70
lines changed Original file line number Diff line number Diff line change @@ -632,46 +632,7 @@ protected function stripEmptyTags($content)
632
632
*/
633
633
protected function stripComments ()
634
634
{
635
- // PHP only supports $this inside anonymous functions since 5.4
636
- $ minifier = $ this ;
637
- $ callback = function ($ match ) use ($ minifier ) {
638
- $ count = count ($ minifier ->extracted );
639
- $ placeholder = '/* ' . $ count . '*/ ' ;
640
- $ minifier ->extracted [$ placeholder ] = $ match [0 ];
641
-
642
- return $ placeholder ;
643
- };
644
- // Moodle-specific change MDL-68191 starts.
645
- /* This was the old code:
646
- $this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
647
- */
648
- // This is the new, more accurate and faster regex.
649
- $ this ->registerPattern ('/
650
- # optional newline
651
- \n?
652
-
653
- # start comment
654
- \/\*
655
-
656
- # comment content
657
- (?:
658
- # either starts with an !
659
- !
660
- |
661
- # or, after some number of characters which do not end the comment
662
- (?:(?!\*\/).)*?
663
-
664
- # there is either a @license or @preserve tag
665
- @(?:license|preserve)
666
- )
667
-
668
- # then match to the end of the comment
669
- .*?\*\/\n?
670
-
671
- /ixs ' , $ callback );
672
- // Moodle-specific change MDL-68191.
673
-
674
- $ this ->registerPattern ('/\/\*.*?\*\//s ' , '' );
635
+ $ this ->stripMultilineComments ();
675
636
}
676
637
677
638
/**
Original file line number Diff line number Diff line change @@ -198,28 +198,7 @@ public function execute($path = null)
198
198
*/
199
199
protected function stripComments ()
200
200
{
201
- // PHP only supports $this inside anonymous functions since 5.4
202
- $ minifier = $ this ;
203
- $ callback = function ($ match ) use ($ minifier ) {
204
- if (
205
- substr ($ match [2 ], 0 , 1 ) === '! ' ||
206
- strpos ($ match [2 ], '@license ' ) !== false ||
207
- strpos ($ match [2 ], '@preserve ' ) !== false
208
- ) {
209
- // preserve multi-line comments that start with /*!
210
- // or contain @license or @preserve annotations
211
- $ count = count ($ minifier ->extracted );
212
- $ placeholder = '/* ' . $ count . '*/ ' ;
213
- $ minifier ->extracted [$ placeholder ] = $ match [0 ];
214
-
215
- return $ match [1 ] . $ placeholder . $ match [3 ];
216
- }
217
-
218
- return $ match [1 ] . $ match [3 ];
219
- };
220
-
221
- // multi-line comments
222
- $ this ->registerPattern ('/(\n?)\/\*(.*?)\*\/(\n?)/s ' , $ callback );
201
+ $ this ->stripMultilineComments ();
223
202
224
203
// single-line comments
225
204
$ this ->registerPattern ('/\/\/.*$/m ' , '' );
Original file line number Diff line number Diff line change @@ -260,6 +260,49 @@ protected function registerPattern($pattern, $replacement = '')
260
260
$ this ->patterns [] = array ($ pattern , $ replacement );
261
261
}
262
262
263
+ /**
264
+ * Both JS and CSS use the same form of multi-line comment, so putting the common code here.
265
+ */
266
+ protected function stripMultilineComments ()
267
+ {
268
+ // First extract comments we want to keep, so they can be restored later
269
+ // PHP only supports $this inside anonymous functions since 5.4
270
+ $ minifier = $ this ;
271
+ $ callback = function ($ match ) use ($ minifier ) {
272
+ $ count = count ($ minifier ->extracted );
273
+ $ placeholder = '/* ' .$ count .'*/ ' ;
274
+ $ minifier ->extracted [$ placeholder ] = $ match [0 ];
275
+
276
+ return $ placeholder ;
277
+ };
278
+ $ this ->registerPattern ('/
279
+ # optional newline
280
+ \n?
281
+
282
+ # start comment
283
+ \/\*
284
+
285
+ # comment content
286
+ (?:
287
+ # either starts with an !
288
+ !
289
+ |
290
+ # or, after some number of characters which do not end the comment
291
+ (?:(?!\*\/).)*?
292
+
293
+ # there is either a @license or @preserve tag
294
+ @(?:license|preserve)
295
+ )
296
+
297
+ # then match to the end of the comment
298
+ .*?\*\/\n?
299
+
300
+ /ixs ' , $ callback );
301
+
302
+ // Then strip all other comments
303
+ $ this ->registerPattern ('/\/\*.*?\*\//s ' , '' );
304
+ }
305
+
263
306
/**
264
307
* We can't "just" run some regular expressions against JavaScript: it's a
265
308
* complex language. E.g. having an occurrence of // xyz would be a comment,
Original file line number Diff line number Diff line change @@ -15,10 +15,4 @@ mv path-converter-A.B.C/src/ /path/to/moodle/lib/minify/matthiasmullie-pathconve
15
15
16
16
3) Apply the following patches:
17
17
18
- MDL-68191: https://github.com/matthiasmullie/minify/issues/317 is a bug that stops
19
- large sections of the CSS from being minimised, and also is a huge performance drain.
20
- We have applied the fix sent upstream because the performance win is so big.
21
- (E.g. one case I measured, with the bug was 40 seconds to minify CSS, with the fix was
22
- a few seconds. This is one of the reasons Behat runs in the browser are so slow.)
23
- Whenever this library is updated check if the fix is included and remove this note.
24
- NOTE: As of 2020/12/08, only the first commit was brought into Moodle
18
+ N/A
Original file line number Diff line number Diff line change 82
82
<location >minify/matthiasmullie-minify</location >
83
83
<name >MatthiasMullie\Minify</name >
84
84
<description >CSS & JavaScript minifier, in PHP</description >
85
- <version >1.3.70 </version >
85
+ <version >1.3.71 </version >
86
86
<license >MIT</license >
87
87
<repository >https://github.com/matthiasmullie/minify</repository >
88
88
<customised />
You can’t perform that action at this time.
0 commit comments