Skip to content

Commit

Permalink
last commit again
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehmet Coskun committed Feb 22, 2019
1 parent 4ab5905 commit 3196d08
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
27 changes: 19 additions & 8 deletions src/expressions/xquery-update/TransformExpression.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import IDocumentWriter from '../../documentWriter/IDocumentWriter';
import { ConcreteElementNode, ConcreteNode, NODE_TYPES } from '../../domFacade/ConcreteNode';
import {
ConcreteDocumentNode,
ConcreteElementNode,
ConcreteNode,
NODE_TYPES
} from '../../domFacade/ConcreteNode';
import IWrappingDomFacade from '../../domFacade/IWrappingDomFacade';
import INodesFactory from '../../nodesFactory/INodesFactory';
import createNodeValue from '../dataTypes/createNodeValue';
Expand Down Expand Up @@ -43,7 +48,6 @@ function deepCloneNode(
attr.value
)
);

for (const child of domFacade.getChildNodes(node)) {
const descendant = deepCloneNode(child, domFacade, nodesFactory, documentWriter);
documentWriter.insertBefore(cloneElem as ConcreteElementNode, descendant, null);
Expand All @@ -53,14 +57,21 @@ function deepCloneNode(
const cloneAttr = nodesFactory.createAttributeNS(node.namespaceURI, node.nodeName);
cloneAttr.value = node.value;
return cloneAttr;
case NODE_TYPES.TEXT_NODE:
return nodesFactory.createTextNode(node.data);
case NODE_TYPES.PROCESSING_INSTRUCTION_NODE:
return nodesFactory.createProcessingInstruction(node.target, node.data);
case NODE_TYPES.COMMENT_NODE:
return nodesFactory.createComment(node.data);
case NODE_TYPES.CDATA_SECTION_NODE:
return nodesFactory.createCDATASection(node.data);
case NODE_TYPES.COMMENT_NODE:
return nodesFactory.createComment(node.data);
case NODE_TYPES.DOCUMENT_NODE:
const cloneDoc = nodesFactory.createDocument();
for (const child of domFacade.getChildNodes(node)) {
const descendant = deepCloneNode(child, domFacade, nodesFactory, documentWriter);
documentWriter.insertBefore(cloneDoc as ConcreteDocumentNode, descendant, null);
}
return cloneDoc;
case NODE_TYPES.PROCESSING_INSTRUCTION_NODE:
return nodesFactory.createProcessingInstruction(node.target, node.data);
case NODE_TYPES.TEXT_NODE:
return nodesFactory.createTextNode(node.data);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/nodesFactory/DomBackedNodesFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ export default class DomBackedNodesFactory implements INodesFactory {
return this._documentNode.createComment(contents);
}

public createDocument() {
if (!this._documentNode) {
throw new Error(
'Please pass a node factory if an XQuery script uses node constructors'
);
}
return this._documentNode.implementation.createDocument(null, null, null);
}

public createElementNS(namespaceURI, name) {
if (!this._documentNode) {
throw new Error(
Expand Down
2 changes: 2 additions & 0 deletions src/nodesFactory/INodesFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export default interface INodesFactory {

createComment(contents: string): Comment;

createDocument(): Document;

createElementNS(namespaceURI: string, name: string): Element;

createProcessingInstruction(target: string, data: string): ProcessingInstruction;
Expand Down
4 changes: 4 additions & 0 deletions src/nodesFactory/wrapExternalNodesFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class WrappingNodesFactory implements INodesFactory {
return this._externalNodesFactory['createComment'](contents);
}

public createDocument() {
return this._externalNodesFactory['createDocument']();
}

public createElementNS(namespaceURI, name) {
return this._externalNodesFactory['createElementNS'](namespaceURI, name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('evaluateUpdatingExpression', () => {
},
createDocument: () => {
createDocumentCalled = true;
return documentNode.createDocument();
return documentNode.implementation.createDocument();
},
createElementNS: (namespaceURI, localName) => {
createElementNSCalled = true;
Expand Down

0 comments on commit 3196d08

Please sign in to comment.