@eslint-community/regexpp 4.10.1 → 4.11.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.
package/index.mjs CHANGED
@@ -2,7 +2,7 @@ var ast = /*#__PURE__*/Object.freeze({
2
2
  __proto__: null
3
3
  });
4
4
 
5
- const latestEcmaVersion = 2024;
5
+ const latestEcmaVersion = 2025;
6
6
 
7
7
  let largeIdStartRanges = undefined;
8
8
  let largeIdContinueRanges = undefined;
@@ -260,6 +260,103 @@ function combineSurrogatePair(lead, trail) {
260
260
  return (lead - 0xd800) * 0x400 + (trail - 0xdc00) + 0x10000;
261
261
  }
262
262
 
263
+ class GroupSpecifiersAsES2018 {
264
+ constructor() {
265
+ this.groupName = new Set();
266
+ }
267
+ clear() {
268
+ this.groupName.clear();
269
+ }
270
+ isEmpty() {
271
+ return !this.groupName.size;
272
+ }
273
+ hasInPattern(name) {
274
+ return this.groupName.has(name);
275
+ }
276
+ hasInScope(name) {
277
+ return this.hasInPattern(name);
278
+ }
279
+ addToScope(name) {
280
+ this.groupName.add(name);
281
+ }
282
+ enterDisjunction() {
283
+ }
284
+ enterAlternative() {
285
+ }
286
+ leaveDisjunction() {
287
+ }
288
+ }
289
+ class BranchID {
290
+ constructor(parent, base) {
291
+ this.parent = parent;
292
+ this.base = base !== null && base !== void 0 ? base : this;
293
+ }
294
+ separatedFrom(other) {
295
+ var _a, _b;
296
+ if (this.base === other.base && this !== other) {
297
+ return true;
298
+ }
299
+ if (other.parent && this.separatedFrom(other.parent)) {
300
+ return true;
301
+ }
302
+ return (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.separatedFrom(other)) !== null && _b !== void 0 ? _b : false;
303
+ }
304
+ child() {
305
+ return new BranchID(this, null);
306
+ }
307
+ sibling() {
308
+ return new BranchID(this.parent, this.base);
309
+ }
310
+ }
311
+ class GroupSpecifiersAsES2025 {
312
+ constructor() {
313
+ this.branchID = new BranchID(null, null);
314
+ this.groupNames = new Map();
315
+ }
316
+ clear() {
317
+ this.branchID = new BranchID(null, null);
318
+ this.groupNames.clear();
319
+ }
320
+ isEmpty() {
321
+ return !this.groupNames.size;
322
+ }
323
+ enterDisjunction() {
324
+ this.branchID = this.branchID.child();
325
+ }
326
+ enterAlternative(index) {
327
+ if (index === 0) {
328
+ return;
329
+ }
330
+ this.branchID = this.branchID.sibling();
331
+ }
332
+ leaveDisjunction() {
333
+ this.branchID = this.branchID.parent;
334
+ }
335
+ hasInPattern(name) {
336
+ return this.groupNames.has(name);
337
+ }
338
+ hasInScope(name) {
339
+ const branches = this.groupNames.get(name);
340
+ if (!branches) {
341
+ return false;
342
+ }
343
+ for (const branch of branches) {
344
+ if (!branch.separatedFrom(this.branchID)) {
345
+ return true;
346
+ }
347
+ }
348
+ return false;
349
+ }
350
+ addToScope(name) {
351
+ const branches = this.groupNames.get(name);
352
+ if (branches) {
353
+ branches.push(this.branchID);
354
+ return;
355
+ }
356
+ this.groupNames.set(name, [this.branchID]);
357
+ }
358
+ }
359
+
263
360
  const legacyImpl = {
264
361
  at(s, end, i) {
265
362
  return i < end ? s.charCodeAt(i) : -1;
@@ -492,10 +589,13 @@ class RegExpValidator {
492
589
  this._lastStrValue = "";
493
590
  this._lastAssertionIsQuantifiable = false;
494
591
  this._numCapturingParens = 0;
495
- this._groupNames = new Set();
496
592
  this._backreferenceNames = new Set();
497
593
  this._srcCtx = null;
498
594
  this._options = options !== null && options !== void 0 ? options : {};
595
+ this._groupSpecifiers =
596
+ this.ecmaVersion >= 2025
597
+ ? new GroupSpecifiersAsES2025()
598
+ : new GroupSpecifiersAsES2018();
499
599
  }
500
600
  validateLiteral(source, start = 0, end = source.length) {
501
601
  this._srcCtx = { source, start, end, kind: "literal" };
@@ -538,7 +638,7 @@ class RegExpValidator {
538
638
  this.consumePattern();
539
639
  if (!this._nFlag &&
540
640
  this.ecmaVersion >= 2018 &&
541
- this._groupNames.size > 0) {
641
+ !this._groupSpecifiers.isEmpty()) {
542
642
  this._nFlag = true;
543
643
  this.rewind(start);
544
644
  this.consumePattern();
@@ -875,7 +975,7 @@ class RegExpValidator {
875
975
  consumePattern() {
876
976
  const start = this.index;
877
977
  this._numCapturingParens = this.countCapturingParens();
878
- this._groupNames.clear();
978
+ this._groupSpecifiers.clear();
879
979
  this._backreferenceNames.clear();
880
980
  this.onPatternEnter(start);
881
981
  this.consumeDisjunction();
@@ -894,7 +994,7 @@ class RegExpValidator {
894
994
  this.raise(`Unexpected character '${c}'`);
895
995
  }
896
996
  for (const name of this._backreferenceNames) {
897
- if (!this._groupNames.has(name)) {
997
+ if (!this._groupSpecifiers.hasInPattern(name)) {
898
998
  this.raise("Invalid named capture referenced");
899
999
  }
900
1000
  }
@@ -935,6 +1035,7 @@ class RegExpValidator {
935
1035
  consumeDisjunction() {
936
1036
  const start = this.index;
937
1037
  let i = 0;
1038
+ this._groupSpecifiers.enterDisjunction();
938
1039
  this.onDisjunctionEnter(start);
939
1040
  do {
940
1041
  this.consumeAlternative(i++);
@@ -946,9 +1047,11 @@ class RegExpValidator {
946
1047
  this.raise("Lone quantifier brackets");
947
1048
  }
948
1049
  this.onDisjunctionLeave(start, this.index);
1050
+ this._groupSpecifiers.leaveDisjunction();
949
1051
  }
950
1052
  consumeAlternative(i) {
951
1053
  const start = this.index;
1054
+ this._groupSpecifiers.enterAlternative(i);
952
1055
  this.onAlternativeEnter(start, i);
953
1056
  while (this.currentCodePoint !== -1 && this.consumeTerm()) {
954
1057
  }
@@ -1182,8 +1285,8 @@ class RegExpValidator {
1182
1285
  consumeGroupSpecifier() {
1183
1286
  if (this.eat(QUESTION_MARK)) {
1184
1287
  if (this.eatGroupName()) {
1185
- if (!this._groupNames.has(this._lastStrValue)) {
1186
- this._groupNames.add(this._lastStrValue);
1288
+ if (!this._groupSpecifiers.hasInScope(this._lastStrValue)) {
1289
+ this._groupSpecifiers.addToScope(this._lastStrValue);
1187
1290
  return true;
1188
1291
  }
1189
1292
  this.raise("Duplicate capture group name");
@@ -2006,11 +2109,21 @@ class RegExpParserState {
2006
2109
  this._node.raw = this.source.slice(start, end);
2007
2110
  for (const reference of this._backreferences) {
2008
2111
  const ref = reference.ref;
2009
- const group = typeof ref === "number"
2010
- ? this._capturingGroups[ref - 1]
2011
- : this._capturingGroups.find((g) => g.name === ref);
2012
- reference.resolved = group;
2013
- group.references.push(reference);
2112
+ const groups = typeof ref === "number"
2113
+ ? [this._capturingGroups[ref - 1]]
2114
+ : this._capturingGroups.filter((g) => g.name === ref);
2115
+ if (groups.length === 1) {
2116
+ const group = groups[0];
2117
+ reference.ambiguous = false;
2118
+ reference.resolved = group;
2119
+ }
2120
+ else {
2121
+ reference.ambiguous = true;
2122
+ reference.resolved = groups;
2123
+ }
2124
+ for (const group of groups) {
2125
+ group.references.push(reference);
2126
+ }
2014
2127
  }
2015
2128
  }
2016
2129
  onAlternativeEnter(start) {
@@ -2256,6 +2369,7 @@ class RegExpParserState {
2256
2369
  end,
2257
2370
  raw: this.source.slice(start, end),
2258
2371
  ref,
2372
+ ambiguous: false,
2259
2373
  resolved: DUMMY_CAPTURING_GROUP,
2260
2374
  };
2261
2375
  parent.elements.push(node);