From a67971a3024fefbcc3ecebc773ecde00382ceed8 Mon Sep 17 00:00:00 2001 From: Max Milton Date: Sun, 7 Aug 2022 16:57:11 +1000 Subject: [PATCH] #558@patch: Additional TreeWalker checks for parentNode. --- packages/happy-dom/src/tree-walker/TreeWalker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/happy-dom/src/tree-walker/TreeWalker.ts b/packages/happy-dom/src/tree-walker/TreeWalker.ts index bd056bd40..6a94b8ffe 100644 --- a/packages/happy-dom/src/tree-walker/TreeWalker.ts +++ b/packages/happy-dom/src/tree-walker/TreeWalker.ts @@ -125,7 +125,7 @@ export default class TreeWalker { * @returns Current node. */ public previousSibling(): INode { - if (this.currentNode !== this.root && this.currentNode) { + if (this.currentNode !== this.root && this.currentNode && this.currentNode.parentNode) { const siblings = this.currentNode.parentNode.childNodes; const index = siblings.indexOf(this.currentNode); @@ -149,7 +149,7 @@ export default class TreeWalker { * @returns Current node. */ public nextSibling(): INode { - if (this.currentNode !== this.root && this.currentNode) { + if (this.currentNode !== this.root && this.currentNode && this.currentNode.parentNode) { const siblings = this.currentNode.parentNode.childNodes; const index = siblings.indexOf(this.currentNode);