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.esm.js
CHANGED
|
@@ -778,6 +778,7 @@ class Reference {
|
|
|
778
778
|
this._name = name;
|
|
779
779
|
this._parent = null;
|
|
780
780
|
this._pattern = null;
|
|
781
|
+
this._cachedPattern = null;
|
|
781
782
|
this._children = [];
|
|
782
783
|
}
|
|
783
784
|
test(text) {
|
|
@@ -799,7 +800,13 @@ class Reference {
|
|
|
799
800
|
}
|
|
800
801
|
_getPatternSafely() {
|
|
801
802
|
if (this._pattern === null) {
|
|
802
|
-
|
|
803
|
+
let pattern = null;
|
|
804
|
+
if (this._cachedPattern == null) {
|
|
805
|
+
pattern = this._findPattern();
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
pattern = this._cachedPattern;
|
|
809
|
+
}
|
|
803
810
|
if (pattern === null) {
|
|
804
811
|
throw new Error(`Couldn't find '${this._name}' pattern within tree.`);
|
|
805
812
|
}
|
|
@@ -865,6 +872,10 @@ class Reference {
|
|
|
865
872
|
clone(name = this._name) {
|
|
866
873
|
const clone = new Reference(name);
|
|
867
874
|
clone._id = this._id;
|
|
875
|
+
// Optimize future clones, by caching the pattern we already found.
|
|
876
|
+
if (this._pattern != null) {
|
|
877
|
+
clone._cachedPattern = this._pattern;
|
|
878
|
+
}
|
|
868
879
|
return clone;
|
|
869
880
|
}
|
|
870
881
|
isEqual(pattern) {
|