clarity-pattern-parser 10.1.2 → 10.1.4

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
@@ -841,9 +841,7 @@ class Reference {
841
841
  pattern = pattern.parent;
842
842
  continue;
843
843
  }
844
- const foundPattern = findPattern(pattern, (pattern) => {
845
- return pattern.name === this._name && pattern.type !== "reference" && pattern.type !== "context";
846
- });
844
+ const foundPattern = pattern.getPatternWithinContext(this.name);
847
845
  if (foundPattern != null) {
848
846
  return foundPattern;
849
847
  }
@@ -2536,17 +2534,23 @@ class Context {
2536
2534
  get children() {
2537
2535
  return this._children;
2538
2536
  }
2537
+ getPatternWithinContext(name) {
2538
+ return this._patterns[name] || null;
2539
+ }
2540
+ getPatternsWithinContext() {
2541
+ return Object.assign({}, this._patterns);
2542
+ }
2539
2543
  constructor(name, pattern, context = []) {
2540
2544
  this._id = `context-${contextId++}`;
2541
2545
  this._type = "context";
2542
2546
  this._name = name;
2543
2547
  this._parent = null;
2544
- const clonedContext = context.map(p => p.clone());
2548
+ this._patterns = {};
2545
2549
  const clonedPattern = pattern.clone();
2546
- clonedContext.forEach(p => p.parent = this);
2550
+ context.forEach(p => this._patterns[p.name] = p);
2547
2551
  clonedPattern.parent = this;
2548
2552
  this._pattern = clonedPattern;
2549
- this._children = [...clonedContext, clonedPattern];
2553
+ this._children = [clonedPattern];
2550
2554
  }
2551
2555
  parse(cursor) {
2552
2556
  return this._pattern.parse(cursor);
@@ -2558,7 +2562,7 @@ class Context {
2558
2562
  return this._pattern.test(text, record);
2559
2563
  }
2560
2564
  clone(name = this._name) {
2561
- const clone = new Context(name, this._pattern, this._children.slice(0, -1));
2565
+ const clone = new Context(name, this._pattern, Object.values(this._patterns));
2562
2566
  return clone;
2563
2567
  }
2564
2568
  getTokens() {