Replace IIFE with block scope in ES6 code

Change-Id: I635f72a62ae44943a7705d28e92c9a0d265800b6
This commit is contained in:
Ed Sanders 2021-10-13 14:21:04 +01:00
parent ebeeed35bb
commit e1fb20d8be
8 changed files with 49 additions and 49 deletions

View file

@ -5,7 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
( function () {
{
const transclusionData = {
params: {
foo: { wt: 'Foo value' },
@ -27,13 +27,13 @@
*
* @return {ve.dm.MWTemplateModel}
*/
function newTemplateModel() {
const newTemplateModel = function () {
const doc = ve.dm.Document.static.newBlankDocument(),
transclusion = new ve.dm.MWTransclusionModel( doc ),
clonedTransclusionData = ve.extendObject( {}, transclusionData );
return ve.dm.MWTemplateModel.newFromData( transclusion, clonedTransclusionData );
}
};
/* Tests */
@ -508,4 +508,4 @@
} )
);
}() );
}

View file

@ -1,4 +1,4 @@
( function () {
{
QUnit.module( 've.dm.MWTemplateSpecModel' );
@ -6,7 +6,7 @@
* @param {string[]} [parameterNames]
* @return {ve.dm.MWTemplateModel} but it's a mock
*/
function createTemplateMock( parameterNames ) {
const createTemplateMock = function ( parameterNames ) {
const params = {};
( parameterNames || [] ).forEach( ( name ) => {
params[ name ] = {};
@ -21,7 +21,7 @@
return this.params;
}
};
}
};
QUnit.test( 'Basic behavior on empty template', ( assert ) => {
const template = createTemplateMock(),
@ -332,4 +332,4 @@
assert.strictEqual( spec.getParameterDeprecationDescription( 'p' ), '' );
} );
}() );
}

View file

@ -1,15 +1,15 @@
( function () {
{
QUnit.module( 've.dm.MWTransclusionContentModel' );
/**
* @return {ve.dm.MWTransclusionModel} but it's a mock
*/
function createTransclusionModel() {
const createTransclusionModel = function () {
return {
getUniquePartId: () => 0
};
}
};
[
[ undefined, false ],
@ -26,4 +26,4 @@
} )
);
}() );
}

View file

@ -4,7 +4,7 @@
* @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
*/
( function () {
{
QUnit.module( 've.dm.MWTransclusionModel', QUnit.newMwEnvironment( {
beforeEach() {
// Mock XHR for mw.Api()
@ -18,7 +18,7 @@
}
} ) );
function runAddPartTest( assert, name, response, server, callback ) {
const runAddPartTest = function ( assert, name, response, server, callback ) {
const doc = ve.dm.Document.static.newBlankDocument(),
transclusion = new ve.dm.MWTransclusionModel( doc ),
part = ve.dm.MWTemplateModel.newFromName( transclusion, name ),
@ -33,7 +33,7 @@
.always( () => {
done();
} );
}
};
QUnit.test( 'getUniquePartId', function ( assert ) {
const transclusion = new ve.dm.MWTransclusionModel();
@ -126,4 +126,4 @@
assert.deepEqual( spec.getKnownParameterNames(), [] );
} );
} );
}() );
}

View file

