clarity-pattern-parser 11.0.14 → 11.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-pattern-parser",
3
- "version": "11.0.14",
3
+ "version": "11.0.15",
4
4
  "description": "Parsing Library for Typescript and Javascript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -72,28 +72,29 @@ export class Reference implements Pattern {
72
72
 
73
73
  parse(cursor: Cursor): Node | null {
74
74
  this._firstIndex = cursor.index;
75
- this._cacheAncestors();
76
-
75
+
76
+ const pattern = this.getReferencePatternSafely();
77
+
78
+ this._cacheAncestors(pattern.id);
77
79
  if (this._isBeyondRecursiveAllowance()) {
78
80
  cursor.recordErrorAt(this._firstIndex, this._firstIndex, this);
79
81
  return null;
80
82
  }
81
83
 
82
- return this.getReferencePatternSafely().parse(cursor);
84
+ return pattern.parse(cursor);
83
85
  }
84
86
 
85
- private _cacheAncestors() {
87
+ private _cacheAncestors(id: string) {
86
88
  if (!this._cachedAncestors) {
87
89
  let pattern: Pattern | null = this.parent;
88
90
 
89
91
  while (pattern != null) {
90
- if (pattern.type === this.type && pattern.id === this._id) {
92
+ if (pattern.id === id) {
91
93
  this._recursiveAncestors.push(pattern as Reference);
92
94
  }
93
95
  pattern = pattern.parent;
94
96
  }
95
97
  }
96
-
97
98
  }
98
99
 
99
100
  private _isBeyondRecursiveAllowance() {
@@ -0,0 +1,48 @@
1
+ export class Query {
2
+ private _context: Node[];
3
+ private _prevQuery: Query | null;
4
+
5
+ constructor(context: Node[], selector?: string, prevQuery: Query | null = null) {
6
+ this._context = context;
7
+ this._prevQuery = prevQuery;
8
+
9
+ if (selector != null) {
10
+ this.find(selector);
11
+ }
12
+ }
13
+
14
+ slice(start: number, end?: number) {
15
+ return new Query(this._context.slice(start, end));
16
+ }
17
+
18
+ // Modifiers
19
+ append() { }
20
+
21
+ prepend() { }
22
+
23
+ after() { }
24
+
25
+ before() { }
26
+
27
+
28
+ // Refiners
29
+ filter(selector: string) { }
30
+
31
+ find(selector: string) { }
32
+
33
+ not(selector: string) { }
34
+
35
+ parent() { }
36
+
37
+ parents(selector: string) { }
38
+
39
+
40
+ // Pop query stack
41
+ end() {
42
+ if (this._prevQuery) {
43
+ return this._prevQuery;
44
+ }
45
+ return this;
46
+ }
47
+
48
+ }
@@ -0,0 +1,8 @@
1
+ import { patterns } from "../grammar/patterns";
2
+
3
+ const {selector} = patterns`
4
+
5
+
6
+
7
+
8
+ `;