Esanders has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/280842

Change subject: Allow toDataElement to return an empty array
......................................................................

Allow toDataElement to return an empty array

This would probably be a bad thing to do in most normal cases
as you would be throwing away document information, but
this is an improvement over throwing an uncaught exception.

Change-Id: I9de60605a94011b60c48275bbe2bd2df6ab72009
---
M src/dm/ve.dm.Converter.js
1 file changed, 6 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/42/280842/1

diff --git a/src/dm/ve.dm.Converter.js b/src/dm/ve.dm.Converter.js
index ab21199..bda9b66 100644
--- a/src/dm/ve.dm.Converter.js
+++ b/src/dm/ve.dm.Converter.js
@@ -389,7 +389,9 @@
        if ( !Array.isArray( dataElements ) ) {
                dataElements = [ dataElements ];
        }
-       dataElements[ 0 ].originalDomElements = domElements;
+       if ( dataElements.length ) {
+               dataElements[ 0 ].originalDomElements = domElements;
+       }
        return dataElements;
 };
 
@@ -679,9 +681,11 @@
                                        childNodes = 
modelClass.static.enableAboutGrouping ?
                                                aboutGroup : [ childNode ];
                                        childDataElements = 
this.createDataElements( modelClass, childNodes );
-                               } else {
+                               } else if ( childDataElements.length ) {
                                        // Update modelClass to reflect the 
type we got back
                                        modelClass = this.modelRegistry.lookup( 
childDataElements[ 0 ].type );
+                               } else {
+                                       continue;
                                }
 
                                // Now take the appropriate action based on that

-- 
To view, visit https://gerrit.wikimedia.org/r/280842
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9de60605a94011b60c48275bbe2bd2df6ab72009
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to