Skip to content

Commit fec1e56

Browse files
committed
Integrate ExpressionSet
1 parent f20e2bf commit fec1e56

5 files changed

Lines changed: 25 additions & 27 deletions

File tree

docs/CHECK_LIST.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Pre release
22
* [ ] npm audit and yarn audit is done
3+
* [ ] change in local package installation
34
* [ ] update pem.d.ts when there is any change path-expression-matcher package
45
* [ ] Change log has been updated
56
* [ ] Added/updated documentation for new properties/features
@@ -15,7 +16,7 @@ Pre release
1516
* [ ] ReadMe file or docs are updated for any change, user list, performance report, links etc.
1617
* [ ] Single test is not running `fit`
1718
* [ ] `npm run checkReadiness` is used to check the files being published
18-
* [ ] tags are assigned to latest commit `git tag -a v3.20.0 -m "summary msg"`
19+
* [ ] tags are assigned to latest commit `git tag -a v5.5.11 -m "ExpressionSet"`
1920

2021
In general
2122
* [ ] tests are added/updated

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
],
8989
"dependencies": {
9090
"fast-xml-builder": "^1.1.4",
91-
"path-expression-matcher": "^1.2.1",
91+
"path-expression-matcher": "^1.3.0",
9292
"strnum": "^2.2.2"
9393
}
94-
}
94+
}

src/xmlparser/OrderedObjParser.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import DocTypeReader from './DocTypeReader.js';
77
import toNumber from "strnum";
88
import getIgnoreAttributesFn from "../ignoreAttributes.js";
99
import { Expression, Matcher } from 'path-expression-matcher';
10+
import { ExpressionSet } from 'path-expression-matcher';
1011

1112
// const regx =
1213
// '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
@@ -121,19 +122,20 @@ export default class OrderedObjParser {
121122
this.isCurrentNodeStopNode = false;
122123

123124
// Pre-compile stopNodes expressions
125+
this.stopNodeExpressionsSet = new ExpressionSet();
124126
const stopNodesOpts = this.options.stopNodes;
125127
if (stopNodesOpts && stopNodesOpts.length > 0) {
126-
this.stopNodeExpressions = [];
127128
for (let i = 0; i < stopNodesOpts.length; i++) {
128129
const stopNodeExp = stopNodesOpts[i];
129130
if (typeof stopNodeExp === 'string') {
130131
// Convert string to Expression object
131-
this.stopNodeExpressions.push(new Expression(stopNodeExp));
132+
this.stopNodeExpressionsSet.add(new Expression(stopNodeExp));
132133
} else if (stopNodeExp instanceof Expression) {
133134
// Already an Expression object
134-
this.stopNodeExpressions.push(stopNodeExp);
135+
this.stopNodeExpressionsSet.add(stopNodeExp);
135136
}
136137
}
138+
this.stopNodeExpressionsSet.seal();
137139
}
138140
}
139141

@@ -494,7 +496,7 @@ const parseXml = function (xmlData) {
494496

495497
// Now check if this is a stop node (after attributes are set)
496498
if (tagName !== xmlObj.tagname) {
497-
this.isCurrentNodeStopNode = this.isItStopNode(this.stopNodeExpressions, this.matcher);
499+
this.isCurrentNodeStopNode = this.isItStopNode();
498500
}
499501

500502
const startIndex = i;
@@ -727,15 +729,10 @@ function saveTextToParentTag(textData, parentNode, matcher, isLeafNode) {
727729
* @param {Array<Expression>} stopNodeExpressions - Array of compiled Expression objects
728730
* @param {Matcher} matcher - Current path matcher
729731
*/
730-
function isItStopNode(stopNodeExpressions, matcher) {
731-
if (!stopNodeExpressions || stopNodeExpressions.length === 0) return false;
732+
function isItStopNode() {
733+
if (this.stopNodeExpressionsSet.size === 0) return false;
732734

733-
for (let i = 0; i < stopNodeExpressions.length; i++) {
734-
if (matcher.matches(stopNodeExpressions[i])) {
735-
return true;
736-
}
737-
}
738-
return false;
735+
return this.matcher.matchesAny(this.stopNodeExpressionsSet);
739736
}
740737

741738
/**

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,10 +3149,10 @@ path-exists@^4.0.0:
31493149
resolved "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz"
31503150
integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==
31513151

3152-
path-expression-matcher@^1.1.3, path-expression-matcher@^1.2.1:
3153-
version "1.2.1"
3154-
resolved "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.2.1.tgz"
3155-
integrity sha512-d7gQQmLvAKXKXE2GeP9apIGbMYKz88zWdsn/BN2HRWVQsDFdUY36WSLTY0Jvd4HWi7Fb30gQ62oAOzdgJA6fZw==
3152+
path-expression-matcher@^1.1.3, path-expression-matcher@^1.3.0:
3153+
version "1.3.0"
3154+
resolved "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.3.0.tgz"
3155+
integrity sha512-tkolHg8cWjEFA8+TqYGk0w6aNEZVcb7pVxW8KXZpU+ebaBr3s1ogbLssjK1cL74TtEuKl/qy6cb90RnwTFt3kw==
31563156

31573157
path-is-absolute@^1.0.0:
31583158
version "1.0.1"

0 commit comments

Comments
 (0)