MCPcopy
hub / github.com/stenciljs/core / MockNode

Class MockNode

src/mock-doc/node.ts:19–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17import { MockTokenList } from './token-list';
18
19export class MockNode {
20 private _nodeValue: string | null;
21 nodeName: string | null;
22 nodeType: number;
23 ownerDocument: any;
24 parentNode: MockNode | null;
25 private _childNodes: MockNode[] = [];
26
27 constructor(ownerDocument: any, nodeType: number, nodeName: string | null, nodeValue: string | null) {
28 this.ownerDocument = ownerDocument;
29 this.nodeType = nodeType;
30 this.nodeName = nodeName;
31 this._nodeValue = nodeValue;
32 this.parentNode = null;
33 }
34
35 get childNodes(): MockNode[] {
36 return this._childNodes;
37 }
38 set childNodes(value: MockNode[]) {
39 this._childNodes = value;
40 }
41
42 appendChild(newNode: MockNode) {
43 if (newNode.nodeType === NODE_TYPES.DOCUMENT_FRAGMENT_NODE) {
44 const nodes = newNode.childNodes.slice();
45 for (const child of nodes) {
46 this.appendChild(child);
47 }
48 } else {
49 newNode.remove();
50 newNode.parentNode = this;
51 this.childNodes.push(newNode);
52 connectNode(this.ownerDocument, newNode);
53 }
54 return newNode;
55 }
56
57 append(...items: (MockNode | string)[]) {
58 items.forEach((item) => {
59 const isNode = typeof item === 'object' && item !== null && 'nodeType' in item;
60 this.appendChild(isNode ? item : this.ownerDocument.createTextNode(String(item)));
61 });
62 }
63
64 prepend(...items: (MockNode | string)[]) {
65 const firstChild = this.firstChild;
66 items.forEach((item) => {
67 const isNode = typeof item === 'object' && item !== null && 'nodeType' in item;
68 this.insertBefore(isNode ? item : this.ownerDocument.createTextNode(String(item)), firstChild);
69 });
70 }
71
72 cloneNode(deep?: boolean): MockNode {
73 throw new Error(`invalid node type to clone: ${this.nodeType}, deep: ${deep}`);
74 }
75
76 compareDocumentPosition(_other: MockNode) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected