clarity-pattern-parser 10.1.11 → 10.1.13

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.js CHANGED
@@ -1025,11 +1025,12 @@ class Options {
1025
1025
  return null;
1026
1026
  }
1027
1027
  _tryToParse(cursor) {
1028
+ const shouldReverseOrder = this._shouldReverseOrder();
1028
1029
  let children = this._children;
1029
- if (depthCache$1.getDepth(this._id, this._firstIndex) > 1) {
1030
+ if (shouldReverseOrder) {
1030
1031
  children = this._children.slice().reverse();
1031
1032
  }
1032
- else if (depthCache$1.getDepth(this._id, this._firstIndex) > 2) {
1033
+ if (depthCache$1.getDepth(this._id, this._firstIndex) > 2) {
1033
1034
  cursor.recordErrorAt(this._firstIndex, this._firstIndex, this);
1034
1035
  return null;
1035
1036
  }
@@ -1050,6 +1051,17 @@ class Options {
1050
1051
  nonNullResults.sort((a, b) => b.endIndex - a.endIndex);
1051
1052
  return nonNullResults[0] || null;
1052
1053
  }
1054
+ _shouldReverseOrder() {
1055
+ let count = 0;
1056
+ let pattern = this._parent;
1057
+ while (pattern != null) {
1058
+ if (pattern.id === this.id) {
1059
+ count++;
1060
+ }
1061
+ pattern = pattern.parent;
1062
+ }
1063
+ return count % 2 === 1;
1064
+ }
1053
1065
  getTokens() {
1054
1066
  const tokens = [];
1055
1067
  for (const child of this._children) {