Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cjs/interface/document-fragment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const {DOCUMENT_FRAGMENT_NODE} = require('../shared/constants.js');
const {DOCUMENT_FRAGMENT_NODE, TEXT_NODE} = require('../shared/constants.js');
const {NonElementParentNode} = require('../mixin/non-element-parent-node.js');
const {NEXT, END} = require('../shared/symbols.js')

/**
* @implements globalThis.DocumentFragment
Expand All @@ -9,5 +10,16 @@ class DocumentFragment extends NonElementParentNode {
constructor(ownerDocument) {
super(ownerDocument, '#document-fragment', DOCUMENT_FRAGMENT_NODE);
}

get textContent() {
const text = [];
let {[NEXT]: next, [END]: end} = this;
while (next !== end) {
if (next.nodeType === TEXT_NODE)
text.push(next.data);
next = next[NEXT];
}
return text.join('');
}
}
exports.DocumentFragment = DocumentFragment
14 changes: 13 additions & 1 deletion esm/interface/document-fragment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {DOCUMENT_FRAGMENT_NODE} from '../shared/constants.js';
import {DOCUMENT_FRAGMENT_NODE, TEXT_NODE} from '../shared/constants.js';
import {NonElementParentNode} from '../mixin/non-element-parent-node.js';
import {NEXT, END} from '../shared/symbols.js'

/**
* @implements globalThis.DocumentFragment
Expand All @@ -8,4 +9,15 @@ export class DocumentFragment extends NonElementParentNode {
constructor(ownerDocument) {
super(ownerDocument, '#document-fragment', DOCUMENT_FRAGMENT_NODE);
}

get textContent() {
const text = [];
let {[NEXT]: next, [END]: end} = this;
while (next !== end) {
if (next.nodeType === TEXT_NODE)
text.push(next.data);
next = next[NEXT];
}
return text.join('');
}
}
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
11 changes: 11 additions & 0 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7168,6 +7168,17 @@ let DocumentFragment$1 = class DocumentFragment extends NonElementParentNode {
constructor(ownerDocument) {
super(ownerDocument, '#document-fragment', DOCUMENT_FRAGMENT_NODE);
}

get textContent() {
const text = [];
let {[NEXT]: next, [END]: end} = this;
while (next !== end) {
if (next.nodeType === TEXT_NODE)
text.push(next.data);
next = next[NEXT];
}
return text.join('');
}
};

/**
Expand Down