From: Aleksander Ɓukasz Date: Fri, 14 Feb 2014 14:41:51 +0000 (+0100) Subject: smartxml: Throw an error on invalid argument to replaceWith method X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/5c398fccc970cf74b857ea5c191b325564f9893f?hp=729243168cee79db77626f00e5b0073f692aba2e smartxml: Throw an error on invalid argument to replaceWith method Replacing node without any context doesn't actually make sense and is probably an error of the client code. --- diff --git a/src/smartxml/core.js b/src/smartxml/core.js index ae445e0..ba612b4 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -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) {