resourceloader: Ignore warnings in JSMinPlus parser
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 13 Feb 2019 01:45:56 +0000 (01:45 +0000)
committerKrinkle <krinklemail@gmail.com>
Wed, 13 Feb 2019 02:11:37 +0000 (02:11 +0000)
It's old and unmaintained. The only thing we care about is if it
was able to parse the script and if not, what its error is. Its
return value or broken inner workings are insignificant at this
point and only cause noise.

Bug: T77169
Change-Id: Ie357ccfcc6141f894b452eb3996e168c1526990f

includes/resourceloader/ResourceLoaderModule.php

index ae79dda..b392625 100644 (file)
@@ -956,16 +956,25 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface {
                        $cache::TTL_WEEK,
                        function () use ( $contents, $fileName ) {
                                $parser = self::javaScriptParser();
+                               $err = null;
                                try {
+                                       Wikimedia\suppressWarnings();
                                        $parser->parse( $contents, $fileName, 1 );
-                                       $result = $contents;
                                } catch ( Exception $e ) {
-                                       // We'll save this to cache to avoid having to re-validate broken JS
-                                       $err = $e->getMessage();
-                                       $result = "mw.log.error(" .
-                                               Xml::encodeJsVar( "JavaScript parse error: $err" ) . ");";
+                                       $err = $e;
+                               } finally {
+                                       Wikimedia\restoreWarnings();
                                }
-                               return $result;
+                               if ( $err ) {
+                                       // Send the error to the browser console client-side.
+                                       // By returning this as replacement for the actual script,
+                                       // we ensure modules are safe to load in a batch request,
+                                       // without causing other unrelated modules to break.
+                                       return 'mw.log.error(' .
+                                               Xml::encodeJsVar( 'JavaScript parse error: ' . $err->getMessage() ) .
+                                               ');';
+                               }
+                               return $contents;
                        }
                );
        }