fast-xml-parser 5.3.0 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,6 +55,20 @@ export default class OrderedObjParser{
55
55
  this.saveTextToParentTag = saveTextToParentTag;
56
56
  this.addChild = addChild;
57
57
  this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
58
+
59
+ if(this.options.stopNodes && this.options.stopNodes.length > 0){
60
+ this.stopNodesExact = new Set();
61
+ this.stopNodesWildcard = new Set();
62
+ for(let i = 0; i < this.options.stopNodes.length; i++){
63
+ const stopNodeExp = this.options.stopNodes[i];
64
+ if(typeof stopNodeExp !== 'string') continue;
65
+ if(stopNodeExp.startsWith("*.")){
66
+ this.stopNodesWildcard.add(stopNodeExp.substring(2));
67
+ }else{
68
+ this.stopNodesExact.add(stopNodeExp);
69
+ }
70
+ }
71
+ }
58
72
  }
59
73
 
60
74
  }
@@ -313,7 +327,7 @@ const parseXml = function(xmlData) {
313
327
  jPath += jPath ? "." + tagName : tagName;
314
328
  }
315
329
  const startIndex = i;
316
- if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
330
+ if (this.isItStopNode(this.stopNodesExact, this.stopNodesWildcard, jPath, tagName)) {
317
331
  let tagContent = "";
318
332
  //self-closing tag
319
333
  if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
@@ -451,17 +465,14 @@ function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
451
465
 
452
466
  //TODO: use jPath to simplify the logic
453
467
  /**
454
- *
455
- * @param {string[]} stopNodes
468
+ * @param {Set} stopNodesExact
469
+ * @param {Set} stopNodesWildcard
456
470
  * @param {string} jPath
457
- * @param {string} currentTagName
471
+ * @param {string} currentTagName
458
472
  */
459
- function isItStopNode(stopNodes, jPath, currentTagName){
460
- const allNodesExp = "*." + currentTagName;
461
- for (const stopNodePath in stopNodes) {
462
- const stopNodeExp = stopNodes[stopNodePath];
463
- if( allNodesExp === stopNodeExp || jPath === stopNodeExp ) return true;
464
- }
473
+ function isItStopNode(stopNodesExact, stopNodesWildcard, jPath, currentTagName){
474
+ if(stopNodesWildcard && stopNodesWildcard.has(currentTagName)) return true;
475
+ if(stopNodesExact && stopNodesExact.has(jPath)) return true;
465
476
  return false;
466
477
  }
467
478