@ -4,7 +4,7 @@
* @copyright 2021 VisualEditor Team and others; see http://ve.mit-license.org
*/
( function () {
{
QUnit.module( 've.ui.MWTransclusionDialog', QUnit.newMwEnvironment( {
beforeEach() {
ve.test.utils.mwEnvironment.beforeEach.call( this );
@ -23,7 +23,7 @@
}
} ) );
function createFragmentFromDoc( doc ) {
const createFragmentFromDoc = function ( doc ) {
// convert doc to something ui magical
const surface = new ve.dm.Surface( doc );
// VE block from surface
@ -31,7 +31,7 @@
// return fragment as data for the dialog
return { fragment: fragment };
}
};
QUnit.test.skip( 'onReplacePart', ( assert ) => {
// don't kill test until this promise is resolved, to allow the async workflow to complete
@ -87,13 +87,13 @@
// change transclusion model (onReplacePart happens automatically)
const promise = transclusion.addPart( template );
promise.done( function () {
// checking for parameter checkboxes
// (should be 3 because of 2 predefined and 1 undocumented)
assert.strictEqual(
dialog.$element.find( '.ve-ui-mwTransclusionOutlineParameterWidget' ).length, 3
);
dialog.close();
promise.done( () => {
// checking for parameter checkboxes
// (should be 3 because of 2 predefined and 1 undocumented)
assert.strictEqual(
dialog.$element.find( '.ve-ui-mwTransclusionOutlineParameterWidget' ).length, 3
);
dialog.close();
} );
} ).fail( () => {
@ -101,9 +101,9 @@
finishTest();
} );
windowInstance.closed.then( function () {
windowInstance.closed.then( () => {
assert.ok( true );
finishTest();
} );
} );
}() );
}

View file

@ -1,10 +1,10 @@
( function () {
{
/**
* @param {string[]} [knownParameters]
* @return {ve.dm.MWTemplateModel} but it's a mock
*/
function makeTemplateMock( knownParameters ) {
const makeTemplateMock = function ( knownParameters ) {
const spec = {
getKnownParameterNames: () => knownParameters || [],
getParameterLabel: () => '',
@ -17,7 +17,7 @@
getSpec: () => spec,
hasParameter: () => false
};
}
};
QUnit.module( 've.ui.MWParameterSearchWidget' );
@ -47,4 +47,4 @@
assert.strictEqual( items[ 1 ].getData().name, 'abbreviation' );
} );
}() );
}

View file

@ -1,9 +1,9 @@
( function () {
function enableCirrusSearchLookup( enabled ) {
{
const enableCirrusSearchLookup = function ( enabled ) {
const config = mw.config.get( 'wgVisualEditorConfig' );
config.cirrusSearchLookup = enabled !== false;
mw.config.set( 'wgVisualEditorConfig', config );
}
};
QUnit.module( 've.ui.MWTemplateTitleInputWidget', QUnit.newMwEnvironment( {
beforeEach: function () {
@ -180,4 +180,4 @@
'(redirectedfrom: Template:From)'
);
} );
}() );
}

View file

@ -5,10 +5,10 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
( function () {
function MWDummyTarget() {
{
const MWDummyTarget = function MWDummyTarget() {
MWDummyTarget.super.call( this );
}
};
OO.inheritClass( MWDummyTarget, ve.test.utils.DummyTarget );
MWDummyTarget.prototype.setDefaultMode = () => {};
MWDummyTarget.prototype.isSaveable = () => true;
@ -23,11 +23,11 @@
ve.test.utils.MWDummyTarget = MWDummyTarget;
function MWDummyPlatform() {
const MWDummyPlatform = function MWDummyPlatform() {
MWDummyPlatform.super.apply( this, arguments );
// Disable some API requests from platform
this.imageInfoCache = null;
}
};
OO.inheritClass( MWDummyPlatform, ve.init.mw.Platform );
MWDummyPlatform.prototype.getMessage = ( ...args ) => args.join( ',' );
MWDummyPlatform.prototype.getHtmlMessage = ( ...args ) => {
@ -44,7 +44,7 @@
};
ve.test.utils.MWDummyPlatform = MWDummyPlatform;
ve.test.utils.mwEnvironment = ( function () {
{
const setEditorPreference = mw.libs.ve.setEditorPreference,
dummySetEditorPreference = () => ve.createDeferred().resolve().promise(),
overrides = [
@ -68,7 +68,7 @@
// Unregister mwTarget
ve.init.target = coreTarget;
function setupOverrides() {
const setupOverrides = function () {
for ( let i = 0; i < overrides.length; i++ ) {
ve.dm.modelRegistry.register( overrides[ i ] );
}
@ -84,9 +84,9 @@
// Ensure the current target is appended to the current fixture
// eslint-disable-next-line no-jquery/no-global-selector
$( '#qunit-fixture' ).append( ve.init.target.$element );
}
};
function teardownOverrides() {
const teardownOverrides = function () {
for ( let i = 0; i < overrides.length; i++ ) {
ve.dm.modelRegistry.unregister( overrides[ i ] );
}
@ -99,16 +99,16 @@
ve.init.platform = corePlatform;
ve.init.target = coreTarget;
mw.libs.ve.setEditorPreference = setEditorPreference;
}
};
// On load, teardown overrides so the first core tests run correctly
teardownOverrides();
return {
ve.test.utils.mwEnvironment = {
beforeEach: setupOverrides,
afterEach: teardownOverrides
};
}() );
}
const getDomElementSummaryCore = ve.getDomElementSummary;
@ -131,4 +131,4 @@
}
return value;
} );
}() );
}