resourceloader: Add minified version of mw.loader.implement() wrapper
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 29 Jan 2018 23:30:23 +0000 (15:30 -0800)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 29 Jan 2018 23:30:23 +0000 (15:30 -0800)
Follows-up b7eb243d92, which changed minification to be per-module,
but had as result that the little implement() wrapper is not always
minified, e.g. when outputting modules that have minification disabled
(such as 'user.tokens' and 'user.options').

Rather than introducing some complex minification cache for the
wrapper (with a find and replace for the variable content), simply
add a hardcoded minified version of the wrapper.

Change-Id: Iccf0d3408beab4387031cc55689394ff67e1e64b

includes/resourceloader/ResourceLoader.php

index 36bf656..ef26d1e 100644 (file)
@@ -1227,7 +1227,11 @@ MESSAGE;
                $name, $scripts, $styles, $messages, $templates
        ) {
                if ( $scripts instanceof XmlJsCode ) {
-                       $scripts = new XmlJsCode( "function ( $, jQuery, require, module ) {\n{$scripts->value}\n}" );
+                       if ( self::inDebugMode() ) {
+                               $scripts = new XmlJsCode( "function ( $, jQuery, require, module ) {\n{$scripts->value}\n}" );
+                       } else {
+                               $scripts = new XmlJsCode( 'function($,jQuery,require,module){'. $scripts->value . '}' );
+                       }
                } elseif ( !is_string( $scripts ) && !is_array( $scripts ) ) {
                        throw new MWException( 'Invalid scripts error. Array of URLs or string of code expected.' );
                }