clarity-pattern-parser 11.5.0 → 11.5.2
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 +11 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +11 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/dist/patterns/Expression.d.ts +1 -0
- package/package.json +1 -1
- package/src/patterns/Expression.ts +12 -5
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ export class Expression implements Pattern {
|
|
|
17
17
|
private _name: string;
|
|
18
18
|
private _originalName: string;
|
|
19
19
|
private _parent: Pattern | null;
|
|
20
|
+
private _cachedParent: Pattern | null;
|
|
20
21
|
private _firstIndex: number;
|
|
21
22
|
private _originalPatterns: Pattern[];
|
|
22
23
|
private _patterns: Pattern[];
|
|
@@ -92,6 +93,7 @@ export class Expression implements Pattern {
|
|
|
92
93
|
this._name = name;
|
|
93
94
|
this._originalName = name;
|
|
94
95
|
this._parent = null;
|
|
96
|
+
this._cachedParent = null;
|
|
95
97
|
this._firstIndex = 0;
|
|
96
98
|
this._atomPatterns = [];
|
|
97
99
|
this._prefixPatterns = [];
|
|
@@ -278,7 +280,8 @@ export class Expression implements Pattern {
|
|
|
278
280
|
}
|
|
279
281
|
|
|
280
282
|
build() {
|
|
281
|
-
if (!this._hasOrganized) {
|
|
283
|
+
if (!this._hasOrganized || this._cachedParent !== this.parent) {
|
|
284
|
+
this._cachedParent = this.parent;
|
|
282
285
|
this._hasOrganized = true;
|
|
283
286
|
this._organizePatterns(this._originalPatterns);
|
|
284
287
|
this._cacheAncestors();
|
|
@@ -491,6 +494,7 @@ export class Expression implements Pattern {
|
|
|
491
494
|
}
|
|
492
495
|
|
|
493
496
|
getTokens(): string[] {
|
|
497
|
+
this.build();
|
|
494
498
|
const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
|
|
495
499
|
const prefixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
|
|
496
500
|
|
|
@@ -498,6 +502,7 @@ export class Expression implements Pattern {
|
|
|
498
502
|
}
|
|
499
503
|
|
|
500
504
|
getTokensAfter(childReference: Pattern): string[] {
|
|
505
|
+
this.build();
|
|
501
506
|
if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
|
|
502
507
|
const atomTokens = this._atomPatterns.map(p => p.getTokens()).flat();
|
|
503
508
|
const prefixTokens = this.prefixPatterns.map(p => p.getTokens()).flat();
|
|
@@ -506,7 +511,7 @@ export class Expression implements Pattern {
|
|
|
506
511
|
}
|
|
507
512
|
|
|
508
513
|
if (this._atomPatterns.includes(childReference)) {
|
|
509
|
-
const postfixTokens = this.
|
|
514
|
+
const postfixTokens = this.postfixPatterns.map(p => p.getTokens()).flat();
|
|
510
515
|
|
|
511
516
|
if (postfixTokens.length === 0) {
|
|
512
517
|
return this._binaryPatterns.map(p => p.getTokens()).flat();
|
|
@@ -534,6 +539,7 @@ export class Expression implements Pattern {
|
|
|
534
539
|
}
|
|
535
540
|
|
|
536
541
|
getPatterns(): Pattern[] {
|
|
542
|
+
this.build();
|
|
537
543
|
const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
|
|
538
544
|
const prefixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
|
|
539
545
|
|
|
@@ -541,6 +547,7 @@ export class Expression implements Pattern {
|
|
|
541
547
|
}
|
|
542
548
|
|
|
543
549
|
getPatternsAfter(childReference: Pattern): Pattern[] {
|
|
550
|
+
this.build();
|
|
544
551
|
if (this._prefixPatterns.includes(childReference) || this._binaryPatterns.includes(childReference)) {
|
|
545
552
|
const atomPatterns = this._atomPatterns.map(p => p.getPatterns()).flat();
|
|
546
553
|
const prefixPatterns = this.prefixPatterns.map(p => p.getPatterns()).flat();
|
|
@@ -549,7 +556,7 @@ export class Expression implements Pattern {
|
|
|
549
556
|
}
|
|
550
557
|
|
|
551
558
|
if (this._atomPatterns.includes(childReference)) {
|
|
552
|
-
const postfixPatterns = this.
|
|
559
|
+
const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
|
|
553
560
|
|
|
554
561
|
if (postfixPatterns.length === 0) {
|
|
555
562
|
return this._binaryPatterns.map(p => p.getPatterns()).flat();
|
|
@@ -559,10 +566,10 @@ export class Expression implements Pattern {
|
|
|
559
566
|
}
|
|
560
567
|
|
|
561
568
|
if (this._postfixPatterns.includes(childReference)) {
|
|
562
|
-
const
|
|
569
|
+
const postfixPatterns = this.postfixPatterns.map(p => p.getPatterns()).flat();
|
|
563
570
|
const binaryPatterns = this._binaryPatterns.map(p => p.getPatterns()).flat();
|
|
564
571
|
|
|
565
|
-
return [...
|
|
572
|
+
return [...postfixPatterns, ...binaryPatterns];
|
|
566
573
|
}
|
|
567
574
|
|
|
568
575
|
return [];
|