clarity-pattern-parser 10.0.7 → 10.0.8
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.
- package/dist/index.browser.js +12 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +12 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/patterns/Reference.d.ts +1 -0
- package/package.json +1 -1
- package/src/patterns/Reference.ts +15 -1
package/dist/index.js
CHANGED
|
@@ -782,6 +782,7 @@ class Reference {
|
|
|
782
782
|
this._name = name;
|
|
783
783
|
this._parent = null;
|
|
784
784
|
this._pattern = null;
|
|
785
|
+
this._cachedPattern = null;
|
|
785
786
|
this._children = [];
|
|
786
787
|
}
|
|
787
788
|
test(text) {
|
|
@@ -803,7 +804,13 @@ class Reference {
|
|
|
803
804
|
}
|
|
804
805
|
_getPatternSafely() {
|
|
805
806
|
if (this._pattern === null) {
|
|
806
|
-
|
|
807
|
+
let pattern = null;
|
|
808
|
+
if (this._cachedPattern == null) {
|
|
809
|
+
pattern = this._findPattern();
|
|
810
|
+
}
|
|
811
|
+
else {
|
|
812
|
+
pattern = this._cachedPattern;
|
|
813
|
+
}
|
|
807
814
|
if (pattern === null) {
|
|
808
815
|
throw new Error(`Couldn't find '${this._name}' pattern within tree.`);
|
|
809
816
|
}
|
|
@@ -869,6 +876,10 @@ class Reference {
|
|
|
869
876
|
clone(name = this._name) {
|
|
870
877
|
const clone = new Reference(name);
|
|
871
878
|
clone._id = this._id;
|
|
879
|
+
// Optimize future clones, by caching the pattern we already found.
|
|
880
|
+
if (this._pattern != null) {
|
|
881
|
+
clone._cachedPattern = this._pattern;
|
|
882
|
+
}
|
|
872
883
|
return clone;
|
|
873
884
|
}
|
|
874
885
|
isEqual(pattern) {
|