From 5c398fccc970cf74b857ea5c191b325564f9893f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 14 Feb 2014 15:41:51 +0100 Subject: [PATCH 1/1] 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. --- src/smartxml/core.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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) { -- 2.20.1