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/package.json
CHANGED
|
@@ -11,6 +11,7 @@ export class Reference implements Pattern {
|
|
|
11
11
|
private _type: string;
|
|
12
12
|
private _name: string;
|
|
13
13
|
private _parent: Pattern | null;
|
|
14
|
+
private _cachedPattern: Pattern | null;
|
|
14
15
|
private _pattern: Pattern | null;
|
|
15
16
|
private _children: Pattern[];
|
|
16
17
|
|
|
@@ -44,6 +45,7 @@ export class Reference implements Pattern {
|
|
|
44
45
|
this._name = name;
|
|
45
46
|
this._parent = null;
|
|
46
47
|
this._pattern = null;
|
|
48
|
+
this._cachedPattern = null;
|
|
47
49
|
this._children = [];
|
|
48
50
|
}
|
|
49
51
|
|
|
@@ -72,7 +74,13 @@ export class Reference implements Pattern {
|
|
|
72
74
|
|
|
73
75
|
private _getPatternSafely(): Pattern {
|
|
74
76
|
if (this._pattern === null) {
|
|
75
|
-
|
|
77
|
+
let pattern: Pattern | null = null;
|
|
78
|
+
|
|
79
|
+
if (this._cachedPattern == null) {
|
|
80
|
+
pattern = this._findPattern();
|
|
81
|
+
} else {
|
|
82
|
+
pattern = this._cachedPattern;
|
|
83
|
+
}
|
|
76
84
|
|
|
77
85
|
if (pattern === null) {
|
|
78
86
|
throw new Error(`Couldn't find '${this._name}' pattern within tree.`);
|
|
@@ -159,6 +167,12 @@ export class Reference implements Pattern {
|
|
|
159
167
|
clone(name = this._name): Pattern {
|
|
160
168
|
const clone = new Reference(name);
|
|
161
169
|
clone._id = this._id;
|
|
170
|
+
|
|
171
|
+
// Optimize future clones, by caching the pattern we already found.
|
|
172
|
+
if (this._pattern != null) {
|
|
173
|
+
clone._cachedPattern = this._pattern;
|
|
174
|
+
}
|
|
175
|
+
|
|
162
176
|
return clone;
|
|
163
177
|
}
|
|
164
178
|
|