Use more arrow functions

Change-Id: Ifdb15ea9e5ca606e02ddaf822bfd6397c3ce639e
This commit is contained in:
Ed Sanders 2024-05-01 12:36:18 +01:00
parent 33db46e6fa
commit 4db99d7a27
9 changed files with 45 additions and 47 deletions

View file

@ -173,7 +173,7 @@ ve.dm.MWWikitextSurfaceFragment.prototype.convertFromSource = function ( source
/*
ve.init.target.getSurface().createProgress(
parsePromise, ve.msg( 'visualeditor-generating-wikitext-progress' )
).done( function ( progressBar, cancelPromise ) {
).done( ( progressBar, cancelPromise ) => {
cancelPromise.fail( () => {
parsePromise.abort();
} );

View file

@ -1075,9 +1075,9 @@ ve.init.mw.ArticleTarget.prototype.getVisualDiffGeneratorPromise = function () {
return mw.libs.ve.diffLoader.getVisualDiffGeneratorPromise( target.originalDmDocPromise, newRevPromise );
} else {
return target.originalDmDocPromise.then( ( originalDmDoc ) => function () {
return new ve.dm.VisualDiff( originalDmDoc, target.getSurface().getModel().getAttachedRoot() );
} );
return target.originalDmDocPromise.then(
( originalDmDoc ) => ve.dm.VisualDiff( originalDmDoc, target.getSurface().getModel().getAttachedRoot() )
);
}
} );
};
@ -1289,7 +1289,7 @@ ve.init.mw.ArticleTarget.prototype.prepareCacheKey = function ( doc ) {
);
} )
.promise( {
abort: function () {
abort: () => {
if ( xhr ) {
xhr.abort();
}
@ -1705,7 +1705,7 @@ ve.init.mw.ArticleTarget.prototype.submit = function ( wikitext, fields ) {
*
* This method performs an asynchronous action and uses a callback function to handle the result.
*
* target.serialize( doc ).then( function ( data ) {
* target.serialize( doc ).then( ( data ) => {
* // Do something with data.content (wikitext)
* } );
*

View file

@ -879,10 +879,10 @@ ve.init.mw.DesktopArticleTarget.prototype.saveComplete = function ( data ) {
if ( !data.nocontent ) {
// Fix permalinks
if ( data.newrevid !== undefined ) {
$( '#t-permalink' ).add( '#coll-download-as-rl' ).find( 'a' ).each( function () {
var permalinkUrl = new URL( this.href );
$( '#t-permalink' ).add( '#coll-download-as-rl' ).find( 'a' ).each( ( i, el ) => {
var permalinkUrl = new URL( el.href );
permalinkUrl.searchParams.set( 'oldid', data.newrevid );
$( this ).attr( 'href', permalinkUrl.toString() );
$( el ).attr( 'href', permalinkUrl.toString() );
} );
}

View file

@ -84,17 +84,17 @@
'div.donut-container', // Web of Trust (T189148)
'div.shield-container' // Web of Trust (T297862)
].join( ',' ) )
.each( function () {
.each( ( j, el ) => {
function truncate( text, l ) {
return text.length > l ? text.slice( 0, l ) + '…' : text;
}
var errorMessage = 'DOM content matching deny list found:\n' + truncate( this.outerHTML, 100 ) +
'\nContext:\n' + truncate( this.parentNode.outerHTML, 200 );
var errorMessage = 'DOM content matching deny list found:\n' + truncate( el.outerHTML, 100 ) +
'\nContext:\n' + truncate( el.parentNode.outerHTML, 200 );
mw.log.error( errorMessage );
var err = new Error( errorMessage );
err.name = 'VeDomDenyListWarning';
mw.errorLogger.logError( err, 'error.visualeditor' );
$( this ).remove();
$( el ).remove();
} );
// data-mw-section-id is copied to headings by mw.libs.ve.unwrapParsoidSections

View file

@ -505,10 +505,10 @@
}
var $heading;
$( '#mw-content-text .mw-editsection a:not( .mw-editsection-visualeditor )' ).each( function () {
var linkUrl = new URL( this.href );
$( '#mw-content-text .mw-editsection a:not( .mw-editsection-visualeditor )' ).each( ( i, el ) => {
var linkUrl = new URL( el.href );
if ( section === parseSection( linkUrl.searchParams.get( 'section' ) ) ) {
$heading = $( this ).closest( '.mw-heading, h1, h2, h3, h4, h5, h6' );
$heading = $( el ).closest( '.mw-heading, h1, h2, h3, h4, h5, h6' );
return false;
}
} );
@ -617,10 +617,10 @@
var visibleSectionOffset = null;
if ( section === null ) {
var firstVisibleEditSection = null;
$( '#firstHeading, #mw-content-text .mw-editsection' ).each( function () {
var top = this.getBoundingClientRect().top;
$( '#firstHeading, #mw-content-text .mw-editsection' ).each( ( i, el ) => {
var top = el.getBoundingClientRect().top;
if ( top > 0 ) {
firstVisibleEditSection = this;
firstVisibleEditSection = el;
// break
return false;
}
@ -900,14 +900,12 @@
* mw.libs.ve.addPlugin( 'ext.gadget.foobar' );
*
* // Register a callback
* mw.libs.ve.addPlugin( function ( target ) {
* mw.libs.ve.addPlugin( ( target ) => {
* ve.dm.Foobar = .....
* } );
*
* // Register a callback that loads another script
* mw.libs.ve.addPlugin( function () {
* return $.getScript( 'http://example.com/foobar.js' );
* } );
* mw.libs.ve.addPlugin( () => $.getScript( 'http://example.com/foobar.js' ) );
*
* @param {string|Function} plugin Module name or callback that optionally returns a promise
*/
@ -933,17 +931,17 @@
'#ca-edit a,' +
// Add section is currently a wikitext-only feature
'#ca-addsection a'
).each( function () {
if ( !this.href ) {
).each( ( i, el ) => {
if ( !el.href ) {
// Not a real link, probably added by a gadget or another extension (T328094)
return;
}
var linkUrl = new URL( this.href );
var linkUrl = new URL( el.href );
if ( linkUrl.searchParams.has( 'action' ) ) {
linkUrl.searchParams.delete( 'action' );
linkUrl.searchParams.set( 'veaction', 'editsource' );
$( this ).attr( 'href', linkUrl.toString() );
$( el ).attr( 'href', linkUrl.toString() );
}
} );
}

View file

@ -62,12 +62,15 @@
false,
// noMetadata, we only use `content` in getModelFromResponse
true
).then( ( response ) => parseDocumentModulePromise.then( () => mw.libs.ve.diffLoader.getModelFromResponse( response, section ) ), function () {
).then(
( response ) => parseDocumentModulePromise.then( () => mw.libs.ve.diffLoader.getModelFromResponse( response, section ) ),
() => {
// Clear promise. Do not cache errors.
delete revCache[ cacheKey ];
// Let caller handle the error code
return $.Deferred().rejectWith( this, arguments );
} );
delete revCache[ cacheKey ];
// Let caller handle the error code
return $.Deferred().rejectWith( this, arguments );
}
);
return revCache[ cacheKey ];
},
@ -93,9 +96,7 @@
// TODO: Differ expects newDoc to be derived from oldDoc and contain all its store data.
// We may want to remove that assumption from the differ?
newDoc.getStore().merge( oldDoc.getStore() );
return function () {
return new ve.dm.VisualDiff( oldDoc, newDoc );
};
return () => new ve.dm.VisualDiff( oldDoc, newDoc );
} );
}

