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