Explorar o código

Changed enum constants to strings in TreeModel.

Szymon Cofalik %!s(int64=10) %!d(string=hai) anos
pai
achega
70236a4923

+ 1 - 2
packages/ckeditor5-engine/src/treemodel/delta/attributedelta.js

@@ -10,7 +10,6 @@ import register from '../batch.js';
 import AttributeOperation from '../operation/attributeoperation.js';
 import Position from '../position.js';
 import Range from '../range.js';
-import TreeWalker from '../treewalker.js';
 import Attribute from '../attribute.js';
 import Element from '../element.js';
 
@@ -115,7 +114,7 @@ function changeRange( doc, delta, key, value, range ) {
 	while ( !next.done ) {
 		// We check values only when the range contains given element, that is when the iterator "enters" the element.
 		// To prevent double-checking or not needed checking, we filter-out iterator values for ELEMENT_END position.
-		if ( next.value.type != TreeWalker.ELEMENT_END ) {
+		if ( next.value.type != 'ELEMENT_END' ) {
 			valueAfter = next.value.item.attrs.getValue( key );
 
 			// At the first run of the iterator the position in undefined. We also do not have a valueBefore, but

+ 13 - 27
packages/ckeditor5-engine/src/treemodel/liveposition.js

@@ -10,8 +10,11 @@ import Range from './range.js';
 import EmitterMixin from '../emittermixin.js';
 import objectUtils from '../lib/lodash/object.js';
 
-const STICKS_TO_NEXT = 0;
-const STICKS_TO_PREVIOUS = 1;
+/**
+ * Enum representing how position is "sticking" with their neighbour nodes.
+ * Possible values: `'STICKS_TO_NEXT'`, `'STICKS_TO_PREVIOUS'`.
+ * @typedef {String} treeModel.PositionStickiness
+ */
 
 /**
  * LivePosition is a position in the Tree Model that updates itself as the tree changes. It may be used as a bookmark.
@@ -28,8 +31,7 @@ export default class LivePosition extends Position {
 	 * @see {@link treeModel.Position}
 	 * @param root
 	 * @param path
-	 * @param {Number} [stickiness] Flag representing how live position is "sticking" with their neighbour nodes.
-	 * Defaults to {@link #STICKS_TO_NEXT}. See {@link #stickiness}.
+	 * @param {treeModel.PositionStickiness} [stickiness] Defaults to `'STICKS_TO_NEXT'`. See {@link #stickiness}.
 	 * @constructor
 	 */
 	constructor( root, path, stickiness ) {
@@ -52,11 +54,9 @@ export default class LivePosition extends Position {
 		 * | sticks to previous node: `<p>f|[oo]</p><p>b^ar</p>` => `<p>f|</p><p>booar</p>`
 		 * | sticks to next node: `<p>f|[oo]</p><p>b^ar</p>` => `<p>f</p><p>b|ooar</p>`
 		 *
-		 * Accepted values are {@link #STICKS_TO_PREVIOUS} and {@link #STICKS_TO_NEXT}.
-		 *
-		 * @type {Number}
+		 * @type {treeModel.PositionStickiness}
 		 */
-		this.stickiness = stickiness || STICKS_TO_NEXT;
+		this.stickiness = stickiness || 'STICKS_TO_NEXT';
 
 		bindWithDocument.call( this );
 	}
@@ -140,7 +140,7 @@ function transform( type, range, position ) {
 
 	switch ( type ) {
 		case 'insert':
-			let insertBefore = this.stickiness == STICKS_TO_NEXT;
+			let insertBefore = this.stickiness == 'STICKS_TO_NEXT';
 			transformed = this.getTransformedByInsertion( range.start, howMany, insertBefore );
 			break;
 
@@ -150,14 +150,14 @@ function transform( type, range, position ) {
 			let originalRange = Range.createFromPositionAndShift( position, howMany );
 
 			let gotMoved = originalRange.containsPosition( this ) ||
-				( originalRange.start.isEqual( this ) && this.stickiness == STICKS_TO_NEXT ) ||
-				( originalRange.end.isEqual( this ) && this.stickiness == STICKS_TO_PREVIOUS );
+				( originalRange.start.isEqual( this ) && this.stickiness == 'STICKS_TO_NEXT' ) ||
+				( originalRange.end.isEqual( this ) && this.stickiness == 'STICKS_TO_PREVIOUS' );
 
 			// We can't use .getTransformedByMove() because we have a different if-condition.
 			if ( gotMoved ) {
 				transformed = this._getCombined( position, range.start );
 			} else {
-				let insertBefore = this.stickiness == STICKS_TO_NEXT;
+				let insertBefore = this.stickiness == 'STICKS_TO_NEXT';
 				transformed = this.getTransformedByMove( position, range.start, howMany, insertBefore );
 			}
 			break;
@@ -167,18 +167,4 @@ function transform( type, range, position ) {
 	this.root = transformed.root;
 }
 
-/**
- * Flag representing that the position is sticking to the node before it or to the beginning of it's parent node.
- *
- * @type {Number}
- */
-LivePosition.STICKS_TO_PREVIOUS = STICKS_TO_PREVIOUS;
-
-/**
- * Flag representing that the position is sticking to the node after it or to the end of it's parent node.
- *
- * @type {number}
- */
-LivePosition.STICKS_TO_NEXT = STICKS_TO_NEXT;
-
-objectUtils.extend( LivePosition.prototype, EmitterMixin );
+objectUtils.extend( LivePosition.prototype, EmitterMixin );

+ 3 - 3
packages/ckeditor5-engine/src/treemodel/liverange.js

@@ -28,8 +28,8 @@ export default class LiveRange extends Range {
 	constructor( start, end ) {
 		super( start, end );
 
-		this.start = new LivePosition( this.start.root, this.start.path.slice(), LivePosition.STICKS_TO_NEXT );
-		this.end = new LivePosition( this.end.root, this.end.path.slice(), LivePosition.STICKS_TO_PREVIOUS );
+		this.start = new LivePosition( this.start.root, this.start.path.slice(), 'STICKS_TO_NEXT' );
+		this.end = new LivePosition( this.end.root, this.end.path.slice(), 'STICKS_TO_PREVIOUS' );
 
 		bindWithDocument.call( this );
 	}
@@ -134,4 +134,4 @@ function fixBoundaries( type, range, position ) {
 	}
 }
 
-objectUtils.extend( LiveRange.prototype, EmitterMixin );
+objectUtils.extend( LiveRange.prototype, EmitterMixin );

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/operation/moveoperation.js

@@ -100,7 +100,7 @@ export default class MoveOperation extends Operation {
 				'operation-move-range-into-itself: Trying to move a range of nodes to the inside of that range.'
 			);
 		} else {
-			if ( utils.compareArrays( this.sourcePosition.getParentPath(), this.targetPosition.getParentPath() ) == utils.compareArrays.PREFIX ) {
+			if ( utils.compareArrays( this.sourcePosition.getParentPath(), this.targetPosition.getParentPath() ) == 'PREFIX' ) {
 				let i = this.sourcePosition.path.length - 1;
 
 				if ( this.targetPosition.path[ i ] >= sourceOffset && this.targetPosition.path[ i ] < sourceOffset + this.howMany ) {
@@ -132,4 +132,4 @@ export default class MoveOperation extends Operation {
 			range: Range.createFromPositionAndShift( this.targetPosition, this.howMany )
 		};
 	}
-}
+}

+ 2 - 2
packages/ckeditor5-engine/src/treemodel/operation/transform.js

@@ -287,7 +287,7 @@ const ot = {
 			// * on deeper tree level - it means that we move nodes that are inside moved nodes
 			// The operations are conflicting only if they try to move exactly same nodes, so only in the first case.
 			// So, we will handle common range if it is "deeper" or if transformed operation is more important.
-			let isDeeper = utils.compareArrays( b.sourcePosition.getParentPath(), a.sourcePosition.getParentPath() ) == utils.compareArrays.PREFIX;
+			let isDeeper = utils.compareArrays( b.sourcePosition.getParentPath(), a.sourcePosition.getParentPath() ) == 'PREFIX';
 
 			if ( common !== null && ( isDeeper || isStrong ) ) {
 				// Here we do not need to worry that newTargetPosition is inside moved range, because that
@@ -420,4 +420,4 @@ function joinRanges( ranges ) {
 
 		return ranges[ 0 ];
 	}
-}
+}

+ 26 - 54
packages/ckeditor5-engine/src/treemodel/position.js

@@ -10,10 +10,12 @@ import CKEditorError from '../ckeditorerror.js';
 import arrayUtils from '../lib/lodash/array.js';
 import utils from '../utils.js';
 
-const SAME = 0;
-const AFTER = 1;
-const BEFORE = 2;
-const DIFFERENT = 3;
+/**
+ * A flag indicating whether this position is `'BEFORE'` or `'AFTER'` or `'SAME'` as given position.
+ * If positions are in different roots `'DIFFERENT'` flag is returned.
+ *
+ * @typedef {String} treeModel.PositionRelation
+ */
 
 /**
  * Position in the tree. Position is always located before or after a node.
@@ -136,32 +138,30 @@ export default class Position {
 	 * Checks whether this position is before or after given position.
 	 *
 	 * @param {treeModel.Position} otherPosition Position to compare with.
-	 * @returns {Number} A flag indicating whether this position is {@link #BEFORE} or
-	 * {@link #AFTER} or {@link #SAME} as given position. If positions are in different roots,
-	 * {@link #DIFFERENT} flag is returned.
+	 * @returns {treeModel.PositionRelation}
 	 */
 	compareWith( otherPosition ) {
 		if ( this.root != otherPosition.root ) {
-			return DIFFERENT;
+			return 'DIFFERENT';
 		}
 
 		const result = utils.compareArrays( this.path, otherPosition.path );
 
 		switch ( result ) {
-			case utils.compareArrays.SAME:
-				return SAME;
+			case 'SAME':
+				return 'SAME';
 
-			case utils.compareArrays.PREFIX:
-				return BEFORE;
+			case 'PREFIX':
+				return 'BEFORE';
 
-			case utils.compareArrays.EXTENSION:
-				return AFTER;
+			case 'EXTENSION':
+				return 'AFTER';
 
 			default:
 				if ( this.path[ result ] < otherPosition.path[ result ] ) {
-					return BEFORE;
+					return 'BEFORE';
 				} else {
-					return AFTER;
+					return 'AFTER';
 				}
 		}
 	}
@@ -208,7 +208,7 @@ export default class Position {
 			return transformed;
 		}
 
-		if ( utils.compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == utils.compareArrays.SAME ) {
+		if ( utils.compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == 'SAME' ) {
 			// If nodes are removed from the node that is pointed by this position...
 			if ( deletePosition.offset < this.offset ) {
 				// And are removed from before an offset of that position...
@@ -219,7 +219,7 @@ export default class Position {
 					transformed.offset -= howMany;
 				}
 			}
-		} else if ( utils.compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == utils.compareArrays.PREFIX ) {
+		} else if ( utils.compareArrays( deletePosition.getParentPath(), this.getParentPath() ) == 'PREFIX' ) {
 			// If nodes are removed from a node that is on a path to this position...
 			const i = deletePosition.path.length - 1;
 
@@ -257,14 +257,14 @@ export default class Position {
 			return transformed;
 		}
 
-		if ( utils.compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == utils.compareArrays.SAME ) {
+		if ( utils.compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == 'SAME' ) {
 			// If nodes are inserted in the node that is pointed by this position...
 			if ( insertPosition.offset < this.offset || ( insertPosition.offset == this.offset && insertBefore ) ) {
 				// And are inserted before an offset of that position...
 				// "Push" this positions offset.
 				transformed.offset += howMany;
 			}
-		} else if ( utils.compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == utils.compareArrays.PREFIX ) {
+		} else if ( utils.compareArrays( insertPosition.getParentPath(), this.getParentPath() ) == 'PREFIX' ) {
 			// If nodes are inserted in a node that is on a path to this position...
 			const i = insertPosition.path.length - 1;
 
@@ -315,7 +315,7 @@ export default class Position {
 	 * @returns {Boolean} True if this position is after given position.
 	 */
 	isAfter( otherPosition ) {
-		return this.compareWith( otherPosition ) == AFTER;
+		return this.compareWith( otherPosition ) == 'AFTER';
 	}
 
 	/**
@@ -350,7 +350,7 @@ export default class Position {
 	 * @returns {Boolean} True if this position is before given position.
 	 */
 	isBefore( otherPosition ) {
-		return this.compareWith( otherPosition ) == BEFORE;
+		return this.compareWith( otherPosition ) == 'BEFORE';
 	}
 
 	/**
@@ -360,7 +360,7 @@ export default class Position {
 	 * @returns {Boolean} True if positions are same.
 	 */
 	isEqual( otherPosition ) {
-		return this.compareWith( otherPosition ) == SAME;
+		return this.compareWith( otherPosition ) == 'SAME';
 	}
 
 	/**
@@ -377,15 +377,15 @@ export default class Position {
 		let compare = this.compareWith( otherPosition );
 
 		switch ( compare ) {
-			case SAME:
+			case 'SAME':
 				return true;
 
-			case BEFORE:
+			case 'BEFORE':
 				left = this;
 				right = otherPosition;
 				break;
 
-			case AFTER:
+			case 'AFTER':
 				left = otherPosition;
 				right = this;
 				break;
@@ -529,31 +529,3 @@ export default class Position {
 		return combined;
 	}
 }
-
-/**
- * Flag for "is after" relation between Positions.
- *
- * @type {Number}
- */
-Position.AFTER = AFTER;
-
-/**
- * Flag for "is before" relation between Positions.
- *
- * @type {Number}
- */
-Position.BEFORE = BEFORE;
-
-/**
- * Flag for "are in different roots" relation between Positions.
- *
- * @type {Number}
- */
-Position.DIFFERENT = DIFFERENT;
-
-/**
- * Flag for "are same" relation between Positions.
- *
- * @type {Number}
- */
-Position.SAME = SAME;

+ 11 - 11
packages/ckeditor5-engine/src/treemodel/range.js

@@ -224,11 +224,12 @@ export default class Range {
 
 		// We find on which tree-level start and end have the lowest common ancestor
 		let cmp = utils.compareArrays( this.start.path, this.end.path );
-		let diffAt = ( cmp < 0 ) ? Math.min( this.start.path.length, this.end.path.length ) : cmp;
+		// If comparison returned string it means that arrays are same.
+		let diffAt = ( typeof cmp == 'string' ) ? Math.min( this.start.path.length, this.end.path.length ) : cmp;
 
 		let pos = Position.createFromPosition( this.start );
 
-		// go up
+		// Go up.
 		while ( pos.path.length > diffAt + 1 ) {
 			let howMany = pos.parent.getChildCount() - pos.offset;
 
@@ -240,7 +241,7 @@ export default class Range {
 			pos.offset++;
 		}
 
-		// go down
+		// Go down.
 		while ( pos.path.length <= this.end.path.length ) {
 			let offset = this.end.path[ pos.path.length - 1 ];
 			let howMany = offset - pos.offset;
@@ -263,9 +264,8 @@ export default class Range {
 	 * we enter into when iterating over this range.
 	 *
 	 * **Note:** this method will not return a parent node of start position. This is in contrary to {@link treeModel.TreeWalker}
-	 * which will return that node with {@link treeModel.TreeWalker#ELEMENT_END} type. This method, also, returns each
-	 * {@link treeModel.Element} once, while iterator return it twice: for {@link treeModel.TreeWalker#ELEMENT_START} and
-	 * {@link treeModel.TreeWalker#ELEMENT_END}.
+	 * which will return that node with `'ELEMENT_END'` type. This method also returns each {@link treeModel.Element} once,
+	 * while simply used {@link treeModel.TreeWalker} might return it twice: for `'ELEMENT_START'` and `'ELEMENT_END'`.
 	 *
 	 * @see {treeModel.TreeWalker}
 	 * @param {Boolean} [mergeCharacters] Flag indicating whether all consecutive characters with the same attributes
@@ -280,7 +280,7 @@ export default class Range {
 		do {
 			step = it.next();
 
-			if ( step.value && step.value.type != TreeWalker.ELEMENT_END ) {
+			if ( step.value && step.value.type != 'ELEMENT_END' ) {
 				yield step.value.item;
 			}
 		} while ( !step.done );
@@ -330,9 +330,9 @@ export default class Range {
 				step = it.next();
 
 				if ( step.value ) {
-					if ( step.value.type == TreeWalker.ELEMENT_START ) {
+					if ( step.value.type == 'ELEMENT_START' ) {
 						depth++;
-					} else if ( step.value.type == TreeWalker.ELEMENT_END ) {
+					} else if ( step.value.type == 'ELEMENT_END' ) {
 						depth--;
 					}
 
@@ -369,8 +369,8 @@ export default class Range {
 	 */
 	getTransformedByInsertion( insertPosition, howMany, spreadOnlyOnSameLevel ) {
 		// Flag indicating whether this whole range and given insertPosition is on the same tree level.
-		const areOnSameLevel = utils.compareArrays( this.start.getParentPath(), this.end.getParentPath() ) == utils.compareArrays.SAME &&
-			utils.compareArrays( this.start.getParentPath(), insertPosition.getParentPath() ) == utils.compareArrays.SAME;
+		const areOnSameLevel = utils.compareArrays( this.start.getParentPath(), this.end.getParentPath() ) == 'SAME' &&
+			utils.compareArrays( this.start.getParentPath(), insertPosition.getParentPath() ) == 'SAME';
 
 		if ( this.containsPosition( insertPosition ) && ( !spreadOnlyOnSameLevel || areOnSameLevel ) ) {
 			// Range has to be spread. The first part is from original start to the spread point.

+ 30 - 60
packages/ckeditor5-engine/src/treemodel/treewalker.js

@@ -11,10 +11,22 @@ import Element from './element.js';
 import Position from './position.js';
 import CKEditorError from '../ckeditorerror.js';
 
-const ELEMENT_START = 0;
-const ELEMENT_END = 1;
-const TEXT = 2;
-const CHARACTER = 3;
+/**
+ * Type of the step made by {@link treeModel.TreeWalker}.
+ * Possible values: `'ELEMENT_START'` if walker is at the beginning of a node, `'ELEMENT_END'` if walker is at the end of node,
+ * `'CHARACTER'` if walker traversed over a character, or `'TEXT'` if walker traversed over multiple characters (available in
+ * character merging mode, see {@link treeModel.TreeWalker#constructor}).
+ *
+ * @typedef {String} treeModel.TreeWalkerItemType
+ */
+
+/**
+ * Object returned by {@link treeModel.TreeWalker} when traversing tree model.
+ *
+ * @typedef {Object} treeModel.TreeWalkerItem
+ * @property {treeModel.TreeWalkerItemType} type
+ * @property {treeModel.Node|treeModel.TextFragment} item Value between old and new position of {@link treeModel.TreeWalker}.
+ */
 
 /**
  * Position iterator class. It allows to iterate forward and backward over the tree document.
@@ -98,14 +110,11 @@ export default class TreeWalker {
 	}
 
 	/**
-	 * Moves the {@link #position} to the next position and returns the encountered value.
+	 * Makes a step forward in tree model. Moves the {@link #position} to the next position and returns the encountered value.
 	 *
-	 * @returns {Object} Value between the previous and the new {@link #position}.
+	 * @returns {Object} Object implementing iterator interface, returning information about taken step.
 	 * @returns {Boolean} return.done True if iterator is done.
-	 * @returns {Object} return.value
-	 * @returns {Number} return.value.type Encountered value type, possible options: {@link TreeWalker#ELEMENT_START},
-	 * {@link TreeWalker#ELEMENT_END}, {@link TreeWalker#CHARACTER} or {@link TreeWalker#TEXT}.
-	 * @returns {treeModel.Node} return.value.item Encountered node.
+	 * @returns {treeModel.TreeWalkerItem} return.value Information about taken step.
 	 */
 	next() {
 		const position = Position.createFromPosition( this.position );
@@ -130,7 +139,7 @@ export default class TreeWalker {
 
 			this._visitedParent = node;
 
-			return formatReturnValue( ELEMENT_START, node );
+			return formatReturnValue( 'ELEMENT_START', node );
 		} else if ( node instanceof CharacterProxy ) {
 			if ( this.mergeCharacters ) {
 				let charactersCount = node._nodeListText.text.length - node._index;
@@ -147,12 +156,12 @@ export default class TreeWalker {
 				position.offset = offset;
 				this.position = position;
 
-				return formatReturnValue( TEXT, textFragment );
+				return formatReturnValue( 'TEXT', textFragment );
 			} else {
 				position.offset++;
 				this.position = position;
 
-				return formatReturnValue( CHARACTER, node );
+				return formatReturnValue( 'CHARACTER', node );
 			}
 		} else {
 			position.path.pop();
@@ -161,19 +170,16 @@ export default class TreeWalker {
 
 			this._visitedParent = parent.parent;
 
-			return formatReturnValue( ELEMENT_END, parent );
+			return formatReturnValue( 'ELEMENT_END', parent );
 		}
 	}
 
 	/**
-	 * Moves the {@link #position} to the previous position and returns the encountered value.
+	 * Makes a step backward in tree model. Moves the {@link #position} to the previous position and returns the encountered value.
 	 *
-	 * @returns {Object} Value between the previous and the new {@link #position}.
+	 * @returns {Object} Object implementing iterator interface, returning information about taken step.
 	 * @returns {Boolean} return.done True if iterator is done.
-	 * @returns {Object} return.value
-	 * @returns {Number} return.value.type Encountered value type, possible options: {@link TreeWalker#ELEMENT_START},
-	 * {@link TreeWalker#ELEMENT_END}, {@link TreeWalker#CHARACTER} or {@link TreeWalker#TEXT}.
-	 * @returns {treeModel.Node} return.value.item Scanned node.
+	 * @returns {treeModel.TreeWalkerItem} return.value Information about taken step.
 	 */
 	previous() {
 		const position = Position.createFromPosition( this.position );
@@ -199,7 +205,7 @@ export default class TreeWalker {
 
 			this._visitedParent = node;
 
-			return formatReturnValue( ELEMENT_END, node );
+			return formatReturnValue( 'ELEMENT_END', node );
 		} else if ( node instanceof CharacterProxy ) {
 			if ( this.mergeCharacters ) {
 				let charactersCount = node._index + 1;
@@ -217,12 +223,12 @@ export default class TreeWalker {
 
 				let textFragment = new TextFragment( this.position, text );
 
-				return formatReturnValue( TEXT, textFragment );
+				return formatReturnValue( 'TEXT', textFragment );
 			} else {
 				position.offset--;
 				this.position = position;
 
-				return formatReturnValue( CHARACTER, node );
+				return formatReturnValue( 'CHARACTER', node );
 			}
 		} else {
 			position.path.pop();
@@ -230,7 +236,7 @@ export default class TreeWalker {
 
 			this._visitedParent = parent.parent;
 
-			return formatReturnValue( ELEMENT_START, parent );
+			return formatReturnValue( 'ELEMENT_START', parent );
 		}
 	}
 }
@@ -244,39 +250,3 @@ function formatReturnValue( type, item ) {
 		}
 	};
 }
-
-/**
- * Flag for encountering start of an element.
- *
- * @static
- * @readonly
- * @property {Number}
- */
-TreeWalker.ELEMENT_START = ELEMENT_START;
-
-/**
- * Flag for encountering end of an element.
- *
- * @static
- * @readonly
- * @property {Number}
- */
-TreeWalker.ELEMENT_END = ELEMENT_END;
-
-/**
- * Flag for text.
- *
- * @static
- * @readonly
- * @property {Number}
- */
-TreeWalker.TEXT = TEXT;
-
-/**
- * Flag for character.
- *
- * @static
- * @readonly
- * @property {Number}
- */
-TreeWalker.CHARACTER = CHARACTER;

+ 15 - 31
packages/ckeditor5-engine/src/utils.js

@@ -5,6 +5,13 @@
 
 'use strict';
 
+/**
+ * An index at which arrays differ. If arrays are same at all indexes, it represents how arrays are related.
+ * In this case, possible values are: 'SAME', 'PREFIX' or 'EXTENSION'.
+ *
+ * @typedef {String|Number} utils.ArrayRelation
+ */
+
 const utils = {
 	/**
 	 * Creates a spy function (ala Sinon.js) that can be used to inspect call to it.
@@ -38,7 +45,7 @@ const utils = {
 	/**
 	 * Checks if value implements iterator interface.
 	 *
-	 * @param {Mixed} value The value to check.
+	 * @param {*} value The value to check.
 	 * @returns {Boolean} True if value implements iterator interface.
 	 */
 	isIterable( value ) {
@@ -51,17 +58,15 @@ const utils = {
 	 * a flag specifying the relation is returned. Flags are negative numbers, so whenever a number >= 0 is returned
 	 * it means that arrays differ.
 	 *
-	 *   compareArrays( [ 0, 2 ], [ 0, 2 ] ); // SAME
-	 *   compareArrays( [ 0, 2 ], [ 0, 2, 1 ] ); // PREFIX
-	 *   compareArrays( [ 0, 2 ], [ 0 ] ); // EXTENSION
+	 *   compareArrays( [ 0, 2 ], [ 0, 2 ] ); // 'SAME'
+	 *   compareArrays( [ 0, 2 ], [ 0, 2, 1 ] ); // 'PREFIX'
+	 *   compareArrays( [ 0, 2 ], [ 0 ] ); // 'EXTENSION'
 	 *   compareArrays( [ 0, 2 ], [ 1, 2 ] ); // 0
 	 *   compareArrays( [ 0, 2 ], [ 0, 1 ] ); // 1
 	 *
 	 * @param {Array} a Array that is compared.
 	 * @param {Array} b Array to compare with.
-	 * @returns {Number} An index at which arrays differ, or if they do not differ, how array `a` is related to array `b`.
-	 * This is represented by one of flags: `a` is {@link utils.compareArrays#SAME same}, `a` is
-	 * a {@link utils.compareArrays#PREFIX prefix) or `a` is an {@link utils.compareArrays#EXTENSION extension}.
+	 * @returns {utils.ArrayRelation} How array `a` is related to `b`.
 	 */
 	compareArrays( a, b ) {
 		const minLen = Math.min( a.length, b.length );
@@ -76,13 +81,13 @@ const utils = {
 		// Both arrays were same at all points.
 		if ( a.length == b.length ) {
 			// If their length is also same, they are the same.
-			return utils.compareArrays.SAME;
+			return 'SAME';
 		} else if ( a.length < b.length ) {
 			// Compared array is shorter so it is a prefix of the other array.
-			return utils.compareArrays.PREFIX;
+			return 'PREFIX';
 		} else {
 			// Compared array is longer so it is an extension of the other array.
-			return utils.compareArrays.EXTENSION;
+			return 'EXTENSION';
 		}
 	},
 
@@ -105,25 +110,4 @@ const utils = {
 	}
 };
 
-/**
- * Flag for "is same as" relation between arrays.
- *
- * @type {Number}
- */
-utils.compareArrays.SAME = -1;
-
-/**
- * Flag for "is a prefix of" relation between arrays.
- *
- * @type {Number}
- */
-utils.compareArrays.PREFIX = -2;
-
-/**
- * Flag for "is a suffix of" relation between arrays.
- *
- * @type {number}
- */
-utils.compareArrays.EXTENSION = -3;
-
 export default utils;

+ 2 - 2
packages/ckeditor5-engine/tests/treemodel/liveposition.js

@@ -240,7 +240,7 @@ describe( 'LivePosition', () => {
 			} );
 
 			it( 'is at the same position and live position is sticking to left side', () => {
-				let live = new LivePosition( root, path, LivePosition.STICKS_TO_PREVIOUS );
+				let live = new LivePosition( root, path, 'STICKS_TO_PREVIOUS' );
 				let insertRange = new Range( new Position( root, [ 1, 4, 6 ] ), new Position( root, [ 1, 4, 9 ] ) );
 
 				doc.fire( 'change', 'insert', { range: insertRange }, null );
@@ -282,7 +282,7 @@ describe( 'LivePosition', () => {
 			} );
 
 			it( 'is at the same position and live position is sticking to left side', () => {
-				let live = new LivePosition( root, path, LivePosition.STICKS_TO_PREVIOUS );
+				let live = new LivePosition( root, path, 'STICKS_TO_PREVIOUS' );
 				let moveSource = new Position( root, [ 2 ] );
 				let moveRange = new Range( new Position( root, [ 1, 4, 6 ] ), new Position( root, [ 1, 4, 9 ] ) );
 

+ 8 - 8
packages/ckeditor5-engine/tests/treemodel/position.js

@@ -361,32 +361,32 @@ describe( 'position', () => {
 	} );
 
 	describe( 'compareWith', () => {
-		it( 'should return Position.SAME if positions are same', () => {
+		it( 'should return SAME if positions are same', () => {
 			const position = new Position( root, [ 1, 2, 3 ] );
 			const compared = new Position( root, [ 1, 2, 3 ] );
 
-			expect( position.compareWith( compared ) ).to.equal( Position.SAME );
+			expect( position.compareWith( compared ) ).to.equal( 'SAME' );
 		} );
 
-		it( 'should return Position.BEFORE if the position is before compared one', () => {
+		it( 'should return BEFORE if the position is before compared one', () => {
 			const position = new Position( root, [ 1, 2, 3 ] );
 			const compared = new Position( root, [ 1, 3 ] );
 
-			expect( position.compareWith( compared ) ).to.equal( Position.BEFORE );
+			expect( position.compareWith( compared ) ).to.equal( 'BEFORE' );
 		} );
 
-		it( 'should return Position.AFTER if the position is after compared one', () => {
+		it( 'should return AFTER if the position is after compared one', () => {
 			const position = new Position( root, [ 1, 2, 3, 4 ] );
 			const compared = new Position( root, [ 1, 2, 3 ] );
 
-			expect( position.compareWith( compared ) ).to.equal( Position.AFTER );
+			expect( position.compareWith( compared ) ).to.equal( 'AFTER' );
 		} );
 
-		it( 'should return Position.DIFFERENT if positions are in different roots', () => {
+		it( 'should return DIFFERENT if positions are in different roots', () => {
 			const position = new Position( root, [ 1, 2, 3 ] );
 			const compared = new Position( otherRoot, [ 1, 2, 3 ] );
 
-			expect( position.compareWith( compared ) ).to.equal( Position.DIFFERENT );
+			expect( position.compareWith( compared ) ).to.equal( 'DIFFERENT' );
 		} );
 	} );
 

+ 20 - 27
packages/ckeditor5-engine/tests/treemodel/treewalker.js

@@ -17,16 +17,9 @@ import Range from '/ckeditor5/core/treemodel/range.js';
 import CKEditorError from '/ckeditor5/core/ckeditorerror.js';
 
 describe( 'range iterator', () => {
-	let ELEMENT_START, ELEMENT_END, CHARACTER, TEXT;
-
 	let doc, expectedItems, expectedItemsMerged, root, img1, paragraph, b, a, r, img2, x;
 
 	before( () => {
-		ELEMENT_START = TreeWalker.ELEMENT_START;
-		ELEMENT_END = TreeWalker.ELEMENT_END;
-		TEXT = TreeWalker.TEXT;
-		CHARACTER = TreeWalker.CHARACTER;
-
 		doc = new Document();
 		root = doc.createRoot( 'root' );
 
@@ -55,35 +48,35 @@ describe( 'range iterator', () => {
 		root.insertChildren( 0, [ img1, paragraph ] );
 
 		expectedItems = [
-			{ type: ELEMENT_START, item: img1 },
-			{ type: ELEMENT_END, item: img1 },
-			{ type: ELEMENT_START, item: paragraph },
-			{ type: CHARACTER, text: 'b', attrs: [ attrBoldTrue ] },
-			{ type: CHARACTER, text: 'a', attrs: [ attrBoldTrue ] },
-			{ type: CHARACTER, text: 'r', attrs: [] },
-			{ type: ELEMENT_START, item: img2 },
-			{ type: ELEMENT_END, item: img2 },
-			{ type: CHARACTER, text: 'x', attrs: [] },
-			{ type: ELEMENT_END, item: paragraph }
+			{ type: 'ELEMENT_START', item: img1 },
+			{ type: 'ELEMENT_END', item: img1 },
+			{ type: 'ELEMENT_START', item: paragraph },
+			{ type: 'CHARACTER', text: 'b', attrs: [ attrBoldTrue ] },
+			{ type: 'CHARACTER', text: 'a', attrs: [ attrBoldTrue ] },
+			{ type: 'CHARACTER', text: 'r', attrs: [] },
+			{ type: 'ELEMENT_START', item: img2 },
+			{ type: 'ELEMENT_END', item: img2 },
+			{ type: 'CHARACTER', text: 'x', attrs: [] },
+			{ type: 'ELEMENT_END', item: paragraph }
 		];
 
 		expectedItemsMerged = [
-			{ type: ELEMENT_START, item: img1 },
-			{ type: ELEMENT_END, item: img1 },
-			{ type: ELEMENT_START, item: paragraph },
-			{ type: TEXT, text: 'ba', attrs: [ attrBoldTrue ] },
-			{ type: TEXT, text: 'r', attrs: [] },
-			{ type: ELEMENT_START, item: img2 },
-			{ type: ELEMENT_END, item: img2 },
-			{ type: TEXT, text: 'x', attrs: [] },
-			{ type: ELEMENT_END, item: paragraph }
+			{ type: 'ELEMENT_START', item: img1 },
+			{ type: 'ELEMENT_END', item: img1 },
+			{ type: 'ELEMENT_START', item: paragraph },
+			{ type: 'TEXT', text: 'ba', attrs: [ attrBoldTrue ] },
+			{ type: 'TEXT', text: 'r', attrs: [] },
+			{ type: 'ELEMENT_START', item: img2 },
+			{ type: 'ELEMENT_END', item: img2 },
+			{ type: 'TEXT', text: 'x', attrs: [] },
+			{ type: 'ELEMENT_END', item: paragraph }
 		];
 	} );
 
 	function expectItem( item, expected ) {
 		expect( item.done ).to.be.false;
 
-		if ( item.value.type == TEXT || item.value.type == CHARACTER ) {
+		if ( item.value.type == 'TEXT' || item.value.type == 'CHARACTER' ) {
 			let text = item.value.item.text || item.value.item.character;
 
 			expect( text ).to.equal( expected.text );

+ 3 - 3
packages/ckeditor5-engine/tests/utils.js

@@ -85,7 +85,7 @@ describe( 'utils', () => {
 
 			let result = utils.compareArrays( a, b );
 
-			expect( result ).to.equal( utils.compareArrays.SAME );
+			expect( result ).to.equal( 'SAME' );
 		} );
 
 		it( 'should return PREFIX flag, when all n elements of first array are same as n first elements of the second array', () => {
@@ -94,7 +94,7 @@ describe( 'utils', () => {
 
 			let result = utils.compareArrays( a, b );
 
-			expect( result ).to.equal( utils.compareArrays.PREFIX );
+			expect( result ).to.equal( 'PREFIX' );
 		} );
 
 		it( 'should return EXTENSION flag, when n first elements of first array are same as all elements of the second array', () => {
@@ -103,7 +103,7 @@ describe( 'utils', () => {
 
 			let result = utils.compareArrays( a, b );
 
-			expect( result ).to.equal( utils.compareArrays.EXTENSION );
+			expect( result ).to.equal( 'EXTENSION' );
 		} );
 
 		it( 'should return index on which arrays differ, when arrays are not the same', () => {