MDL-75012 js: Drop support for modules built pre-babel

We now include more polyfills than we have ever done, and some of these
cause false-positives on our code to address modules which do not have a
name.

We started adding module names to modules in Moodle 3.8 at _build_ time
and kept support for modules which were not transpiled using Babel
before that point.

We no longer need to support this as all pre-3.8 Moodle versions are
long out of support. The most recent to go out of support was Moodle
3.5, which went completely out of support in May 2021.

We should not support code written and minified without a transpilation
phase from this time any longer.
This commit is contained in:
Andrew Nicols
2023-03-02 11:55:31 +08:00
parent 784098fe9e
commit 84c650489a
2 changed files with 13 additions and 17 deletions
+11 -17
View File
@@ -104,13 +104,12 @@ if ($rev > 0 and $rev < (time() + 60 * 60)) {
$js = rtrim($js);
$js .= "\n";
if (preg_match('/define\(\s*(\[|function)/', $js)) {
// If the JavaScript module has been defined without specifying a name then we'll
// add the Moodle module name now.
$replace = 'define(\'' . $modulename . '\', ';
$search = 'define(';
// Replace only the first occurrence.
$js = implode($replace, explode($search, $js, 2));
if (!preg_match('/define\(\s*["\']/', $js)) {
$shortfilename = str_replace($CFG->dirroot, '', $jsfile);
error_log(
"JS file: '{$shortfilename}' cannot be loaded, or does not contain a javascript" .
' module in AMD format. "define()" not found.'
);
}
$content .= $js;
@@ -157,16 +156,11 @@ if (!empty($jsfiles)) {
$js = rtrim($js);
}
if (preg_match('/define\(\s*(\[|function)/', $js)) {
// If the JavaScript module has been defined without specifying a name then we'll
// add the Moodle module name now.
$replace = 'define(\'' . $modulename . '\', ';
// Replace only the first occurrence.
$js = implode($replace, explode('define(', $js, 2));
} else if (!preg_match('/define\s*\(/', $js)) {
debugging('JS file: ' . $shortfilename . ' cannot be loaded, or does not contain a javascript' .
' module in AMD format. "define()" not found.', DEBUG_DEVELOPER);
if (!preg_match('/define\(\s*["\']/', $js)) {
error_log(
"JS file: '{$shortfilename}' cannot be loaded, or does not contain a javascript" .
' module in AMD format. "define()" not found.'
);
}
js_send_uncached($js, 'requirejs.php');
+2
View File
@@ -72,6 +72,8 @@ information provided here is intended especially for developers.
* The core/modal module and all their versions (SAVE_CANCEL, DELETE_CANCEL...) now has a setButtonDisable to disable or enable
specific modal action buttons. This function allows developers to have modals that could only be submited if the user do some
action in the modal body like ticking a checkbox or selecting an element.
* Support for serving of AMD modules built in really old versions of Moodle (<= 3.8) has been removed.
Please ensure that your AMD modules have been rebuilt with a supported Moodle version.
=== 4.1 ===