resourceloader: Remove unused code from mw.loader.register()
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 24 Aug 2018 02:31:48 +0000 (03:31 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Sun, 26 Aug 2018 04:25:16 +0000 (05:25 +0100)
The optional 'dependencies' parameter is only ever used with
an array of strings, never just as a string.

Also fix the missing square-brackets around the parameter name
in the documentation that indicate the parameter as optional.
The code was already allowing it to be missing, and the server
does indeed omit it when a module has no dependencies.
(See ResourceLoaderStartupModuleTest for confirmation of that).

The server-side methods ResourceLoaderModule::getDependencies
and ResourceLoader::makeLoaderRegisterScript already don't
support string-type for this parameter.

Change-Id: I80a1e4b2eefb62e669c031e0d953bf74a9623264

resources/src/startup/mediawiki.js

index 8ad2588..0aa15db 100644 (file)
                                 *  a list of arguments compatible with this method
                                 * @param {string|number} version Module version hash (falls backs to empty string)
                                 *  Can also be a number (timestamp) for compatibility with MediaWiki 1.25 and earlier.
-                                * @param {string|Array} dependencies One string or array of strings of module
-                                *  names on which this module depends.
+                                * @param {string[]} [dependencies] Array of module names on which this module depends.
                                 * @param {string} [group=null] Group which the module is in
                                 * @param {string} [source='local'] Name of the source
                                 * @param {string} [skip=null] Script body of the skip function
                                 */
                                register: function ( module, version, dependencies, group, source, skip ) {
-                                       var i, deps;
+                                       var i;
                                        // Allow multiple registration
                                        if ( typeof module === 'object' ) {
                                                resolveIndexedDependencies( module );
                                        if ( hasOwn.call( registry, module ) ) {
                                                throw new Error( 'module already registered: ' + module );
                                        }
-                                       if ( typeof dependencies === 'string' ) {
-                                               // A single module name
-                                               deps = [ dependencies ];
-                                       } else if ( typeof dependencies === 'object' ) {
-                                               // Array of module names
-                                               deps = dependencies;
-                                       }
                                        // List the module as registered
                                        registry[ module ] = {
                                                // Exposed to execute() for mw.loader.implement() closures.
                                                        exports: {}
                                                },
                                                version: String( version || '' ),
-                                               dependencies: deps || [],
+                                               dependencies: dependencies || [],
                                                group: typeof group === 'string' ? group : null,
                                                source: typeof source === 'string' ? source : 'local',
                                                state: 'registered',