-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathout.js
More file actions
3124 lines (3109 loc) · 114 KB
/
Copy pathout.js
File metadata and controls
3124 lines (3109 loc) · 114 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const exports = (() => {
var __defProp = Object.defineProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
// node_modules/@shikijs/engine-javascript/dist/index.mjs
var dist_exports = {};
__export(dist_exports, {
JavaScriptScanner: () => JavaScriptScanner,
createJavaScriptRawEngine: () => createJavaScriptRawEngine,
createJavaScriptRegexEngine: () => createJavaScriptRegexEngine,
defaultJavaScriptRegexConstructor: () => defaultJavaScriptRegexConstructor
});
// node_modules/oniguruma-parser/dist/utils.js
var e = String.fromCodePoint;
var o = String.raw;
var i = /* @__PURE__ */ new Set(["alnum", "alpha", "ascii", "blank", "cntrl", "digit", "graph", "lower", "print", "punct", "space", "upper", "word", "xdigit"]);
function s(t, r4, n) {
return t.has(r4) || t.set(r4, n), t.get(r4);
}
function c(t, r4) {
if (!t) throw new Error(r4 ?? "Value expected");
return t;
}
// node_modules/oniguruma-parser/dist/tokenizer/tokenize.js
var o2 = { Alternator: "Alternator", Assertion: "Assertion", Backreference: "Backreference", Character: "Character", CharacterClassClose: "CharacterClassClose", CharacterClassHyphen: "CharacterClassHyphen", CharacterClassIntersector: "CharacterClassIntersector", CharacterClassOpen: "CharacterClassOpen", CharacterSet: "CharacterSet", Directive: "Directive", GroupClose: "GroupClose", GroupOpen: "GroupOpen", Subroutine: "Subroutine", Quantifier: "Quantifier", EscapedNumber: "EscapedNumber" };
var h = { any: "any", digit: "digit", dot: "dot", grapheme: "grapheme", hex: "hex", newline: "newline", posix: "posix", property: "property", space: "space", word: "word" };
var x = { flags: "flags", keep: "keep" };
var g = { absent_repeater: "absent_repeater", atomic: "atomic", capturing: "capturing", group: "group", lookahead: "lookahead", lookbehind: "lookbehind" };
var C = { greedy: "greedy", lazy: "lazy", possessive: "possessive" };
var y = /* @__PURE__ */ new Map([["a", 7], ["b", 8], ["e", 27], ["f", 12], ["n", 10], ["r", 13], ["t", 9], ["v", 11]]);
var E = o`\[\^?`;
var $ = `c.? | C(?:-.?)?|${o`[pP]\{(?:\^?[-\x20_]*[A-Za-z][-\x20\w]*\})?`}|${o`x[89A-Fa-f]\p{AHex}(?:\\x[89A-Fa-f]\p{AHex})*`}|${o`u(?:\p{AHex}{4})? | x\{[^\}]*\}? | x\p{AHex}{0,2}`}|${o`o\{[^\}]*\}?`}|${o`\d{1,3}`}`;
var I = /[?*+][?+]?|\{(?:\d+(?:,\d*)?|,\d+)\}\??/;
var k = new RegExp(o`
\\ (?:
${$}
| [gk]<[^>]*>?
| [gk]'[^']*'?
| .
)
| \( (?:
\? (?:
[:=!>({]
| <[=!]
| <[^>]*>
| '[^']*'
| ~\|?
| #(?:[^)\\]|\\.?)*
| [^:)]*[:)]
)?
| \*
)?
| ${I.source}
| ${E}
| .
`.replace(/\s+/g, ""), "gsu");
var A = new RegExp(o`
\\ (?:
${$}
| .
)
| \[:(?:\^?\p{Alpha}+|\^):\]
| ${E}
| &&
| .
`.replace(/\s+/g, ""), "gsu");
function P(e2, t = {}) {
const n = { flags: "", ...t, rules: { captureGroup: false, singleline: false, ...t.rules } };
if (typeof e2 != "string") throw new Error("String expected as pattern");
const i2 = z(n.flags), a = [i2.extended], p = { captureGroup: n.rules.captureGroup, getCurrentModX: () => a.at(-1), numOpenGroups: 0, popModX() {
a.pop();
}, pushModX(c2) {
a.push(c2);
}, replaceCurrentModX(c2) {
a[a.length - 1] = c2;
}, singleline: n.rules.singleline };
let r4 = [], u;
for (k.lastIndex = 0; u = k.exec(e2); ) {
const c2 = F(p, e2, u[0], k.lastIndex);
c2.tokens ? r4.push(...c2.tokens) : c2.token && r4.push(c2.token), c2.lastIndex !== void 0 && (k.lastIndex = c2.lastIndex);
}
const l = [];
let f2 = 0;
r4.forEach((c2) => {
c2.type === o2.GroupOpen && (c2.kind === g.capturing ? c2.number = ++f2 : c2.raw === "(" && l.push(c2));
}), f2 || l.forEach((c2, S2) => {
c2.kind = g.capturing, c2.number = S2 + 1;
});
const G2 = f2 || l.length;
return r4 = r4.map((c2) => c2.type === o2.EscapedNumber ? j(c2, G2) : c2).flat(), { tokens: r4, flags: i2 };
}
function F(e2, t, n, i2) {
const [a, p] = n;
if (a === "[") {
const r4 = M(t, n, i2);
return { tokens: r4.tokens, lastIndex: r4.lastIndex };
}
if (a === "\\") {
if ("AbBGyYzZ".includes(p)) return { token: s2(o2.Assertion, n, { kind: n }) };
if (/^\\g[<']/.test(n)) {
if (!/^\\g(?:<[^>]+>|'[^']+')$/.test(n)) throw new Error(`Invalid group name "${n}"`);
return { token: s2(o2.Subroutine, n) };
}
if (/^\\k[<']/.test(n)) {
if (!/^\\k(?:<[^>]+>|'[^']+')$/.test(n)) throw new Error(`Invalid group name "${n}"`);
return { token: s2(o2.Backreference, n) };
}
if (p === "K") return { token: s2(o2.Directive, n, { kind: x.keep }) };
if (p === "N" || p === "R") return { token: s2(o2.CharacterSet, n, { kind: h.newline, negate: p === "N" }) };
if (p === "O") return { token: s2(o2.CharacterSet, n, { kind: h.any }) };
if (p === "X") return { token: s2(o2.CharacterSet, n, { kind: h.grapheme }) };
const r4 = O(n, { inCharClass: false });
return Array.isArray(r4) ? { tokens: r4 } : { token: r4 };
}
if (a === "(") {
if (n === "(*") throw new Error(`Unsupported named callout "${n}"`);
if (n === "(?{") throw new Error(`Unsupported callout "${n}"`);
if (n.startsWith("(?#")) {
if (t[i2] !== ")") throw new Error('Unclosed comment group "(?#"');
return { lastIndex: i2 + 1 };
}
if (/^\(\?[-imx]+[:)]$/.test(n)) return { token: W(n, e2) };
if (e2.pushModX(e2.getCurrentModX()), e2.numOpenGroups++, n === "(" && !e2.captureGroup || n === "(?:") return { token: s2(o2.GroupOpen, n, { kind: g.group }) };
if (n === "(?>") return { token: s2(o2.GroupOpen, n, { kind: g.atomic }) };
if (n === "(?=" || n === "(?!" || n === "(?<=" || n === "(?<!") return { token: s2(o2.GroupOpen, n, { kind: n[2] === "<" ? g.lookbehind : g.lookahead, negate: n.endsWith("!") }) };
if (n === "(" && e2.captureGroup || n.startsWith("(?<") && n.endsWith(">") || n.startsWith("(?'") && n.endsWith("'")) {
const r4 = s2(o2.GroupOpen, n, { kind: g.capturing });
return n !== "(" && (r4.name = n.slice(3, -1)), { token: r4 };
}
if (n.startsWith("(?~")) {
if (n === "(?~|") throw new Error(`Unsupported absent function kind "${n}"`);
return { token: s2(o2.GroupOpen, n, { kind: g.absent_repeater }) };
}
throw n === "(?(" ? new Error(`Unsupported conditional "${n}"`) : new Error(`Invalid or unsupported group option "${n}"`);
}
if (n === ")") {
if (e2.popModX(), e2.numOpenGroups--, e2.numOpenGroups < 0) throw new Error('Unmatched ")"');
return { token: s2(o2.GroupClose, n) };
}
if (n === "#" && e2.getCurrentModX()) {
const r4 = t.indexOf(`
`, i2);
return { lastIndex: r4 === -1 ? t.length : r4 };
}
if (/^\s$/.test(n) && e2.getCurrentModX()) {
const r4 = /\s+/y;
return r4.lastIndex = i2, { lastIndex: r4.exec(t) ? r4.lastIndex : i2 };
}
if (n === ".") return { token: s2(o2.CharacterSet, n, { kind: h.dot }) };
if (n === "^" || n === "$") {
const r4 = e2.singleline ? { "^": o`\A`, $: o`\Z` }[n] : n;
return { token: s2(o2.Assertion, n, { kind: r4 }) };
}
return n === "|" ? { token: s2(o2.Alternator, n) } : I.test(n) ? { token: X(n) } : (v(n), { token: s2(o2.Character, n, { value: n.codePointAt(0) }) });
}
function M(e2, t, n) {
const i2 = [s2(o2.CharacterClassOpen, t, { negate: t[1] === "^" })];
let a = 1, p;
for (A.lastIndex = n; p = A.exec(e2); ) {
const r4 = p[0];
if (r4[0] === "[" && r4[1] !== ":") a++, i2.push(s2(o2.CharacterClassOpen, r4, { negate: r4[1] === "^" }));
else if (r4 === "]") {
if (i2.at(-1).type === o2.CharacterClassOpen) i2.push(s2(o2.Character, r4, { value: 93 }));
else if (a--, i2.push(s2(o2.CharacterClassClose, r4)), !a) break;
} else {
const u = w(r4);
Array.isArray(u) ? i2.push(...u) : i2.push(u);
}
}
return { tokens: i2, lastIndex: A.lastIndex || e2.length };
}
function w(e2) {
if (e2[0] === "\\") return O(e2, { inCharClass: true });
if (e2[0] === "[") {
const t = /\[:(?<negate>\^?)(?<name>[a-z]+):\]/.exec(e2);
if (!t || !i.has(t.groups.name)) throw new Error(`Invalid POSIX class "${e2}"`);
return s2(o2.CharacterSet, e2, { kind: h.posix, value: t.groups.name, negate: !!t.groups.negate });
}
return e2 === "-" ? s2(o2.CharacterClassHyphen, e2) : e2 === "&&" ? s2(o2.CharacterClassIntersector, e2) : (v(e2), s2(o2.Character, e2, { value: e2.codePointAt(0) }));
}
function O(e2, { inCharClass: t }) {
const n = e2[1];
if (n === "c" || n === "C") return U(e2);
if ("dDhHsSwW".includes(n)) return H(e2);
if (e2.startsWith(o`\o{`)) throw new Error(`Incomplete, invalid, or unsupported octal code point "${e2}"`);
if (/^\\[pP]\{/.test(e2)) {
if (e2.length === 3) throw new Error(`Incomplete or invalid Unicode property "${e2}"`);
return D(e2);
}
if (/^\\x[89A-Fa-f]\p{AHex}/u.test(e2)) try {
const i2 = e2.split(/\\x/).slice(1).map((u) => parseInt(u, 16)), a = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }).decode(new Uint8Array(i2)), p = new TextEncoder();
return [...a].map((u) => {
const l = [...p.encode(u)].map((f2) => `\\x${f2.toString(16)}`).join("");
return s2(o2.Character, l, { value: u.codePointAt(0) });
});
} catch {
throw new Error(`Multibyte code "${e2}" incomplete or invalid in Oniguruma`);
}
if (n === "u" || n === "x") return s2(o2.Character, e2, { value: N(e2) });
if (y.has(n)) return s2(o2.Character, e2, { value: y.get(n) });
if (/\d/.test(n)) return s2(o2.EscapedNumber, e2, { inCharClass: t });
if (e2 === "\\") throw new Error(o`Incomplete escape "\"`);
if (n === "M") throw new Error(`Unsupported meta "${e2}"`);
if ([...e2].length === 2) return s2(o2.Character, e2, { value: e2.codePointAt(1) });
throw new Error(`Unexpected escape "${e2}"`);
}
function s2(e2, t, n) {
return { type: e2, raw: t, ...n };
}
function U(e2) {
const t = e2[1] === "c" ? e2[2] : e2[3];
if (!t || !/[A-Za-z]/.test(t)) throw new Error(`Unsupported control character "${e2}"`);
return s2(o2.Character, e2, { value: t.toUpperCase().codePointAt(0) - 64 });
}
function W(e2, t) {
let { on: n, off: i2 } = /^\(\?(?<on>[imx]*)(?:-(?<off>[-imx]*))?/.exec(e2).groups;
i2 ??= "";
const a = (t.getCurrentModX() || n.includes("x")) && !i2.includes("x"), p = b(n), r4 = b(i2), u = {};
if (p && (u.enable = p), r4 && (u.disable = r4), e2.endsWith(")")) return t.replaceCurrentModX(a), s2(o2.Directive, e2, { kind: x.flags, flags: u });
if (e2.endsWith(":")) {
t.pushModX(a), t.numOpenGroups++;
const l = s2(o2.GroupOpen, e2, { kind: g.group });
return (p || r4) && (l.flags = u), l;
}
throw new Error(`Unexpected flag modifier "${e2}"`);
}
function X(e2) {
const t = {};
if (e2[0] === "{") {
const { min: n, max: i2 } = /^\{(?<min>\d*)(?:,(?<max>\d*))?/.exec(e2).groups, a = 1e5;
if (+n > a || +i2 > a) throw new Error("Quantifier value unsupported in Oniguruma");
t.min = +n, t.max = i2 === void 0 ? +n : i2 === "" ? 1 / 0 : +i2, t.kind = e2.endsWith("?") ? C.lazy : C.greedy;
} else t.min = e2[0] === "+" ? 1 : 0, t.max = e2[0] === "?" ? 1 : 1 / 0, t.kind = e2[1] === "+" ? C.possessive : e2[1] === "?" ? C.lazy : C.greedy;
return s2(o2.Quantifier, e2, t);
}
function H(e2) {
const t = e2[1].toLowerCase();
return s2(o2.CharacterSet, e2, { kind: { d: h.digit, h: h.hex, s: h.space, w: h.word }[t], negate: e2[1] !== t });
}
function D(e2) {
const { p: t, neg: n, value: i2 } = /^\\(?<p>[pP])\{(?<neg>\^?)(?<value>[^}]+)/.exec(e2).groups, a = t === "P" && !n || t === "p" && !!n;
return s2(o2.CharacterSet, e2, { kind: h.property, value: i2, negate: a });
}
function b(e2) {
const t = {};
return e2.includes("i") && (t.ignoreCase = true), e2.includes("m") && (t.dotAll = true), e2.includes("x") && (t.extended = true), Object.keys(t).length ? t : null;
}
function z(e2) {
if (!/^[imxDPSW]*$/.test(e2)) throw new Error(`Flags "${e2}" includes unsupported value`);
const t = { ignoreCase: false, dotAll: false, extended: false, digitIsAscii: false, posixIsAscii: false, spaceIsAscii: false, wordIsAscii: false };
for (const n of e2) t[{ i: "ignoreCase", m: "dotAll", x: "extended", D: "digitIsAscii", P: "posixIsAscii", S: "spaceIsAscii", W: "wordIsAscii" }[n]] = true;
return t;
}
function N(e2) {
if (/^(?:\\u(?!\p{AHex}{4})|\\x(?!\p{AHex}{1,2}|\{\p{AHex}{1,8}\}))/u.test(e2)) throw new Error(`Incomplete or invalid escape "${e2}"`);
const t = e2[2] === "{" ? /^\\x\{\s*(?<hex>\p{AHex}+)/u.exec(e2).groups.hex : e2.slice(2);
return parseInt(t, 16);
}
function j(e2, t) {
const { raw: n, inCharClass: i2 } = e2, a = n.slice(1);
if (!i2 && (a !== "0" && a.length === 1 || a[0] !== "0" && +a <= t)) return [s2(o2.Backreference, n)];
const p = [], r4 = a.match(/^[0-7]+|\d/g);
for (let u = 0; u < r4.length; u++) {
const l = r4[u];
let f2;
if (u === 0 && l !== "8" && l !== "9") {
if (f2 = parseInt(l, 8), f2 > 127) throw new Error(o`Octal encoded byte above 177 unsupported "${n}"`);
} else f2 = l.codePointAt(0);
p.push(s2(o2.Character, (u === 0 ? "\\" : "") + l, { value: f2 }));
}
return p;
}
function v(e2) {
if ([...e2].length !== 1) throw new Error(`Expected "${e2}" to be a single code point`);
}
// node_modules/oniguruma-parser/dist/parser/parse.js
var s3 = { AbsentFunction: "AbsentFunction", Alternative: "Alternative", Assertion: "Assertion", Backreference: "Backreference", CapturingGroup: "CapturingGroup", Character: "Character", CharacterClass: "CharacterClass", CharacterClassRange: "CharacterClassRange", CharacterSet: "CharacterSet", Directive: "Directive", Flags: "Flags", Group: "Group", LookaroundAssertion: "LookaroundAssertion", Pattern: "Pattern", Quantifier: "Quantifier", Regex: "Regex", Subroutine: "Subroutine", Recursion: "Recursion" };
var F2 = { repeater: "repeater" };
var f = { grapheme_boundary: "grapheme_boundary", line_end: "line_end", line_start: "line_start", search_start: "search_start", string_end: "string_end", string_end_newline: "string_end_newline", string_start: "string_start", word_boundary: "word_boundary" };
var L = { union: "union", intersection: "intersection" };
var A2 = h;
var E2 = x;
var _ = C;
var b2 = { lookahead: "lookahead", lookbehind: "lookbehind" };
function ne(e2, r4 = {}) {
const n = { flags: "", normalizeUnknownPropertyNames: false, skipBackrefValidation: false, skipLookbehindValidation: false, skipPropertyNameValidation: false, unicodePropertyMap: null, ...r4, rules: { captureGroup: false, singleline: false, ...r4.rules } }, a = P(e2, { flags: n.flags, rules: { captureGroup: n.rules.captureGroup, singleline: n.rules.singleline } }), t = { capturingGroups: [], current: 0, hasNumberedRef: false, namedGroupsByName: /* @__PURE__ */ new Map(), normalizeUnknownPropertyNames: n.normalizeUnknownPropertyNames, parent: null, skipBackrefValidation: n.skipBackrefValidation, skipLookbehindValidation: n.skipLookbehindValidation, skipPropertyNameValidation: n.skipPropertyNameValidation, subroutines: [], token: null, tokens: a.tokens, unicodePropertyMap: n.unicodePropertyMap, walk: o3 };
function o3(p, m) {
const d = a.tokens[t.current];
switch (t.parent = p, t.token = d, t.current++, d.type) {
case o2.Alternator:
return k2();
case o2.Assertion:
return le(d);
case o2.Backreference:
return te(t);
case o2.Character:
return I2(d.value, { useLastValid: !!m.isCheckingRangeEnd });
case o2.CharacterClassHyphen:
return ae(t, m);
case o2.CharacterClassOpen:
return oe(t, m);
case o2.CharacterSet:
return se(t);
case o2.Directive:
return K(c(E2[d.kind], `Unexpected directive kind "${d.kind}"`), { flags: d.flags });
case o2.GroupOpen:
return ie(t, m);
case o2.Quantifier:
return ue(t);
case o2.Subroutine:
return ce(t);
default:
throw new Error(`Unexpected token type "${d.type}"`);
}
}
const i2 = q(D2(), O2(a.flags));
let c2 = i2.pattern.alternatives[0];
for (; t.current < a.tokens.length; ) {
const p = o3(c2, {});
p.type === s3.Alternative ? (i2.pattern.alternatives.push(p), c2 = p) : c2.elements.push(p);
}
const { capturingGroups: u, hasNumberedRef: h2, namedGroupsByName: y2, subroutines: N2 } = t;
if (h2 && y2.size && !n.rules.captureGroup) throw new Error("Numbered backref/subroutine not allowed when using named capture");
for (const { ref: p } of N2) if (typeof p == "number") {
if (p > u.length) throw new Error("Subroutine uses a group number that's not defined");
} else if (y2.has(p)) {
if (y2.get(p).length > 1) throw new Error(o`Subroutine uses a duplicate group name "\g<${p}>"`);
} else throw new Error(o`Subroutine uses a group name that's not defined "\g<${p}>"`);
return i2;
}
function te(e2) {
const { raw: r4 } = e2.token, n = /^\\k[<']/.test(r4), a = n ? r4.slice(3, -1) : r4.slice(1), t = (o3, i2 = false) => {
const c2 = e2.capturingGroups.length;
let u = false;
if (o3 > c2) if (e2.skipBackrefValidation) u = true;
else throw new Error(`Not enough capturing groups defined to the left "${r4}"`);
return e2.hasNumberedRef = true, P2(i2 ? c2 + 1 - o3 : o3, { orphan: u });
};
if (n) {
const o3 = /^(?<sign>-?)0*(?<num>[1-9]\d*)$/.exec(a);
if (o3) return t(+o3.groups.num, !!o3.groups.sign);
if (/[-+]/.test(a)) throw new Error(`Invalid backref name "${r4}"`);
if (!e2.namedGroupsByName.has(a)) throw new Error(`Group name not defined to the left "${r4}"`);
return P2(a);
}
return t(+a);
}
function ae(e2, r4) {
const { parent: n, tokens: a, walk: t } = e2, o3 = n.elements.at(-1), i2 = a[e2.current];
if (!r4.isCheckingRangeEnd && o3 && o3.type !== s3.CharacterClass && o3.type !== s3.CharacterClassRange && i2 && i2.type !== o2.CharacterClassOpen && i2.type !== o2.CharacterClassClose && i2.type !== o2.CharacterClassIntersector) {
const c2 = t(n, { ...r4, isCheckingRangeEnd: true });
if (o3.type === s3.Character && c2.type === s3.Character) return n.elements.pop(), z2(o3, c2);
throw new Error("Invalid character class range");
}
return I2(45);
}
function oe(e2, r4) {
const { token: n, tokens: a, walk: t } = e2, o3 = a[e2.current], i2 = [G()];
let c2 = J(o3);
for (; c2.type !== o2.CharacterClassClose; ) {
if (c2.type === o2.CharacterClassIntersector) i2.push(G()), e2.current++;
else {
const h2 = i2.at(-1);
h2.elements.push(t(h2, r4));
}
c2 = J(a[e2.current], o3);
}
const u = G({ negate: n.negate });
return i2.length === 1 ? u.elements = i2[0].elements : (u.kind = L.intersection, u.elements = i2.map((h2) => h2.elements.length === 1 ? h2.elements[0] : h2)), e2.current++, u;
}
function se({ token: e2, normalizeUnknownPropertyNames: r4, skipPropertyNameValidation: n, unicodePropertyMap: a }) {
let { kind: t, negate: o3, value: i2 } = e2;
if (t === h.property) {
const c2 = $2(i2);
if (i.has(c2) && !a?.has(c2)) t = h.posix, i2 = c2;
else return Y(i2, { negate: o3, normalizeUnknownPropertyNames: r4, skipPropertyNameValidation: n, unicodePropertyMap: a });
}
return t === h.posix ? M2(i2, { negate: o3 }) : T(t, { negate: o3 });
}
function ie(e2, r4) {
const { token: n, tokens: a, capturingGroups: t, namedGroupsByName: o3, skipLookbehindValidation: i2, walk: c2 } = e2;
let u = pe(n);
const h2 = u.type === s3.AbsentFunction, y2 = u.kind === b2.lookbehind, N2 = y2 && u.negate;
if (u.type === s3.CapturingGroup && (t.push(u), u.name && s(o3, u.name, []).push(u)), h2 && r4.isInAbsentFunction) throw new Error("Nested absent function not supported by Oniguruma");
let p = W2(a[e2.current]);
for (; p.type !== o2.GroupClose; ) {
if (p.type === o2.Alternator) u.alternatives.push(k2()), e2.current++;
else {
const m = u.alternatives.at(-1), d = c2(m, { ...r4, isInAbsentFunction: r4.isInAbsentFunction || h2, isInLookbehind: r4.isInLookbehind || y2, isInNegLookbehind: r4.isInNegLookbehind || N2 });
if (m.elements.push(d), (y2 || r4.isInLookbehind) && !i2) {
const R = "Lookbehind includes a pattern not allowed by Oniguruma";
if (N2 || r4.isInNegLookbehind) {
if (d.kind === b2.lookahead || d.type === s3.CapturingGroup) throw new Error(R);
} else if (d.kind === b2.lookahead || d.kind === b2.lookbehind && d.negate) throw new Error(R);
}
}
p = W2(a[e2.current]);
}
return e2.current++, u;
}
function ue({ token: e2, parent: r4 }) {
const { min: n, max: a, kind: t } = e2, o3 = r4.elements.at(-1);
if (!o3 || o3.type === s3.Assertion || o3.type === s3.Directive || o3.type === s3.LookaroundAssertion) throw new Error("Quantifier requires a repeatable token");
const i2 = Z(o3, n, a, c(_[t], `Unexpected quantifier kind "${t}"`));
return r4.elements.pop(), i2;
}
function ce(e2) {
const { token: r4, capturingGroups: n, subroutines: a } = e2;
let t = r4.raw.slice(3, -1);
const o3 = /^(?<sign>[-+]?)0*(?<num>[1-9]\d*)$/.exec(t);
if (o3) {
const c2 = +o3.groups.num, u = n.length;
if (e2.hasNumberedRef = true, t = { "": c2, "+": u + c2, "-": u + 1 - c2 }[o3.groups.sign], t < 1) throw new Error("Invalid subroutine number");
} else t === "0" && (t = 0);
const i2 = H2(t);
return a.push(i2), i2;
}
function B(e2) {
if (e2 !== F2.repeater) throw new Error(`Unexpected absent function kind "${e2}"`);
return { type: s3.AbsentFunction, kind: e2, alternatives: [k2()] };
}
function k2() {
return { type: s3.Alternative, elements: [] };
}
function V(e2, r4) {
const n = { type: s3.Assertion, kind: e2 };
return (e2 === f.word_boundary || e2 === f.grapheme_boundary) && (n.negate = !!r4?.negate), n;
}
function le({ kind: e2 }) {
return V(c({ "^": f.line_start, $: f.line_end, "\\A": f.string_start, "\\b": f.word_boundary, "\\B": f.word_boundary, "\\G": f.search_start, "\\y": f.grapheme_boundary, "\\Y": f.grapheme_boundary, "\\z": f.string_end, "\\Z": f.string_end_newline }[e2], `Unexpected assertion kind "${e2}"`), { negate: e2 === o`\B` || e2 === o`\Y` });
}
function P2(e2, r4) {
const n = !!r4?.orphan;
return { type: s3.Backreference, ref: e2, ...n && { orphan: n } };
}
function pe({ flags: e2, kind: r4, name: n, negate: a, number: t }) {
switch (r4) {
case g.absent_repeater:
return B(F2.repeater);
case g.atomic:
return S({ atomic: true });
case g.capturing:
return x2(t, n);
case g.group:
return S({ flags: e2 });
case g.lookahead:
case g.lookbehind:
return Q({ behind: r4 === g.lookbehind, negate: a });
default:
throw new Error(`Unexpected group kind "${r4}"`);
}
}
function x2(e2, r4) {
const n = r4 !== void 0;
if (n && !de(r4)) throw new Error(`Group name "${r4}" invalid in Oniguruma`);
return { type: s3.CapturingGroup, number: e2, ...n && { name: r4 }, alternatives: [k2()] };
}
function I2(e2, r4) {
const n = { useLastValid: false, ...r4 };
if (e2 > 1114111) {
const a = e2.toString(16);
if (n.useLastValid) e2 = 1114111;
else throw e2 > 1310719 ? new Error(`Invalid code point out of range "\\x{${a}}"`) : new Error(`Invalid code point out of range in JS "\\x{${a}}"`);
}
return { type: s3.Character, value: e2 };
}
function G(e2) {
const r4 = { kind: L.union, negate: false, ...e2 };
return { type: s3.CharacterClass, kind: r4.kind, negate: r4.negate, elements: [] };
}
function z2(e2, r4) {
if (r4.value < e2.value) throw new Error("Character class range out of order");
return { type: s3.CharacterClassRange, min: e2, max: r4 };
}
function T(e2, r4) {
const n = !!r4?.negate, a = { type: s3.CharacterSet, kind: c(A2[e2], `Unexpected character set kind "${e2}"`) };
return (e2 === h.digit || e2 === h.hex || e2 === h.newline || e2 === h.space || e2 === h.word) && (a.negate = n), (e2 === h.grapheme || e2 === h.newline && !n) && (a.variableLength = true), a;
}
function K(e2, r4) {
const n = { type: s3.Directive, kind: e2 };
return e2 === E2.flags && (n.flags = r4.flags), n;
}
function O2(e2) {
return { type: s3.Flags, ...e2 };
}
function S(e2) {
const r4 = e2?.atomic, n = e2?.flags;
return { type: s3.Group, ...r4 && { atomic: r4 }, ...n && { flags: n }, alternatives: [k2()] };
}
function Q(e2) {
const r4 = { behind: false, negate: false, ...e2 };
return { type: s3.LookaroundAssertion, kind: r4.behind ? b2.lookbehind : b2.lookahead, negate: r4.negate, alternatives: [k2()] };
}
function D2() {
return { type: s3.Pattern, alternatives: [k2()] };
}
function M2(e2, r4) {
const n = !!r4?.negate;
if (!i.has(e2)) throw new Error(`Invalid POSIX class "${e2}"`);
return { type: s3.CharacterSet, kind: A2.posix, value: e2, negate: n };
}
function Z(e2, r4, n, a = _.greedy) {
const t = { type: s3.Quantifier, min: r4, max: n, kind: a, element: e2 };
return n < r4 ? { ...t, min: n, max: r4, kind: _.possessive } : t;
}
function q(e2, r4) {
return { type: s3.Regex, pattern: e2, flags: r4 };
}
function H2(e2) {
return { type: s3.Subroutine, ref: e2 };
}
function Y(e2, r4) {
const n = { negate: false, normalizeUnknownPropertyNames: false, skipPropertyNameValidation: false, unicodePropertyMap: null, ...r4 };
let a = n.unicodePropertyMap?.get($2(e2));
if (!a) {
if (n.normalizeUnknownPropertyNames) a = fe(e2);
else if (n.unicodePropertyMap && !n.skipPropertyNameValidation) throw new Error(o`Invalid Unicode property "\p{${e2}}"`);
}
return { type: s3.CharacterSet, kind: A2.property, value: a ?? e2, negate: n.negate };
}
function de(e2) {
return /^[\p{Alpha}\p{Pc}][^)]*$/u.test(e2);
}
function fe(e2) {
return e2.trim().replace(/[- _]+/g, "_").replace(/[A-Z][a-z]+(?=[A-Z])/g, "$&_").replace(/[A-Za-z]+/g, (r4) => r4[0].toUpperCase() + r4.slice(1).toLowerCase());
}
function $2(e2) {
return e2.replace(/[- _]+/g, "").toLowerCase();
}
function J(e2, r4) {
return c(e2, `${r4?.value === 93 ? "Empty" : "Unclosed"} character class`);
}
function W2(e2) {
return c(e2, "Unclosed group");
}
// node_modules/emoji-regex-xs/index.mjs
var r = String.raw;
var seq = r`(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})`;
var sTags = r`\u{E0061}-\u{E007A}`;
var emoji_regex_xs_default = () => new RegExp(r`[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[${sTags}]{2}[\u{E0030}-\u{E0039}${sTags}]{1,3}\u{E007F}|${seq}(?:\u200D${seq})*`, "gu");
// node_modules/oniguruma-parser/dist/traverser/traverse.js
function T2(A3, C2, p = null) {
function x3(e2, i2) {
for (let r4 = 0; r4 < e2.length; r4++) {
const a = l(e2[r4], i2, r4, e2);
r4 = Math.max(-1, r4 + a);
}
}
function l(e2, i2 = null, r4 = null, a = null) {
const f2 = "Container expected";
let c2 = 0, n = false;
const u = { node: e2, parent: i2, key: r4, container: a, root: A3, remove() {
c(a, f2).splice(Math.max(0, r4 + c2), 1), c2--, n = true;
}, removeAllNextSiblings() {
return c(a, f2).splice(r4 + 1);
}, removeAllPrevSiblings() {
const s4 = r4 + c2;
return c2 -= s4, c(a, f2).splice(0, Math.max(0, s4));
}, replaceWith(s4, g2 = {}) {
const b3 = !!g2.traverse;
a ? a[Math.max(0, r4 + c2)] = s4 : i2[r4] = s4, b3 && l(s4, i2, r4, a), n = true;
}, replaceWithMultiple(s4, g2 = {}) {
const b3 = !!g2.traverse;
if (c(a, f2).splice(Math.max(0, r4 + c2), 1, ...s4), c2 += s4.length - 1, b3) {
let S2 = 0;
for (let o3 = 0; o3 < s4.length; o3++) S2 += l(s4[o3], i2, r4 + o3 + S2, a);
}
n = true;
}, skip() {
n = true;
} }, h2 = C2["*"], m = C2[e2.type], k3 = typeof h2 == "function" ? h2 : h2?.enter, M3 = typeof m == "function" ? m : m?.enter;
if (k3?.(u, p), M3?.(u, p), !n) switch (e2.type) {
case s3.Regex:
l(e2.pattern, e2, "pattern"), l(e2.flags, e2, "flags");
break;
case s3.Alternative:
case s3.CharacterClass:
x3(e2.elements, e2);
break;
case s3.Assertion:
case s3.Backreference:
case s3.Character:
case s3.CharacterSet:
case s3.Directive:
case s3.Flags:
case s3.Recursion:
case s3.Subroutine:
break;
case s3.AbsentFunction:
case s3.CapturingGroup:
case s3.Group:
case s3.Pattern:
x3(e2.alternatives, e2);
break;
case s3.CharacterClassRange:
l(e2.min, e2, "min"), l(e2.max, e2, "max");
break;
case s3.LookaroundAssertion:
x3(e2.alternatives, e2);
break;
case s3.Quantifier:
l(e2.element, e2, "element");
break;
default:
throw new Error(`Unexpected node type "${e2.type}"`);
}
return h2?.exit?.(u, p), m?.exit?.(u, p), c2;
}
l(A3);
}
// node_modules/regex/src/utils-internals.js
var noncapturingDelim = String.raw`\(\?(?:[:=!>A-Za-z\-]|<[=!]|\(DEFINE\))`;
function incrementIfAtLeast(arr, threshold) {
for (let i2 = 0; i2 < arr.length; i2++) {
if (arr[i2] >= threshold) {
arr[i2]++;
}
}
}
function spliceStr(str, pos, oldValue, newValue) {
return str.slice(0, pos) + newValue + str.slice(pos + oldValue.length);
}
// node_modules/regex-utilities/src/index.js
var Context = Object.freeze({
DEFAULT: "DEFAULT",
CHAR_CLASS: "CHAR_CLASS"
});
function replaceUnescaped(expression, needle, replacement, context) {
const re = new RegExp(String.raw`${needle}|(?<$skip>\[\^?|\\?.)`, "gsu");
const negated = [false];
let numCharClassesOpen = 0;
let result = "";
for (const match of expression.matchAll(re)) {
const { 0: m, groups: { $skip } } = match;
if (!$skip && (!context || context === Context.DEFAULT === !numCharClassesOpen)) {
if (replacement instanceof Function) {
result += replacement(match, {
context: numCharClassesOpen ? Context.CHAR_CLASS : Context.DEFAULT,
negated: negated[negated.length - 1]
});
} else {
result += replacement;
}
continue;
}
if (m[0] === "[") {
numCharClassesOpen++;
negated.push(m[1] === "^");
} else if (m === "]" && numCharClassesOpen) {
numCharClassesOpen--;
negated.pop();
}
result += m;
}
return result;
}
function forEachUnescaped(expression, needle, callback, context) {
replaceUnescaped(expression, needle, callback, context);
}
function execUnescaped(expression, needle, pos = 0, context) {
if (!new RegExp(needle, "su").test(expression)) {
return null;
}
const re = new RegExp(`${needle}|(?<$skip>\\\\?.)`, "gsu");
re.lastIndex = pos;
let numCharClassesOpen = 0;
let match;
while (match = re.exec(expression)) {
const { 0: m, groups: { $skip } } = match;
if (!$skip && (!context || context === Context.DEFAULT === !numCharClassesOpen)) {
return match;
}
if (m === "[") {
numCharClassesOpen++;
} else if (m === "]" && numCharClassesOpen) {
numCharClassesOpen--;
}
if (re.lastIndex == match.index) {
re.lastIndex++;
}
}
return null;
}
function hasUnescaped(expression, needle, context) {
return !!execUnescaped(expression, needle, 0, context);
}
function getGroupContents(expression, contentsStartPos) {
const token2 = /\\?./gsu;
token2.lastIndex = contentsStartPos;
let contentsEndPos = expression.length;
let numCharClassesOpen = 0;
let numGroupsOpen = 1;
let match;
while (match = token2.exec(expression)) {
const [m] = match;
if (m === "[") {
numCharClassesOpen++;
} else if (!numCharClassesOpen) {
if (m === "(") {
numGroupsOpen++;
} else if (m === ")") {
numGroupsOpen--;
if (!numGroupsOpen) {
contentsEndPos = match.index;
break;
}
}
} else if (m === "]") {
numCharClassesOpen--;
}
}
return expression.slice(contentsStartPos, contentsEndPos);
}
// node_modules/regex/src/atomic.js
var atomicPluginToken = new RegExp(String.raw`(?<noncapturingStart>${noncapturingDelim})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`, "gsu");
function atomic(expression, data) {
const hiddenCaptures = data?.hiddenCaptures ?? [];
let captureTransfers = data?.captureTransfers ?? /* @__PURE__ */ new Map();
if (!/\(\?>/.test(expression)) {
return {
pattern: expression,
captureTransfers,
hiddenCaptures
};
}
const aGDelim = "(?>";
const emulatedAGDelim = "(?:(?=(";
const captureNumMap = [0];
const addedHiddenCaptures = [];
let numCapturesBeforeAG = 0;
let numAGs = 0;
let aGPos = NaN;
let hasProcessedAG;
do {
hasProcessedAG = false;
let numCharClassesOpen = 0;
let numGroupsOpenInAG = 0;
let inAG = false;
let match;
atomicPluginToken.lastIndex = Number.isNaN(aGPos) ? 0 : aGPos + emulatedAGDelim.length;
while (match = atomicPluginToken.exec(expression)) {
const { 0: m, index, groups: { capturingStart, noncapturingStart } } = match;
if (m === "[") {
numCharClassesOpen++;
} else if (!numCharClassesOpen) {
if (m === aGDelim && !inAG) {
aGPos = index;
inAG = true;
} else if (inAG && noncapturingStart) {
numGroupsOpenInAG++;
} else if (capturingStart) {
if (inAG) {
numGroupsOpenInAG++;
} else {
numCapturesBeforeAG++;
captureNumMap.push(numCapturesBeforeAG + numAGs);
}
} else if (m === ")" && inAG) {
if (!numGroupsOpenInAG) {
numAGs++;
const addedCaptureNum = numCapturesBeforeAG + numAGs;
expression = `${expression.slice(0, aGPos)}${emulatedAGDelim}${expression.slice(aGPos + aGDelim.length, index)}))<$$${addedCaptureNum}>)${expression.slice(index + 1)}`;
hasProcessedAG = true;
addedHiddenCaptures.push(addedCaptureNum);
incrementIfAtLeast(hiddenCaptures, addedCaptureNum);
if (captureTransfers.size) {
const newCaptureTransfers = /* @__PURE__ */ new Map();
captureTransfers.forEach((from, to) => {
newCaptureTransfers.set(
to >= addedCaptureNum ? to + 1 : to,
from.map((f2) => f2 >= addedCaptureNum ? f2 + 1 : f2)
);
});
captureTransfers = newCaptureTransfers;
}
break;
}
numGroupsOpenInAG--;
}
} else if (m === "]") {
numCharClassesOpen--;
}
}
} while (hasProcessedAG);
hiddenCaptures.push(...addedHiddenCaptures);
expression = replaceUnescaped(
expression,
String.raw`\\(?<backrefNum>[1-9]\d*)|<\$\$(?<wrappedBackrefNum>\d+)>`,
({ 0: m, groups: { backrefNum, wrappedBackrefNum } }) => {
if (backrefNum) {
const bNum = +backrefNum;
if (bNum > captureNumMap.length - 1) {
throw new Error(`Backref "${m}" greater than number of captures`);
}
return `\\${captureNumMap[bNum]}`;
}
return `\\${wrappedBackrefNum}`;
},
Context.DEFAULT
);
return {
pattern: expression,
captureTransfers,
hiddenCaptures
};
}
var baseQuantifier = String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`;
var possessivePluginToken = new RegExp(String.raw`
\\(?: \d+
| c[A-Za-z]
| [gk]<[^>]+>
| [pPu]\{[^\}]+\}
| u[A-Fa-f\d]{4}
| x[A-Fa-f\d]{2}
)
| \((?: \? (?: [:=!>]
| <(?:[=!]|[^>]+>)
| [A-Za-z\-]+:
| \(DEFINE\)
))?
| (?<qBase>${baseQuantifier})(?<qMod>[?+]?)(?<invalidQ>[?*+\{]?)
| \\?.
`.replace(/\s+/g, ""), "gsu");
function possessive(expression) {
if (!new RegExp(`${baseQuantifier}\\+`).test(expression)) {
return {
pattern: expression
};
}
const openGroupIndices = [];
let lastGroupIndex = null;
let lastCharClassIndex = null;
let lastToken = "";
let numCharClassesOpen = 0;
let match;
possessivePluginToken.lastIndex = 0;
while (match = possessivePluginToken.exec(expression)) {
const { 0: m, index, groups: { qBase, qMod, invalidQ } } = match;
if (m === "[") {
if (!numCharClassesOpen) {
lastCharClassIndex = index;
}
numCharClassesOpen++;
} else if (m === "]") {
if (numCharClassesOpen) {
numCharClassesOpen--;
} else {
lastCharClassIndex = null;
}
} else if (!numCharClassesOpen) {
if (qMod === "+" && lastToken && !lastToken.startsWith("(")) {
if (invalidQ) {
throw new Error(`Invalid quantifier "${m}"`);
}
let charsAdded = -1;
if (/^\{\d+\}$/.test(qBase)) {
expression = spliceStr(expression, index + qBase.length, qMod, "");
} else {
if (lastToken === ")" || lastToken === "]") {
const nodeIndex = lastToken === ")" ? lastGroupIndex : lastCharClassIndex;
if (nodeIndex === null) {
throw new Error(`Invalid unmatched "${lastToken}"`);
}
expression = `${expression.slice(0, nodeIndex)}(?>${expression.slice(nodeIndex, index)}${qBase})${expression.slice(index + m.length)}`;
} else {
expression = `${expression.slice(0, index - lastToken.length)}(?>${lastToken}${qBase})${expression.slice(index + m.length)}`;
}
charsAdded += 4;
}
possessivePluginToken.lastIndex += charsAdded;
} else if (m[0] === "(") {
openGroupIndices.push(index);
} else if (m === ")") {
lastGroupIndex = openGroupIndices.length ? openGroupIndices.pop() : null;
}
}
lastToken = m;
}
return {
pattern: expression
};
}
// node_modules/regex-recursion/src/index.js
var r2 = String.raw;
var gRToken = r2`\\g<(?<gRNameOrNum>[^>&]+)&R=(?<gRDepth>[^>]+)>`;
var recursiveToken = r2`\(\?R=(?<rDepth>[^\)]+)\)|${gRToken}`;
var namedCaptureDelim = r2`\(\?<(?![=!])(?<captureName>[^>]+)>`;
var captureDelim = r2`${namedCaptureDelim}|(?<unnamed>\()(?!\?)`;
var token = new RegExp(r2`${namedCaptureDelim}|${recursiveToken}|\(\?|\\?.`, "gsu");
var overlappingRecursionMsg = "Cannot use multiple overlapping recursions";
function recursion(pattern, data) {
const { hiddenCaptures, mode } = {
hiddenCaptures: [],
mode: "plugin",
...data
};
let captureTransfers = data?.captureTransfers ?? /* @__PURE__ */ new Map();
if (!new RegExp(recursiveToken, "su").test(pattern)) {
return {
pattern,
captureTransfers,
hiddenCaptures
};
}
if (mode === "plugin" && hasUnescaped(pattern, r2`\(\?\(DEFINE\)`, Context.DEFAULT)) {
throw new Error("DEFINE groups cannot be used with recursion");
}
const addedHiddenCaptures = [];
const hasNumberedBackref = hasUnescaped(pattern, r2`\\[1-9]`, Context.DEFAULT);
const groupContentsStartPos = /* @__PURE__ */ new Map();
const openGroups = [];
let hasRecursed = false;
let numCharClassesOpen = 0;
let numCapturesPassed = 0;
let match;
token.lastIndex = 0;
while (match = token.exec(pattern)) {
const { 0: m, groups: { captureName, rDepth, gRNameOrNum, gRDepth } } = match;
if (m === "[") {
numCharClassesOpen++;
} else if (!numCharClassesOpen) {
if (rDepth) {
assertMaxInBounds(rDepth);
if (hasRecursed) {
throw new Error(overlappingRecursionMsg);
}
if (hasNumberedBackref) {
throw new Error(
// When used in `external` mode by transpilers other than Regex+, backrefs might have
// gone through conversion from named to numbered, so avoid a misleading error
`${mode === "external" ? "Backrefs" : "Numbered backrefs"} cannot be used with global recursion`
);
}
const left = pattern.slice(0, match.index);
const right = pattern.slice(token.lastIndex);
if (hasUnescaped(right, recursiveToken, Context.DEFAULT)) {
throw new Error(overlappingRecursionMsg);
}
const reps = +rDepth - 1;
pattern = makeRecursive(
left,
right,
reps,
false,
hiddenCaptures,
addedHiddenCaptures,
numCapturesPassed
);
captureTransfers = mapCaptureTransfers(
captureTransfers,
left,
reps,
addedHiddenCaptures.length,
0,
numCapturesPassed
);
break;
} else if (gRNameOrNum) {
assertMaxInBounds(gRDepth);
let isWithinReffedGroup = false;
for (const g2 of openGroups) {
if (g2.name === gRNameOrNum || g2.num === +gRNameOrNum) {
isWithinReffedGroup = true;
if (g2.hasRecursedWithin) {
throw new Error(overlappingRecursionMsg);
}
break;
}
}
if (!isWithinReffedGroup) {
throw new Error(r2`Recursive \g cannot be used outside the referenced group "${mode === "external" ? gRNameOrNum : r2`\g<${gRNameOrNum}&R=${gRDepth}>`}"`);
}
const startPos = groupContentsStartPos.get(gRNameOrNum);
const groupContents = getGroupContents(pattern, startPos);
if (hasNumberedBackref && hasUnescaped(groupContents, r2`${namedCaptureDelim}|\((?!\?)`, Context.DEFAULT)) {
throw new Error(
// When used in `external` mode by transpilers other than Regex+, backrefs might have
// gone through conversion from named to numbered, so avoid a misleading error
`${mode === "external" ? "Backrefs" : "Numbered backrefs"} cannot be used with recursion of capturing groups`
);
}
const groupContentsLeft = pattern.slice(startPos, match.index);
const groupContentsRight = groupContents.slice(groupContentsLeft.length + m.length);
const numAddedHiddenCapturesPreExpansion = addedHiddenCaptures.length;
const reps = +gRDepth - 1;
const expansion = makeRecursive(
groupContentsLeft,
groupContentsRight,