88// Dummy implmentation for the logging functions. Replace by something
99// useful when you want to debug.
1010
11- import {
12- DOM_ATTRIBUTE_NODE ,
13- DOM_CDATA_SECTION_NODE ,
14- DOM_COMMENT_NODE ,
15- DOM_DOCUMENT_FRAGMENT_NODE ,
16- DOM_DOCUMENT_NODE ,
17- DOM_ELEMENT_NODE ,
18- DOM_TEXT_NODE
19- } from '../constants' ;
11+
2012import { FunctionCallExpr , BinaryExpr , UnaryMinusExpr , NumberExpr } from '../xpath/expressions' ;
21- import { XDocument } from './xdocument' ;
22- import { XNode } from './xnode' ;
2313
2414// Throws an exception if false.
2515export function assert ( b ) {
@@ -83,132 +73,6 @@ export function copyArrayIgnoringAttributesWithoutValue(dst, src) {
8373 }
8474}
8575
86- // Returns the text value of a node; for nodes without children this
87- // is the nodeValue, for nodes with children this is the concatenation
88- // of the value of all children. Browser-specific optimizations are used by
89- // default; they can be disabled by passing "true" in as the second parameter.
90- export function xmlValue ( node : any , disallowBrowserSpecificOptimization : boolean = false ) {
91- if ( ! node ) {
92- return '' ;
93- }
94-
95- let ret = '' ;
96- if ( node . nodeType == DOM_TEXT_NODE || node . nodeType == DOM_CDATA_SECTION_NODE ) {
97- ret += node . nodeValue ;
98- } else if ( node . nodeType == DOM_ATTRIBUTE_NODE ) {
99- ret += node . nodeValue ;
100- } else if (
101- node . nodeType == DOM_ELEMENT_NODE ||
102- node . nodeType == DOM_DOCUMENT_NODE ||
103- node . nodeType == DOM_DOCUMENT_FRAGMENT_NODE
104- ) {
105- if ( ! disallowBrowserSpecificOptimization ) {
106- // IE, Safari, Opera, and friends
107- const innerText = node . innerText ;
108- if ( innerText != undefined ) {
109- return innerText ;
110- }
111- // Firefox
112- const textContent = node . textContent ;
113- if ( textContent != undefined ) {
114- return textContent ;
115- }
116- }
117- // pobrecito!
118- const len = node . childNodes . length ;
119- for ( let i = 0 ; i < len ; ++ i ) {
120- ret += xmlValue ( node . childNodes [ i ] ) ;
121- }
122- }
123- return ret ;
124- }
125-
126- // Returns the representation of a node as XML text.
127- export function xmlText ( node : any , opt_cdata : boolean = false ) {
128- const buf = [ ] ;
129- xmlTextR ( node , buf , opt_cdata ) ;
130- return buf . join ( '' ) ;
131- }
132-
133- function xmlTextR ( node , buf , cdata ) {
134- if ( node . nodeType == DOM_TEXT_NODE ) {
135- buf . push ( xmlEscapeText ( node . nodeValue ) ) ;
136- } else if ( node . nodeType == DOM_CDATA_SECTION_NODE ) {
137- if ( cdata ) {
138- buf . push ( node . nodeValue ) ;
139- } else {
140- buf . push ( `<![CDATA[${ node . nodeValue } ]]>` ) ;
141- }
142- } else if ( node . nodeType == DOM_COMMENT_NODE ) {
143- buf . push ( `<!--${ node . nodeValue } -->` ) ;
144- } else if ( node . nodeType == DOM_ELEMENT_NODE ) {
145- buf . push ( `<${ xmlFullNodeName ( node ) } ` ) ;
146- for ( let i = 0 ; i < node . attributes . length ; ++ i ) {
147- const a = node . attributes [ i ] ;
148- if ( a && a . nodeName && a . nodeValue ) {
149- buf . push ( ` ${ xmlFullNodeName ( a ) } ="${ xmlEscapeAttr ( a . nodeValue ) } "` ) ;
150- }
151- }
152-
153- if ( node . childNodes . length == 0 ) {
154- buf . push ( '/>' ) ;
155- } else {
156- buf . push ( '>' ) ;
157- for ( let i = 0 ; i < node . childNodes . length ; ++ i ) {
158- xmlTextR ( node . childNodes [ i ] , buf , cdata ) ;
159- }
160- buf . push ( `</${ xmlFullNodeName ( node ) } >` ) ;
161- }
162- } else if ( node . nodeType == DOM_DOCUMENT_NODE || node . nodeType == DOM_DOCUMENT_FRAGMENT_NODE ) {
163- for ( let i = 0 ; i < node . childNodes . length ; ++ i ) {
164- xmlTextR ( node . childNodes [ i ] , buf , cdata ) ;
165- }
166- }
167- }
168-
169- function xmlFullNodeName ( n ) {
170- if ( n . prefix && n . nodeName . indexOf ( `${ n . prefix } :` ) != 0 ) {
171- return `${ n . prefix } :${ n . nodeName } ` ;
172- } else {
173- return n . nodeName ;
174- }
175- }
176-
177- // Escape XML special markup chracters: tag delimiter < > and entity
178- // reference start delimiter &. The escaped string can be used in XML
179- // text portions (i.e. between tags).
180- export function xmlEscapeText ( s ) {
181- return `${ s } `
182- . replace ( / & / g, '&' )
183- . replace ( / & a m p ; a m p ; / g, '&' )
184- . replace ( / < / g, '<' )
185- . replace ( / > / g, '>' ) ;
186- }
187-
188- // Escape XML special markup characters: tag delimiter < > entity
189- // reference start delimiter & and quotes ". The escaped string can be
190- // used in double quoted XML attribute value portions (i.e. in
191- // attributes within start tags).
192- function xmlEscapeAttr ( s ) {
193- return xmlEscapeText ( s ) . replace ( / " / g, '"' ) ;
194- }
195-
196- /**
197- * Wrapper function to access the owner document uniformly for document
198- * and other nodes: for the document node, the owner document is the
199- * node itself, for all others it's the ownerDocument property.
200- *
201- * @param {Node } node
202- * @return {Document }
203- */
204- export function xmlOwnerDocument ( node : any ) {
205- if ( node . nodeType == DOM_DOCUMENT_NODE ) {
206- return node ;
207- }
208-
209- return node . ownerDocument ;
210- }
211-
21276/**
21377 * Escape the special regular expression characters when the regular expression
21478 * is specified as a string.
@@ -265,9 +129,13 @@ function exprReturnsNumberValue(expr) {
265129 round : true
266130 } ;
267131 return isMember [ ( expr as any ) . name . value ] ;
268- } else if ( expr instanceof UnaryMinusExpr ) {
132+ }
133+
134+ if ( expr instanceof UnaryMinusExpr ) {
269135 return true ;
270- } else if ( expr instanceof BinaryExpr ) {
136+ }
137+
138+ if ( expr instanceof BinaryExpr ) {
271139 let isMember = {
272140 '+' : true ,
273141 '-' : true ,
@@ -276,15 +144,18 @@ function exprReturnsNumberValue(expr) {
276144 div : true
277145 } ;
278146 return isMember [ expr . op . value ] ;
279- } else if ( expr instanceof NumberExpr ) {
147+ }
148+
149+ if ( expr instanceof NumberExpr ) {
280150 return true ;
281151 }
152+
282153 return false ;
283154}
284155
285156// (viat) given an XNode (see dom.js), returns an object mapping prefixes to their corresponding namespaces in its scope.
286157// default namespace is treated as if its prefix were the empty string.
287- export function namespaceMapAt ( node ) {
158+ export function namespaceMapAt ( node : any ) {
288159 const map = {
289160 // reserved namespaces https://www.w3.org/TR/REC-xml-names/#xmlReserved
290161 xmlns : 'http://www.w3.org/2000/xmlns/' ,
0 commit comments