clarity-pattern-parser 10.0.7 → 10.1.0
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 +29 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +29 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +29 -1
- package/dist/index.js.map +1 -1
- package/dist/patterns/Cursor.d.ts +1 -0
- package/dist/patterns/CursorHistory.d.ts +7 -0
- package/dist/patterns/Reference.d.ts +1 -0
- package/package.json +1 -1
- package/src/patterns/Cursor.test.ts +59 -5
- package/src/patterns/Cursor.ts +4 -0
- package/src/patterns/CursorHistory.ts +21 -0
- package/src/patterns/Reference.ts +15 -1
package/dist/index.js
CHANGED
|
@@ -283,6 +283,7 @@ class CursorHistory {
|
|
|
283
283
|
this._patterns = [];
|
|
284
284
|
this._nodes = [];
|
|
285
285
|
this._errors = [];
|
|
286
|
+
this._records = [];
|
|
286
287
|
}
|
|
287
288
|
get isRecording() {
|
|
288
289
|
return this._isRecording;
|
|
@@ -305,6 +306,9 @@ class CursorHistory {
|
|
|
305
306
|
get error() {
|
|
306
307
|
return this._currentError;
|
|
307
308
|
}
|
|
309
|
+
get records() {
|
|
310
|
+
return this._records;
|
|
311
|
+
}
|
|
308
312
|
get nodes() {
|
|
309
313
|
return this._nodes;
|
|
310
314
|
}
|
|
@@ -315,6 +319,11 @@ class CursorHistory {
|
|
|
315
319
|
if (this._isRecording) {
|
|
316
320
|
this._patterns.push(pattern);
|
|
317
321
|
this._nodes.push(node);
|
|
322
|
+
this._records.push({
|
|
323
|
+
pattern,
|
|
324
|
+
ast: node,
|
|
325
|
+
error: null
|
|
326
|
+
});
|
|
318
327
|
}
|
|
319
328
|
this._rootMatch.pattern = pattern;
|
|
320
329
|
this._rootMatch.node = node;
|
|
@@ -354,6 +363,11 @@ class CursorHistory {
|
|
|
354
363
|
}
|
|
355
364
|
if (this._isRecording) {
|
|
356
365
|
this._errors.push(error);
|
|
366
|
+
this.records.push({
|
|
367
|
+
pattern,
|
|
368
|
+
ast: null,
|
|
369
|
+
error
|
|
370
|
+
});
|
|
357
371
|
}
|
|
358
372
|
}
|
|
359
373
|
startRecording() {
|
|
@@ -404,6 +418,9 @@ class Cursor {
|
|
|
404
418
|
get errors() {
|
|
405
419
|
return this._history.errors;
|
|
406
420
|
}
|
|
421
|
+
get records() {
|
|
422
|
+
return this._history.records;
|
|
423
|
+
}
|
|
407
424
|
get index() {
|
|
408
425
|
return this._index;
|
|
409
426
|
}
|
|
@@ -782,6 +799,7 @@ class Reference {
|
|
|
782
799
|
this._name = name;
|
|
783
800
|
this._parent = null;
|
|
784
801
|
this._pattern = null;
|
|
802
|
+
this._cachedPattern = null;
|
|
785
803
|
this._children = [];
|
|
786
804
|
}
|
|
787
805
|
test(text) {
|
|
@@ -803,7 +821,13 @@ class Reference {
|
|
|
803
821
|
}
|
|
804
822
|
_getPatternSafely() {
|
|
805
823
|
if (this._pattern === null) {
|
|
806
|
-
|
|
824
|
+
let pattern = null;
|
|
825
|
+
if (this._cachedPattern == null) {
|
|
826
|
+
pattern = this._findPattern();
|
|
827
|
+
}
|
|
828
|
+
else {
|
|
829
|
+
pattern = this._cachedPattern;
|
|
830
|
+
}
|
|
807
831
|
if (pattern === null) {
|
|
808
832
|
throw new Error(`Couldn't find '${this._name}' pattern within tree.`);
|
|
809
833
|
}
|
|
@@ -869,6 +893,10 @@ class Reference {
|
|
|
869
893
|
clone(name = this._name) {
|
|
870
894
|
const clone = new Reference(name);
|
|
871
895
|
clone._id = this._id;
|
|
896
|
+
// Optimize future clones, by caching the pattern we already found.
|
|
897
|
+
if (this._pattern != null) {
|
|
898
|
+
clone._cachedPattern = this._pattern;
|
|
899
|
+
}
|
|
872
900
|
return clone;
|
|
873
901
|
}
|
|
874
902
|
isEqual(pattern) {
|