path-expression-matcher 1.3.0 → 1.5.0

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.
@@ -159,6 +159,26 @@ export default class ExpressionSet {
159
159
  * }
160
160
  */
161
161
  matchesAny(matcher) {
162
+ return this.findMatch(matcher) !== null;
163
+ }
164
+ /**
165
+ * Find and return the first Expression that matches the matcher's current path.
166
+ *
167
+ * Uses the same evaluation order as matchesAny (cheapest → most expensive):
168
+ * 1. Exact depth + tag bucket
169
+ * 2. Depth-only wildcard bucket
170
+ * 3. Deep-wildcard list
171
+ *
172
+ * @param {import('./Matcher.js').default} matcher - Matcher instance (or readOnly view)
173
+ * @returns {import('./Expression.js').default | null} the first matching Expression, or null
174
+ *
175
+ * @example
176
+ * const expr = stopNodes.findMatch(matcher);
177
+ * if (expr) {
178
+ * // access expr.config, expr.pattern, etc.
179
+ * }
180
+ */
181
+ findMatch(matcher) {
162
182
  const depth = matcher.getDepth();
163
183
  const tag = matcher.getCurrentTag();
164
184
 
@@ -167,7 +187,7 @@ export default class ExpressionSet {
167
187
  const exactBucket = this._byDepthAndTag.get(exactKey);
168
188
  if (exactBucket) {
169
189
  for (let i = 0; i < exactBucket.length; i++) {
170
- if (matcher.matches(exactBucket[i])) return true;
190
+ if (matcher.matches(exactBucket[i])) return exactBucket[i];
171
191
  }
172
192
  }
173
193
 
@@ -175,15 +195,15 @@ export default class ExpressionSet {
175
195
  const wildcardBucket = this._wildcardByDepth.get(depth);
176
196
  if (wildcardBucket) {
177
197
  for (let i = 0; i < wildcardBucket.length; i++) {
178
- if (matcher.matches(wildcardBucket[i])) return true;
198
+ if (matcher.matches(wildcardBucket[i])) return wildcardBucket[i];
179
199
  }
180
200
  }
181
201
 
182
202
  // 3. Deep wildcards — cannot be pre-filtered by depth or tag
183
203
  for (let i = 0; i < this._deepWildcards.length; i++) {
184
- if (matcher.matches(this._deepWildcards[i])) return true;
204
+ if (matcher.matches(this._deepWildcards[i])) return this._deepWildcards[i];
185
205
  }
186
206
 
187
- return false;
207
+ return null;
188
208
  }
189
209
  }