View file

@ -181,7 +181,7 @@ QUnit.test( 'toDataElement', ( assert ) => {
}
];
articlePaths.forEach( function ( pathData ) {
articlePaths.forEach( ( pathData ) => {
// Set up global state (site configuration)
mw.config.set( pathData.config );
@ -196,14 +196,13 @@ QUnit.test( 'toDataElement', ( assert ) => {
converter.fromClipboard = true;
// Generate test cases for this site configuration
const cases = getCases();
for ( let i = 0; i < cases.length; i++ ) {
getCases().forEach( ( caseItem ) => {
assert.deepEqual(
ve.dm.MWInternalLinkAnnotation.static.toDataElement( [ cases[ i ].element ], converter ),
cases[ i ].expected,
cases[ i ].msg + ': ' + pathData.msg
ve.dm.MWInternalLinkAnnotation.static.toDataElement( [ caseItem.element ], converter ),
caseItem.expected,
caseItem.msg + ': ' + pathData.msg
);
}
} );
} );
} );

View file

@ -12,8 +12,10 @@
} );
return {
params,
getTemplateDataQueryTitle: () => null,
getTarget: () => {
getTemplateDataQueryTitle: function () {
return null;
},
getTarget: function () {
return { wt: 'RawTemplateName' };
},
getParameters: function () {

View file

@ -54,9 +54,7 @@ ve.ui.MWExternalLinkAnnotationWidget.static.createExternalLinkInputWidget = func
var inputWidget = new OO.ui.TextInputWidget( ve.extendObject( {}, config, {
icon: 'linkExternal',
type: 'url',
validate: function ( text ) {
return !!ve.init.platform.getExternalLinkUrlProtocolsRegExp().exec( text.trim() );
}
validate: ( text ) => !!ve.init.platform.getExternalLinkUrlProtocolsRegExp().exec( text.trim() )
} ) );
inputWidget.$input.attr( 'aria-label', mw.msg( 'visualeditor-linkinspector-button-link-external' ) );