mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-79663 libraries: upgrade to version 1.3.71 of Minify.
This commit is contained in:
parent
513f3b02c7
commit
f0efcf9494
@ -632,46 +632,7 @@ class CSS extends Minify
|
||||
*/
|
||||
protected function stripComments()
|
||||
{
|
||||
// PHP only supports $this inside anonymous functions since 5.4
|
||||
$minifier = $this;
|
||||
$callback = function ($match) use ($minifier) {
|
||||
$count = count($minifier->extracted);
|
||||
$placeholder = '/*' . $count . '*/';
|
||||
$minifier->extracted[$placeholder] = $match[0];
|
||||
|
||||
return $placeholder;
|
||||
};
|
||||
// Moodle-specific change MDL-68191 starts.
|
||||
/* This was the old code:
|
||||
$this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
|
||||
*/
|
||||
// This is the new, more accurate and faster regex.
|
||||
$this->registerPattern('/
|
||||
# optional newline
|
||||
\n?
|
||||
|
||||
# start comment
|
||||
\/\*
|
||||
|
||||
# comment content
|
||||
(?:
|
||||
# either starts with an !
|
||||
!
|
||||
|
|
||||
# or, after some number of characters which do not end the comment
|
||||
(?:(?!\*\/).)*?
|
||||
|
||||
# there is either a @license or @preserve tag
|
||||
@(?:license|preserve)
|
||||
)
|
||||
|
||||
# then match to the end of the comment
|
||||
.*?\*\/\n?
|
||||
|
||||
/ixs', $callback);
|
||||
// Moodle-specific change MDL-68191.
|
||||
|
||||
$this->registerPattern('/\/\*.*?\*\//s', '');
|
||||
$this->stripMultilineComments();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -198,28 +198,7 @@ class JS extends Minify
|
||||
*/
|
||||
protected function stripComments()
|
||||
{
|
||||
// PHP only supports $this inside anonymous functions since 5.4
|
||||
$minifier = $this;
|
||||
$callback = function ($match) use ($minifier) {
|
||||
if (
|
||||
substr($match[2], 0, 1) === '!' ||
|
||||
strpos($match[2], '@license') !== false ||
|
||||
strpos($match[2], '@preserve') !== false
|
||||
) {
|
||||
// preserve multi-line comments that start with /*!
|
||||
// or contain @license or @preserve annotations
|
||||
$count = count($minifier->extracted);
|
||||
$placeholder = '/*' . $count . '*/';
|
||||
$minifier->extracted[$placeholder] = $match[0];
|
||||
|
||||
return $match[1] . $placeholder . $match[3];
|
||||
}
|
||||
|
||||
return $match[1] . $match[3];
|
||||
};
|
||||
|
||||
// multi-line comments
|
||||
$this->registerPattern('/(\n?)\/\*(.*?)\*\/(\n?)/s', $callback);
|
||||
$this->stripMultilineComments();
|
||||
|
||||
// single-line comments
|
||||
$this->registerPattern('/\/\/.*$/m', '');
|
||||
|
@ -260,6 +260,49 @@ abstract class Minify
|
||||
$this->patterns[] = array($pattern, $replacement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Both JS and CSS use the same form of multi-line comment, so putting the common code here.
|
||||
*/
|
||||
protected function stripMultilineComments()
|
||||
{
|
||||
// First extract comments we want to keep, so they can be restored later
|
||||
// PHP only supports $this inside anonymous functions since 5.4
|
||||
$minifier = $this;
|
||||
$callback = function ($match) use ($minifier) {
|
||||
$count = count($minifier->extracted);
|
||||
$placeholder = '/*'.$count.'*/';
|
||||
$minifier->extracted[$placeholder] = $match[0];
|
||||
|
||||
return $placeholder;
|
||||
};
|
||||
$this->registerPattern('/
|
||||
# optional newline
|
||||
\n?
|
||||
|
||||
# start comment
|
||||
\/\*
|
||||
|
||||
# comment content
|
||||
(?:
|
||||
# either starts with an !
|
||||
!
|
||||
|
|
||||
# or, after some number of characters which do not end the comment
|
||||
(?:(?!\*\/).)*?
|
||||
|
||||
# there is either a @license or @preserve tag
|
||||
@(?:license|preserve)
|
||||
)
|
||||
|
||||
# then match to the end of the comment
|
||||
.*?\*\/\n?
|
||||
|
||||
/ixs', $callback);
|
||||
|
||||
// Then strip all other comments
|
||||
$this->registerPattern('/\/\*.*?\*\//s', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* We can't "just" run some regular expressions against JavaScript: it's a
|
||||
* complex language. E.g. having an occurrence of // xyz would be a comment,
|
||||
|
@ -15,10 +15,4 @@ mv path-converter-A.B.C/src/ /path/to/moodle/lib/minify/matthiasmullie-pathconve
|
||||
|
||||
3) Apply the following patches:
|
||||
|
||||
MDL-68191: https://github.com/matthiasmullie/minify/issues/317 is a bug that stops
|
||||
large sections of the CSS from being minimised, and also is a huge performance drain.
|
||||
We have applied the fix sent upstream because the performance win is so big.
|
||||
(E.g. one case I measured, with the bug was 40 seconds to minify CSS, with the fix was
|
||||
a few seconds. This is one of the reasons Behat runs in the browser are so slow.)
|
||||
Whenever this library is updated check if the fix is included and remove this note.
|
||||
NOTE: As of 2020/12/08, only the first commit was brought into Moodle
|
||||
N/A
|
||||
|
@ -82,7 +82,7 @@
|
||||
<location>minify/matthiasmullie-minify</location>
|
||||
<name>MatthiasMullie\Minify</name>
|
||||
<description>CSS & JavaScript minifier, in PHP</description>
|
||||
<version>1.3.70</version>
|
||||
<version>1.3.71</version>
|
||||
<license>MIT</license>
|
||||
<repository>https://github.com/matthiasmullie/minify</repository>
|
||||
<customised/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user