Przeglądaj źródła

Fixed errors/warnings.

Maciej Bukowski 6 lat temu
rodzic
commit
fe519715a0

+ 6 - 7
packages/ckeditor5-engine/src/conversion/downcasthelpers.js

@@ -9,7 +9,7 @@
  * @module engine/conversion/downcasthelpers
  */
 
-/* globals console */
+/* globals */
 
 import ModelRange from '../model/range';
 import ModelSelection from '../model/selection';
@@ -20,7 +20,7 @@ import DocumentSelection from '../model/documentselection';
 import ConversionHelpers from './conversionhelpers';
 
 import { cloneDeep } from 'lodash-es';
-import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 /**
  * Downcast conversion helper functions.
@@ -826,12 +826,11 @@ function changeAttribute( attributeCreator ) {
 			 *
 			 * @error conversion-attribute-to-attribute-on-text
 			 */
-			console.warn( attachLinkToDocumentation(
+			throw new CKEditorError(
 				'conversion-attribute-to-attribute-on-text: ' +
-				'Trying to convert text node\'s attribute with attribute-to-attribute converter.'
-			) );
-
-			return;
+				'Trying to convert text node\'s attribute with attribute-to-attribute converter.',
+				[ data, conversionApi ]
+			);
 		}
 
 		// First remove the old attribute if there was one.

+ 8 - 2
packages/ckeditor5-engine/src/model/utils/insertcontent.js

@@ -15,7 +15,7 @@ import Element from '../element';
 import Range from '../range';
 import DocumentSelection from '../documentselection';
 import Selection from '../selection';
-import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+import CKEditorError, { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 /**
  * Inserts content into the editor (specified selection) as one would expect the paste
@@ -438,7 +438,13 @@ class Insertion {
 				// Algorithm's correctness check. We should never end up here but it's good to know that we did.
 				// At this point the insertion position should be after the node we'll merge. If it isn't,
 				// it should need to be secured as in the left merge case.
-				// @if CK_DEBUG // console.error( 'The insertion position should equal the merge position' );
+				/**
+				 * An internal error occured during merging insertion content with siblings.
+				 * The insertion position should equal to the merge position.
+				 *
+				 * @error insertcontent-invalid-insertion-position
+				 */
+				throw new CKEditorError( 'insertcontent-invalid-insertion-position', this );
 			}
 
 			// Move the position to the previous node, so it isn't moved to the graveyard on merge.

+ 9 - 18
packages/ckeditor5-engine/tests/conversion/downcasthelpers.js

@@ -33,6 +33,7 @@ import { stringify as stringifyView } from '../../src/dev-utils/view';
 import View from '../../src/view/view';
 import createViewRoot from '../view/_utils/createroot';
 import { setData as setModelData } from '../../src/dev-utils/model';
+import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
 
 describe( 'DowncastHelpers', () => {
 	let model, modelRoot, viewRoot, downcastHelpers, controller;
@@ -638,29 +639,19 @@ describe( 'DowncastHelpers', () => {
 
 		// #1587
 		it( 'config.view and config.model as strings in generic conversion (elements + text)', () => {
-			const consoleWarnStub = testUtils.sinon.stub( console, 'warn' );
-
 			downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );
 
 			downcastHelpers.attributeToAttribute( { model: 'test', view: 'test' } );
 
-			model.change( writer => {
-				writer.insertElement( 'paragraph', modelRoot, 0 );
-				writer.insertElement( 'paragraph', { test: '1' }, modelRoot, 1 );
-
-				writer.insertText( 'Foo', { test: '2' }, modelRoot.getChild( 0 ), 0 );
-				writer.insertText( 'Bar', { test: '3' }, modelRoot.getChild( 1 ), 0 );
-			} );
-
-			expectResult( '<p>Foo</p><p test="1">Bar</p>' );
-			expect( consoleWarnStub.callCount ).to.equal( 2 );
-			expect( consoleWarnStub.alwaysCalledWithMatch( 'conversion-attribute-to-attribute-on-text' ) ).to.true;
-
-			model.change( writer => {
-				writer.removeAttribute( 'test', modelRoot.getChild( 1 ) );
-			} );
+			expectToThrowCKEditorError( () => {
+				model.change( writer => {
+					writer.insertElement( 'paragraph', modelRoot, 0 );
+					writer.insertElement( 'paragraph', { test: '1' }, modelRoot, 1 );
 
-			expectResult( '<p>Foo</p><p>Bar</p>' );
+					writer.insertText( 'Foo', { test: '2' }, modelRoot.getChild( 0 ), 0 );
+					writer.insertText( 'Bar', { test: '3' }, modelRoot.getChild( 1 ), 0 );
+				} );
+			}, /^conversion-attribute-to-attribute-on-text/ );
 		} );
 
 		it( 'should convert attribute insert/change/remove on a model node', () => {