Skip to content

Commit

Permalink
Fix hasChildNodes method.
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardocavazza committed Dec 12, 2023
1 parent 48c4b21 commit 82218d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-taxis-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chialab/quantum': patch
---

Fix `hasChildNodes` method.
17 changes: 8 additions & 9 deletions src/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,31 @@ export function extendNode(Node) {
},
});

defineProperty(NodePrototype, 'childNodes', {
defineProperty(NodePrototype, 'hasChildNodes', {
/**
* @this {Node}
*/
get() {
value() {
const realm = getRealm(this);
if (!realm) {
return /** @type {import('./utils.js').GetterDescriptor} */ (childNodes).get.call(this);
return /** @type {import('./utils.js').ValueDescriptor} */ (hasChildNodes).value.call(this);
}
return createNodeList(realm.childNodes);
return !!realm.childNodes.length;
},
set: childNodes.set,
});

defineProperty(NodePrototype, 'hasChildNodes', {
defineProperty(NodePrototype, 'childNodes', {
/**
* @this {Node}
*/
get() {
const realm = getRealm(this);
if (!realm) {
return /** @type {import('./utils.js').ValueDescriptor} */ (hasChildNodes).value.call(this);
return /** @type {import('./utils.js').GetterDescriptor} */ (childNodes).get.call(this);
}
return !!realm.childNodes.length;
return createNodeList(realm.childNodes);
},
set: hasChildNodes.set,
set: childNodes.set,
});

defineProperty(NodePrototype, 'firstChild', {
Expand Down

0 comments on commit 82218d2

Please sign in to comment.