smartxml: Throw an error on invalid argument to replaceWith method
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 14 Feb 2014 14:41:51 +0000 (15:41 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 14 Feb 2014 14:46:54 +0000 (15:46 +0100)
Replacing node without any context doesn't actually make sense and
is probably an error of the client code.

src/smartxml/core.js

index ae445e0..ba612b4 100644 (file)
@@ -45,9 +45,12 @@ var documentNodeTransformations = {
         if(this.isRoot()) {
             return this.document.replaceRoot(node);
         }
-        toret = this.after(node);
-        this.detach();
-        return toret;
+        if(this.parent()) {
+            toret = this.after(node);
+            this.detach();
+            return toret;
+        }
+        throw new Error('Cannot replace node without a parent.');
     },
 
     after: INSERTION(function(node) {