clarity-pattern-parser 10.1.7 → 10.1.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.
@@ -22,6 +22,7 @@ export declare class Reference implements Pattern {
22
22
  parse(cursor: Cursor): Node | null;
23
23
  private _getPatternSafely;
24
24
  private _findPattern;
25
+ private _isValidPattern;
25
26
  private _getRoot;
26
27
  getTokens(): string[];
27
28
  getTokensAfter(_lastMatched: Pattern): string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clarity-pattern-parser",
3
- "version": "10.1.7",
3
+ "version": "10.1.8",
4
4
  "description": "Parsing Library for Typescript and Javascript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",
@@ -108,7 +108,7 @@ export class Reference implements Pattern {
108
108
 
109
109
  const foundPattern = (pattern as Context).getPatternWithinContext(this.name);
110
110
 
111
- if (foundPattern != null && foundPattern.type !== "reference") {
111
+ if (foundPattern != null && this._isValidPattern(foundPattern)) {
112
112
  return foundPattern;
113
113
  }
114
114
 
@@ -117,10 +117,22 @@ export class Reference implements Pattern {
117
117
 
118
118
  const root = this._getRoot();
119
119
  return findPattern(root, (pattern: Pattern) => {
120
- return pattern.name === this._name && pattern.type !== "reference";
120
+ return pattern.name === this._name && this._isValidPattern(pattern);
121
121
  });
122
122
  }
123
123
 
124
+ private _isValidPattern(pattern: Pattern) {
125
+ if (pattern.type === "reference") {
126
+ return false;
127
+ }
128
+
129
+ if (pattern.type === "context" && pattern.children[0].type === "reference") {
130
+ return false;
131
+ }
132
+
133
+ return true;
134
+ }
135
+
124
136
  private _getRoot(): Pattern {
125
137
  let node: Pattern = this;
126
138