clarity-pattern-parser 10.1.1 → 10.1.3

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.
@@ -847,9 +847,7 @@
847
847
  pattern = pattern.parent;
848
848
  continue;
849
849
  }
850
- const foundPattern = findPattern(pattern, (pattern) => {
851
- return pattern.name === this._name && pattern.type !== "reference" && pattern.type !== "context";
852
- });
850
+ const foundPattern = pattern.getPatternWithinContext(this.name);
853
851
  if (foundPattern != null) {
854
852
  return foundPattern;
855
853
  }
@@ -2542,17 +2540,23 @@
2542
2540
  get children() {
2543
2541
  return this._children;
2544
2542
  }
2543
+ getPatternWithinContext(name) {
2544
+ return this._patterns[name] || null;
2545
+ }
2546
+ getPatternsWithinContext() {
2547
+ return Object.assign({}, this._patterns);
2548
+ }
2545
2549
  constructor(name, pattern, context = []) {
2546
2550
  this._id = `context-${contextId++}`;
2547
2551
  this._type = "context";
2548
2552
  this._name = name;
2549
2553
  this._parent = null;
2550
- const clonedContext = context.map(p => p.clone());
2554
+ this._patterns = {};
2551
2555
  const clonedPattern = pattern.clone();
2552
- clonedContext.forEach(p => p.parent = this);
2556
+ context.forEach(p => this._patterns[p.name] = p);
2553
2557
  clonedPattern.parent = this;
2554
2558
  this._pattern = clonedPattern;
2555
- this._children = [...clonedContext, clonedPattern];
2559
+ this._children = [clonedPattern];
2556
2560
  }
2557
2561
  parse(cursor) {
2558
2562
  return this._pattern.parse(cursor);
@@ -2564,7 +2568,7 @@
2564
2568
  return this._pattern.test(text, record);
2565
2569
  }
2566
2570
  clone(name = this._name) {
2567
- const clone = new Context(name, this._pattern, this._children.slice(-1));
2571
+ const clone = new Context(name, this._pattern, this._children.slice(0, -1));
2568
2572
  return clone;
2569
2573
  }
2570
2574
  getTokens() {