From e856b6638c2e22d6eae70c04e137511380818f86 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 24 Aug 2018 03:31:48 +0100 Subject: [PATCH] resourceloader: Remove unused code from mw.loader.register() 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 | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/resources/src/startup/mediawiki.js b/resources/src/startup/mediawiki.js index 8ad2588d93..0aa15db840 100644 --- a/resources/src/startup/mediawiki.js +++ b/resources/src/startup/mediawiki.js @@ -1756,14 +1756,13 @@ * 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 ); @@ -1781,13 +1780,6 @@ 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. @@ -1796,7 +1788,7 @@ exports: {} }, version: String( version || '' ), - dependencies: deps || [], + dependencies: dependencies || [], group: typeof group === 'string' ? group : null, source: typeof source === 'string' ? source : 'local', state: 'registered', -- 2.20.1