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