clarity-pattern-parser 10.1.7 → 10.1.9

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.esm.js CHANGED
@@ -842,16 +842,25 @@ class Reference {
842
842
  continue;
843
843
  }
844
844
  const foundPattern = pattern.getPatternWithinContext(this.name);
845
- if (foundPattern != null && foundPattern.type !== "reference") {
845
+ if (foundPattern != null && this._isValidPattern(foundPattern)) {
846
846
  return foundPattern;
847
847
  }
848
848
  pattern = pattern.parent;
849
849
  }
850
850
  const root = this._getRoot();
851
851
  return findPattern(root, (pattern) => {
852
- return pattern.name === this._name && pattern.type !== "reference";
852
+ return pattern.name === this._name && this._isValidPattern(pattern);
853
853
  });
854
854
  }
855
+ _isValidPattern(pattern) {
856
+ if (pattern.type === "reference") {
857
+ return false;
858
+ }
859
+ if (pattern.type === "context" && pattern.children[0].type === "reference") {
860
+ return false;
861
+ }
862
+ return true;
863
+ }
855
864
  _getRoot() {
856
865
  let node = this;
857
866
  while (true) {
@@ -1012,12 +1021,16 @@ class Options {
1012
1021
  return null;
1013
1022
  }
1014
1023
  _tryToParse(cursor) {
1015
- if (depthCache$1.getDepth(this._id, this._firstIndex) > 2) {
1024
+ let children = this._children;
1025
+ if (depthCache$1.getDepth(this._id, this._firstIndex) > 1) {
1026
+ children = this._children.reverse();
1027
+ }
1028
+ else if (depthCache$1.getDepth(this._id, this._firstIndex) > 2) {
1016
1029
  cursor.recordErrorAt(this._firstIndex, this._firstIndex, this);
1017
1030
  return null;
1018
1031
  }
1019
1032
  const results = [];
1020
- for (const pattern of this._children) {
1033
+ for (const pattern of children) {
1021
1034
  cursor.moveTo(this._firstIndex);
1022
1035
  let result = null;
1023
1036
  result = pattern.parse(cursor);