clarity-pattern-parser 11.3.9 → 11.3.10

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
@@ -1255,12 +1255,10 @@ class FiniteRepeat {
1255
1255
  }
1256
1256
  }
1257
1257
  }
1258
- if (this._trimDivider && this._hasDivider) {
1259
- const isDividerLastMatch = this.children.length > 1 && nodes.length > 1 && nodes[nodes.length - 1].name === this.children[1].name;
1260
- if (isDividerLastMatch) {
1261
- const node = nodes.pop();
1262
- cursor.moveTo(node.firstIndex);
1263
- }
1258
+ const endedOnDivider = this._hasDivider && nodes.length % modulo === 0;
1259
+ if (this._trimDivider && endedOnDivider) {
1260
+ const node = nodes.pop();
1261
+ cursor.moveTo(node.firstIndex);
1264
1262
  }
1265
1263
  if (matchCount < this._min) {
1266
1264
  const lastIndex = cursor.index;
@@ -1396,6 +1394,7 @@ class InfiniteRepeat {
1396
1394
  this._firstIndex = 0;
1397
1395
  this._nodes = [];
1398
1396
  this._trimDivider = options.trimDivider == null ? false : options.trimDivider;
1397
+ this._patterns = [];
1399
1398
  }
1400
1399
  _assignChildrenToParent(children) {
1401
1400
  for (const child of children) {
@@ -1411,6 +1410,7 @@ class InfiniteRepeat {
1411
1410
  parse(cursor) {
1412
1411
  this._firstIndex = cursor.index;
1413
1412
  this._nodes = [];
1413
+ this._patterns = [];
1414
1414
  const passed = this._tryToParse(cursor);
1415
1415
  if (passed) {
1416
1416
  cursor.resolveError();
@@ -1462,6 +1462,7 @@ class InfiniteRepeat {
1462
1462
  }
1463
1463
  if (repeatNode != null) {
1464
1464
  this._nodes.push(repeatNode);
1465
+ this._patterns.push(this._pattern);
1465
1466
  if (!cursor.hasNext()) {
1466
1467
  passed = true;
1467
1468
  break;
@@ -1486,6 +1487,7 @@ class InfiniteRepeat {
1486
1487
  }
1487
1488
  else {
1488
1489
  this._nodes.push(dividerNode);
1490
+ this._patterns.push(this._divider);
1489
1491
  if (!cursor.hasNext()) {
1490
1492
  passed = true;
1491
1493
  break;
@@ -1508,11 +1510,11 @@ class InfiniteRepeat {
1508
1510
  return passed;
1509
1511
  }
1510
1512
  _createNode(cursor) {
1511
- var _a;
1512
1513
  const hasDivider = this._divider != null;
1514
+ const lastPattern = this._patterns[this._patterns.length - 1];
1513
1515
  if (hasDivider &&
1514
1516
  this._trimDivider &&
1515
- this._nodes[this._nodes.length - 1].name === ((_a = this._divider) === null || _a === void 0 ? void 0 : _a.name)) {
1517
+ lastPattern === this._divider) {
1516
1518
  const dividerNode = this._nodes.pop();
1517
1519
  cursor.moveTo(dividerNode.firstIndex);
1518
1520
  }