Skip to content

Commit

Permalink
+ DocumentFragment.textContent
Browse files Browse the repository at this point in the history
  • Loading branch information
iacore committed Jun 9, 2024
1 parent 7a9720d commit d3fda1d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cjs/interface/document-fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,15 @@ class DocumentFragment extends NonElementParentNode {
constructor(ownerDocument) {
super(ownerDocument, '#document-fragment', DOCUMENT_FRAGMENT_NODE);
}

get textContent() {
let r = ""
let curr = this.firstChild
while (curr) {
r += curr.textContent
curr = curr.nextSibling
}
return r;
}
}
exports.DocumentFragment = DocumentFragment
10 changes: 10 additions & 0 deletions esm/interface/document-fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ export class DocumentFragment extends NonElementParentNode {
constructor(ownerDocument) {
super(ownerDocument, '#document-fragment', DOCUMENT_FRAGMENT_NODE);
}

get textContent() {
let r = ""
let curr = this.firstChild
while (curr) {
r += curr.textContent
curr = curr.nextSibling
}
return r;
}
}
2 changes: 2 additions & 0 deletions test/interface/document-fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ assert(node.firstElementChild, node.lastElementChild, 'element child');
node.prepend('a');
node.append('b');
assert(node.toString(), '<#document-fragment>a<div id="any"></div>b</#document-fragment>', 'expected content');
assert(node.textContent, 'ab', 'expected textContent');
node.replaceChildren('c', 'd');
assert(node.toString(), '<#document-fragment>cd</#document-fragment>', 'expected content');
assert(node.textContent, 'cd', 'expected textContent');
node.normalize();
assert(node.childNodes.length, 1, 'normalize()');
node.replaceChild(document.createElement('input'), node.firstChild);
Expand Down
1 change: 1 addition & 0 deletions types/esm/interface/document-fragment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
*/
export class DocumentFragment extends NonElementParentNode implements globalThis.DocumentFragment {
constructor(ownerDocument: any);
get textContent(): string;
}
import { NonElementParentNode } from '../mixin/non-element-parent-node.js';
3 changes: 0 additions & 3 deletions types/esm/mixin/parent-node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ import { Node } from '../interface/node.js';
import { NodeList } from '../interface/node-list.js';
import { PRIVATE } from '../shared/symbols.js';
import { END } from '../shared/symbols.js';
import { NEXT } from '../shared/symbols.js';
import { PREV } from '../shared/symbols.js';
import { START } from '../shared/symbols.js';
import { ATTRIBUTE_NODE } from '../shared/constants.js';
import { DOCUMENT_FRAGMENT_NODE } from '../shared/constants.js';
import { ELEMENT_NODE } from '../shared/constants.js';
Expand Down
10 changes: 10 additions & 0 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7168,6 +7168,16 @@ let DocumentFragment$1 = class DocumentFragment extends NonElementParentNode {
constructor(ownerDocument) {
super(ownerDocument, '#document-fragment', DOCUMENT_FRAGMENT_NODE);
}

get textContent() {
let r = "";
let curr = this.firstChild;
while (curr) {
r += curr.textContent;
curr = curr.nextSibling;
}
return r;
}
};

/**
Expand Down

0 comments on commit d3fda1d

Please sign in to comment.