clarity-pattern-parser 10.1.2 → 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.
package/dist/index.js CHANGED
@@ -845,9 +845,7 @@ class Reference {
845
845
  pattern = pattern.parent;
846
846
  continue;
847
847
  }
848
- const foundPattern = findPattern(pattern, (pattern) => {
849
- return pattern.name === this._name && pattern.type !== "reference" && pattern.type !== "context";
850
- });
848
+ const foundPattern = pattern.getPatternWithinContext(this.name);
851
849
  if (foundPattern != null) {
852
850
  return foundPattern;
853
851
  }
@@ -2540,17 +2538,23 @@ class Context {
2540
2538
  get children() {
2541
2539
  return this._children;
2542
2540
  }
2541
+ getPatternWithinContext(name) {
2542
+ return this._patterns[name] || null;
2543
+ }
2544
+ getPatternsWithinContext() {
2545
+ return Object.assign({}, this._patterns);
2546
+ }
2543
2547
  constructor(name, pattern, context = []) {
2544
2548
  this._id = `context-${contextId++}`;
2545
2549
  this._type = "context";
2546
2550
  this._name = name;
2547
2551
  this._parent = null;
2548
- const clonedContext = context.map(p => p.clone());
2552
+ this._patterns = {};
2549
2553
  const clonedPattern = pattern.clone();
2550
- clonedContext.forEach(p => p.parent = this);
2554
+ context.forEach(p => this._patterns[p.name] = p);
2551
2555
  clonedPattern.parent = this;
2552
2556
  this._pattern = clonedPattern;
2553
- this._children = [...clonedContext, clonedPattern];
2557
+ this._children = [clonedPattern];
2554
2558
  }
2555
2559
  parse(cursor) {
2556
2560
  return this._pattern.parse(cursor);