clarity-pattern-parser 10.1.17 → 10.1.20

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
@@ -2363,9 +2363,8 @@ class AutoComplete {
2363
2363
  errorAtIndex = startIndex;
2364
2364
  }
2365
2365
  else if (!isComplete && this._cursor.hasError && this._cursor.furthestError != null) {
2366
- errorAtIndex = this._cursor.furthestError.endIndex;
2367
- error = this._cursor.furthestError;
2368
- errorAtIndex = options.reduce((errorAtIndex, option) => Math.max(errorAtIndex, option.startIndex), errorAtIndex);
2366
+ errorAtIndex = this.getFurthestPosition(cursor);
2367
+ error = new ParseError(errorAtIndex, errorAtIndex, this._pattern);
2369
2368
  }
2370
2369
  return {
2371
2370
  isComplete: isComplete,
@@ -2376,6 +2375,25 @@ class AutoComplete {
2376
2375
  ast,
2377
2376
  };
2378
2377
  }
2378
+ getFurthestPosition(cursor) {
2379
+ const furthestError = cursor.furthestError;
2380
+ const furthestMatch = cursor.allMatchedNodes[cursor.allMatchedNodes.length - 1];
2381
+ if (furthestError && furthestMatch) {
2382
+ if (furthestError.endIndex > furthestMatch.endIndex) {
2383
+ return furthestMatch.endIndex;
2384
+ }
2385
+ else {
2386
+ return furthestError.endIndex;
2387
+ }
2388
+ }
2389
+ if (furthestError == null && furthestMatch != null) {
2390
+ return furthestMatch.endIndex;
2391
+ }
2392
+ if (furthestMatch == null && furthestError != null) {
2393
+ return furthestError.endIndex;
2394
+ }
2395
+ return 0;
2396
+ }
2379
2397
  suggestFor(text) {
2380
2398
  return this.suggestForWithCursor(new Cursor(text));
2381
2399
  }