smartxml: Throw an error on invalid argument to replaceWith method
[fnpeditor.git] / 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) {