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.esm.js CHANGED
@@ -1251,12 +1251,10 @@ class FiniteRepeat {
1251
1251
  }
1252
1252
  }
1253
1253
  }
1254
- if (this._trimDivider && this._hasDivider) {
1255
- const isDividerLastMatch = this.children.length > 1 && nodes.length > 1 && nodes[nodes.length - 1].name === this.children[1].name;
1256
- if (isDividerLastMatch) {
1257
- const node = nodes.pop();
1258
- cursor.moveTo(node.firstIndex);
1259
- }
1254
+ const endedOnDivider = this._hasDivider && nodes.length % modulo === 0;
1255
+ if (this._trimDivider && endedOnDivider) {
1256
+ const node = nodes.pop();
1257
+ cursor.moveTo(node.firstIndex);
1260
1258
  }
1261
1259
  if (matchCount < this._min) {
1262
1260
  const lastIndex = cursor.index;
@@ -1392,6 +1390,7 @@ class InfiniteRepeat {
1392
1390
  this._firstIndex = 0;
1393
1391
  this._nodes = [];
1394
1392
  this._trimDivider = options.trimDivider == null ? false : options.trimDivider;
1393
+ this._patterns = [];
1395
1394
  }
1396
1395
  _assignChildrenToParent(children) {
1397
1396
  for (const child of children) {
@@ -1407,6 +1406,7 @@ class InfiniteRepeat {
1407
1406
  parse(cursor) {
1408
1407
  this._firstIndex = cursor.index;
1409
1408
  this._nodes = [];
1409
+ this._patterns = [];
1410
1410
  const passed = this._tryToParse(cursor);
1411
1411
  if (passed) {
1412
1412
  cursor.resolveError();
@@ -1458,6 +1458,7 @@ class InfiniteRepeat {
1458
1458
  }
1459
1459
  if (repeatNode != null) {
1460
1460
  this._nodes.push(repeatNode);
1461
+ this._patterns.push(this._pattern);
1461
1462
  if (!cursor.hasNext()) {
1462
1463
  passed = true;
1463
1464
  break;
@@ -1482,6 +1483,7 @@ class InfiniteRepeat {
1482
1483
  }
1483
1484
  else {
1484
1485
  this._nodes.push(dividerNode);
1486
+ this._patterns.push(this._divider);
1485
1487
  if (!cursor.hasNext()) {
1486
1488
  passed = true;
1487
1489
  break;
@@ -1504,11 +1506,11 @@ class InfiniteRepeat {
1504
1506
  return passed;
1505
1507
  }
1506
1508
  _createNode(cursor) {
1507
- var _a;
1508
1509
  const hasDivider = this._divider != null;
1510
+ const lastPattern = this._patterns[this._patterns.length - 1];
1509
1511
  if (hasDivider &&
1510
1512
  this._trimDivider &&
1511
- this._nodes[this._nodes.length - 1].name === ((_a = this._divider) === null || _a === void 0 ? void 0 : _a.name)) {
1513
+ lastPattern === this._divider) {
1512
1514
  const dividerNode = this._nodes.pop();
1513
1515
  cursor.moveTo(dividerNode.firstIndex);
1514
1516
  }