8
0
Эх сурвалжийг харах

Replaced var with let or const.

Piotrek Koszuliński 10 жил өмнө
parent
commit
d8cf7fbcf3

+ 7 - 7
packages/ckeditor5-ui/src/collection.js

@@ -81,8 +81,8 @@ CKEDITOR.define( [ 'emittermixin', 'ckeditorerror', 'utils' ], function( Emitter
 		 * @param {Object} item
 		 */
 		add( item ) {
-			var itemId;
-			var idProperty = this._idProperty;
+			let itemId;
+			const idProperty = this._idProperty;
 
 			if ( ( idProperty in item ) ) {
 				itemId = item[ idProperty ];
@@ -124,7 +124,7 @@ CKEDITOR.define( [ 'emittermixin', 'ckeditorerror', 'utils' ], function( Emitter
 		 * @returns {Object} The requested item or `null` if such item does not exist.
 		 */
 		get( idOrIndex ) {
-			var item;
+			let item;
 
 			if ( typeof idOrIndex == 'string' ) {
 				item = this._itemMap.get( idOrIndex );
@@ -149,9 +149,9 @@ CKEDITOR.define( [ 'emittermixin', 'ckeditorerror', 'utils' ], function( Emitter
 		 * @returns {Object} The removed item.
 		 */
 		remove( subject ) {
-			var index, id, item;
-			var itemDoesNotExist = false;
-			var idProperty = this._idProperty;
+			let index, id, item;
+			let itemDoesNotExist = false;
+			const idProperty = this._idProperty;
 
 			if ( typeof subject == 'string' ) {
 				id = subject;
@@ -245,7 +245,7 @@ CKEDITOR.define( [ 'emittermixin', 'ckeditorerror', 'utils' ], function( Emitter
 		 * @returns {String} The next id.
 		 */
 		_getNextId() {
-			var id;
+			let id;
 
 			do {
 				id = String( this._nextId++ );

+ 6 - 6
packages/ckeditor5-ui/src/config.js

@@ -76,17 +76,17 @@ CKEDITOR.define( [ 'model', 'utils' ], function( Model, utils ) {
 
 			// The target for this configuration is, for now, this object.
 			//jscs:disable safeContextKeyword
-			var target = this;
+			let target = this;
 			//jscs:enable
 
 			// The configuration name should be split into parts if it has dots. E.g: `resize.width`.
-			var parts = name.toLowerCase().split( '.' );
+			const parts = name.toLowerCase().split( '.' );
 
 			// Take the name of the configuration out of the parts. E.g. `resize.width` -> `width`
 			name = parts.pop();
 
 			// Retrieves the final target for this configuration recursively.
-			for ( var i = 0; i < parts.length; i++ ) {
+			for ( let i = 0; i < parts.length; i++ ) {
 				// The target will always be an instance of Config.
 				if ( !( target[ parts[ i ] ] instanceof Config ) ) {
 					target.set( parts[ i ], new Config() );
@@ -132,17 +132,17 @@ CKEDITOR.define( [ 'model', 'utils' ], function( Model, utils ) {
 		get( name ) {
 			// The target for this configuration is, for now, this object.
 			//jscs:disable safeContextKeyword
-			var source = this;
+			let source = this;
 			//jscs:enable
 
 			// The configuration name should be split into parts if it has dots. E.g. `resize.width` -> [`resize`, `width`]
-			var parts = name.toLowerCase().split( '.' );
+			const parts = name.toLowerCase().split( '.' );
 
 			// Take the name of the configuration from the parts. E.g. `resize.width` -> `width`
 			name = parts.pop();
 
 			// Retrieves the source for this configuration recursively.
-			for ( var i = 0; i < parts.length; i++ ) {
+			for ( let i = 0; i < parts.length; i++ ) {
 				// The target will always be an instance of Config.
 				if ( !( source[ parts[ i ] ] instanceof Config ) ) {
 					source = null;

+ 15 - 15
packages/ckeditor5-ui/src/emittermixin.js

@@ -25,7 +25,7 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 		 * Lower values are called first.
 		 */
 		on( event, callback, ctx, priority ) {
-			var callbacks = getCallbacks( this, event );
+			const callbacks = getCallbacks( this, event );
 
 			// Set the priority defaults.
 			if ( typeof priority != 'number' ) {
@@ -39,7 +39,7 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 			};
 
 			// Add the callback to the list in the right priority position.
-			for ( var i = callbacks.length - 1; i >= 0; i-- ) {
+			for ( let i = callbacks.length - 1; i >= 0; i-- ) {
 				if ( callbacks[ i ].priority <= priority ) {
 					callbacks.splice( i + 1, 0, callback );
 
@@ -62,7 +62,7 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 		 * Lower values are called first.
 		 */
 		once( event, callback, ctx, priority ) {
-			var onceCallback = function( event ) {
+			const onceCallback = function( event ) {
 				// Go off() at the first call.
 				event.off();
 
@@ -83,13 +83,13 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 		 * the same callback is used several times with different contexts.
 		 */
 		off( event, callback, ctx ) {
-			var callbacks = getCallbacksIfAny( this, event );
+			const callbacks = getCallbacksIfAny( this, event );
 
 			if ( !callbacks ) {
 				return;
 			}
 
-			for ( var i = 0; i < callbacks.length; i++ ) {
+			for ( let i = 0; i < callbacks.length; i++ ) {
 				if ( callbacks[ i ].callback == callback ) {
 					if ( !ctx || ctx == callbacks[ i ].ctx ) {
 						// Remove the callback from the list (fixing the next index).
@@ -111,7 +111,7 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 		 * Lower values are called first.
 		 */
 		listenTo( emitter, event, callback, ctx, priority ) {
-			var emitters, emitterId, emitterInfo, eventCallbacks;
+			let emitters, emitterId, emitterInfo, eventCallbacks;
 
 			// _listeningTo contains a list of emitters that this object is listening to.
 			// This list has the following format:
@@ -167,10 +167,10 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 		 * `event`.
 		 */
 		stopListening( emitter, event, callback ) {
-			var emitters = this._listeningTo;
-			var emitterId = emitter && emitter._emitterId;
-			var emitterInfo = emitters && emitterId && emitters[ emitterId ];
-			var eventCallbacks = emitterInfo && event && emitterInfo.callbacks[ event ];
+			let emitters = this._listeningTo;
+			let emitterId = emitter && emitter._emitterId;
+			let emitterInfo = emitters && emitterId && emitters[ emitterId ];
+			let eventCallbacks = emitterInfo && event && emitterInfo.callbacks[ event ];
 
 			// Stop if nothing has been listened.
 			if ( !emitters || ( emitter && !emitterInfo ) || ( event && !eventCallbacks ) ) {
@@ -214,19 +214,19 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 		 * @param {...*} [args] Additional arguments to be passed to the callbacks.
 		 */
 		fire( event, args ) {
-			var callbacks = getCallbacksIfAny( this, event );
+			const callbacks = getCallbacksIfAny( this, event );
 
 			if ( !callbacks ) {
 				return;
 			}
 
-			var eventInfo = new EventInfo( this, event );
+			let eventInfo = new EventInfo( this, event );
 
 			// Take the list of arguments to pass to the callbacks.
 			args = Array.prototype.slice.call( arguments, 1 );
 			args.unshift( eventInfo );
 
-			for ( var i = 0; i < callbacks.length; i++ ) {
+			for ( let i = 0; i < callbacks.length; i++ ) {
 				callbacks[ i ].callback.apply( callbacks[ i ].ctx, args );
 
 				// Remove the callback from future requests if off() has been called.
@@ -262,7 +262,7 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 
 	// Gets the list of callbacks for a given event.
 	function getCallbacks( source, eventName ) {
-		var events = getEvents( source );
+		const events = getEvents( source );
 
 		if ( !events[ eventName ] ) {
 			events[ eventName ] = [];
@@ -273,7 +273,7 @@ CKEDITOR.define( [ 'eventinfo', 'utils' ], function( EventInfo, utils ) {
 
 	// Get the list of callbacks for a given event only if there is any available.
 	function getCallbacksIfAny( source, event ) {
-		var callbacks;
+		let callbacks;
 
 		if ( !source._events || !( callbacks = source._events[ event ] ) || !callbacks.length ) {
 			return null;

+ 1 - 1
packages/ckeditor5-ui/src/log.js

@@ -40,7 +40,7 @@
  */
 
 CKEDITOR.define( function() {
-	var log = {
+	const log = {
 		/**
 		 * Logs an error to the console.
 		 *

+ 2 - 2
packages/ckeditor5-ui/src/model.js

@@ -71,7 +71,7 @@ CKEDITOR.define( [ 'emittermixin', 'ckeditorerror', 'utils' ], function( Emitter
 				 * This error is thrown when trying to {@link Model#set set} an attribute with
 				 * a name of an already existing property. For example:
 				 *
-				 *		var model = new Model();
+				 *		let model = new Model();
 				 *		model.property = 1;
 				 *		model.set( 'property', 2 );		// throws
 				 *
@@ -92,7 +92,7 @@ CKEDITOR.define( [ 'emittermixin', 'ckeditorerror', 'utils' ], function( Emitter
 				},
 
 				set: function( value ) {
-					var oldValue = this._attributes[ name ];
+					const oldValue = this._attributes[ name ];
 
 					if ( oldValue !== value ) {
 						this._attributes[ name ] = value;

+ 10 - 10
packages/ckeditor5-ui/src/ui/domemittermixin.js

@@ -50,8 +50,8 @@ CKEDITOR.define( [ 'emittermixin', 'utils', 'log' ], function( EmitterMixin, uti
 		 * Lower values are called first.
 		 */
 		listenTo() {
-			var args = Array.prototype.slice.call( arguments );
-			var emitter = args[ 0 ];
+			const args = Array.prototype.slice.call( arguments );
+			const emitter = args[ 0 ];
 
 			// Check if emitter is an instance of DOM Node. If so, replace the argument with
 			// corresponding ProxyEmitter (or create one if not existing).
@@ -79,12 +79,12 @@ CKEDITOR.define( [ 'emittermixin', 'utils', 'log' ], function( EmitterMixin, uti
 		 * `event`.
 		 */
 		stopListening() {
-			var args = Array.prototype.slice.call( arguments );
-			var emitter = args[ 0 ];
+			const args = Array.prototype.slice.call( arguments );
+			const emitter = args[ 0 ];
 
 			// Check if emitter is an instance of DOM Node. If so, replace the argument with corresponding ProxyEmitter.
 			if ( emitter instanceof Node ) {
-				var proxy = this._getProxyEmitter( emitter );
+				let proxy = this._getProxyEmitter( emitter );
 
 				if ( proxy ) {
 					args[ 0 ] = proxy;
@@ -107,10 +107,10 @@ CKEDITOR.define( [ 'emittermixin', 'utils', 'log' ], function( EmitterMixin, uti
 		 * @return {ProxyEmitter} ProxyEmitter instance or null.
 		 */
 		_getProxyEmitter( node ) {
-			var proxy, emitters, emitterInfo;
+			let proxy, emitters, emitterInfo;
 
 			// Get node UID. It allows finding Proxy Emitter for this DOM Node.
-			var uid = getNodeUID( node );
+			const uid = getNodeUID( node );
 
 			// Find existing Proxy Emitter for this DOM Node among emitters.
 			if ( ( emitters = this._listeningTo ) ) {
@@ -172,7 +172,7 @@ CKEDITOR.define( [ 'emittermixin', 'utils', 'log' ], function( EmitterMixin, uti
 				return;
 			}
 
-			var domListener = this._createDomListener( event );
+			const domListener = this._createDomListener( event );
 
 			// Attach the native DOM listener to DOM Node.
 			this._domNode.addEventListener( event, domListener );
@@ -198,7 +198,7 @@ CKEDITOR.define( [ 'emittermixin', 'utils', 'log' ], function( EmitterMixin, uti
 			// Execute parent class method first.
 			EmitterMixin.off.apply( this, arguments );
 
-			var callbacks;
+			let callbacks;
 
 			// Remove native DOM listeners which are orphans. If no callbacks
 			// are awaiting given event, detach native DOM listener from DOM Node.
@@ -217,7 +217,7 @@ CKEDITOR.define( [ 'emittermixin', 'utils', 'log' ], function( EmitterMixin, uti
 		 * @returns {Function} The DOM listener callback.
 		 */
 		_createDomListener( event ) {
-			var domListener = domEvt => {
+			const domListener = domEvt => {
 				this.fire( event, domEvt );
 			};
 

+ 7 - 7
packages/ckeditor5-ui/src/ui/template.js

@@ -53,7 +53,7 @@ CKEDITOR.define( function() {
 			return null;
 		}
 
-		var el = document.createElement( def.tag );
+		const el = document.createElement( def.tag );
 
 		// Set the text first.
 		renderElementText( def, el );
@@ -81,8 +81,8 @@ CKEDITOR.define( function() {
 	}
 
 	function renderElementAttributes( def, el ) {
-		var value;
-		var attr;
+		let value;
+		let attr;
 
 		for ( attr in def.attrs ) {
 			value = def.attrs[ attr ];
@@ -105,7 +105,7 @@ CKEDITOR.define( function() {
 	}
 
 	function renderElementChildren( def, el ) {
-		var child;
+		let child;
 
 		if ( def.children ) {
 			for ( child of def.children ) {
@@ -116,9 +116,9 @@ CKEDITOR.define( function() {
 
 	function activateElementListeners( def, el ) {
 		if ( def.on ) {
-			for ( var l in def.on ) {
-				var domEvtDef = l.split( '@' );
-				var name, selector;
+			for ( let l in def.on ) {
+				let domEvtDef = l.split( '@' );
+				let name, selector;
 
 				if ( domEvtDef.length == 2 ) {
 					name = domEvtDef[ 0 ];

+ 1 - 1
packages/ckeditor5-ui/src/ui/view.js

@@ -95,7 +95,7 @@ CKEDITOR.define( [
 				onModelChange( null, this.model[ property ] );
 
 				function onModelChange( evt, value ) {
-					var processedValue = callback( el, value );
+					let processedValue = callback( el, value );
 
 					if ( typeof processedValue != 'undefined' ) {
 						domUpdater( el, processedValue );

+ 1 - 1
packages/ckeditor5-ui/src/utils-lodash.js

@@ -16,7 +16,7 @@
 ( function() {
 	// The list of Lo-Dash methods to include in "utils".
 	// It is mandatory to execute `grunt lodash` after changes to this list.
-	var lodashInclude = [
+	const lodashInclude = [
 		/**
 		 * See Lo-Dash: https://lodash.com/docs#clone
 		 *

+ 9 - 8
packages/ckeditor5-ui/src/utils.js

@@ -13,7 +13,7 @@
  */
 
 CKEDITOR.define( [ 'utils-lodash', 'lib/lodash/lodash-ckeditor' ], function( lodashIncludes, lodash ) {
-	var utils = {
+	const utils = {
 		/**
 		 * Creates a spy function (ala Sinon.js) that can be used to inspect call to it.
 		 *
@@ -24,11 +24,9 @@ CKEDITOR.define( [ 'utils-lodash', 'lib/lodash/lodash-ckeditor' ], function( lod
 		 * @returns {Function} The spy function.
 		 */
 		spy() {
-			var spy = function() {
+			return function spy() {
 				spy.called = true;
 			};
-
-			return spy;
 		},
 
 		/**
@@ -38,7 +36,7 @@ CKEDITOR.define( [ 'utils-lodash', 'lib/lodash/lodash-ckeditor' ], function( lod
 		 * @returns {Number} A number representing the id.
 		 */
 		uid: ( function() {
-			var next = 1;
+			let next = 1;
 
 			return function() {
 				return next++;
@@ -71,9 +69,9 @@ CKEDITOR.define( [ 'utils-lodash', 'lib/lodash/lodash-ckeditor' ], function( lod
 		 * `a` is a {@link utils.compareArrays#EXTENSION extension}, or `a` is {@link utils.compareArrays#DIFFERENT different}.
 		 */
 		compareArrays( a, b ) {
-			var minLen = Math.min( a.length, b.length );
+			const minLen = Math.min( a.length, b.length );
 
-			for ( var i = 0; i < minLen; i++ ) {
+			for ( let i = 0; i < minLen; i++ ) {
 				if ( a[ i ] != b[ i ] ) {
 					// The arrays are different.
 					return utils.compareArrays.DIFFERENT;
@@ -100,18 +98,21 @@ CKEDITOR.define( [ 'utils-lodash', 'lib/lodash/lodash-ckeditor' ], function( lod
 	 * @type {Number}
 	 */
 	utils.compareArrays.SAME = 0;
+
 	/**
 	 * Flag for "is a prefix of" relation between arrays.
 	 *
 	 * @type {Number}
 	 */
 	utils.compareArrays.PREFIX = 1;
+
 	/**
 	 * Flag for "is a suffix of" relation between arrays.
 	 *
 	 * @type {number}
 	 */
 	utils.compareArrays.EXTENSION = 2;
+
 	/**
 	 * Flag for "is different than" relation between arrays.
 	 *
@@ -120,7 +121,7 @@ CKEDITOR.define( [ 'utils-lodash', 'lib/lodash/lodash-ckeditor' ], function( lod
 	utils.compareArrays.DIFFERENT = 3;
 
 	// Extend "utils" with Lo-Dash methods.
-	for ( var i = 0; i < lodashIncludes.length; i++ ) {
+	for ( let i = 0; i < lodashIncludes.length; i++ ) {
 		utils[ lodashIncludes[ i ] ] = lodash[ lodashIncludes[ i ] ];
 	}