source: frontend/node_modules/@eslint-community/regexpp/index.mjs

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 106.9 KB
Line 
1var ast = /*#__PURE__*/Object.freeze({
2 __proto__: null
3});
4
5const latestEcmaVersion = 2025;
6
7let largeIdStartRanges = undefined;
8let largeIdContinueRanges = undefined;
9function isIdStart(cp) {
10 if (cp < 0x41)
11 return false;
12 if (cp < 0x5b)
13 return true;
14 if (cp < 0x61)
15 return false;
16 if (cp < 0x7b)
17 return true;
18 return isLargeIdStart(cp);
19}
20function isIdContinue(cp) {
21 if (cp < 0x30)
22 return false;
23 if (cp < 0x3a)
24 return true;
25 if (cp < 0x41)
26 return false;
27 if (cp < 0x5b)
28 return true;
29 if (cp === 0x5f)
30 return true;
31 if (cp < 0x61)
32 return false;
33 if (cp < 0x7b)
34 return true;
35 return isLargeIdStart(cp) || isLargeIdContinue(cp);
36}
37function isLargeIdStart(cp) {
38 return isInRange(cp, largeIdStartRanges !== null && largeIdStartRanges !== void 0 ? largeIdStartRanges : (largeIdStartRanges = initLargeIdStartRanges()));
39}
40function isLargeIdContinue(cp) {
41 return isInRange(cp, largeIdContinueRanges !== null && largeIdContinueRanges !== void 0 ? largeIdContinueRanges : (largeIdContinueRanges = initLargeIdContinueRanges()));
42}
43function initLargeIdStartRanges() {
44 return restoreRanges("4q 0 b 0 5 0 6 m 2 u 2 cp 5 b f 4 8 0 2 0 3m 4 2 1 3 3 2 0 7 0 2 2 2 0 2 j 2 2a 2 3u 9 4l 2 11 3 0 7 14 20 q 5 3 1a 16 10 1 2 2q 2 0 g 1 8 1 b 2 3 0 h 0 2 t u 2g c 0 p w a 1 5 0 6 l 5 0 a 0 4 0 o o 8 a 6 n 2 6 h 15 1n 1h 4 0 j 0 8 9 g f 5 7 3 1 3 l 2 6 2 0 4 3 4 0 h 0 e 1 2 2 f 1 b 0 9 5 5 1 3 l 2 6 2 1 2 1 2 1 w 3 2 0 k 2 h 8 2 2 2 l 2 6 2 1 2 4 4 0 j 0 g 1 o 0 c 7 3 1 3 l 2 6 2 1 2 4 4 0 v 1 2 2 g 0 i 0 2 5 4 2 2 3 4 1 2 0 2 1 4 1 4 2 4 b n 0 1h 7 2 2 2 m 2 f 4 0 r 2 2 1 3 1 v 0 5 7 2 2 2 m 2 9 2 4 4 0 v 2 2 1 g 1 i 8 2 2 2 14 3 0 h 0 6 2 9 2 p 5 6 h 4 n 2 8 2 0 3 6 1n 1b 2 1 d 6 1n 1 2 0 2 4 2 n 2 0 2 9 2 1 a 0 3 4 2 0 m 3 x 0 1s 7 2 z s 4 38 16 l 0 h 5 5 3 4 0 4 1 8 2 5 c d 0 i 11 2 0 6 0 3 16 2 98 2 3 3 6 2 0 2 3 3 14 2 3 3 w 2 3 3 6 2 0 2 3 3 e 2 1k 2 3 3 1u 12 f h 2d 3 5 4 h7 3 g 2 p 6 22 4 a 8 h e i f h f c 2 2 g 1f 10 0 5 0 1w 2g 8 14 2 0 6 1x b u 1e t 3 4 c 17 5 p 1j m a 1g 2b 0 2m 1a i 7 1j t e 1 b 17 r z 16 2 b z 3 a 6 16 3 2 16 3 2 5 2 1 4 0 6 5b 1t 7p 3 5 3 11 3 5 3 7 2 0 2 0 2 0 2 u 3 1g 2 6 2 0 4 2 2 6 4 3 3 5 5 c 6 2 2 6 39 0 e 0 h c 2u 0 5 0 3 9 2 0 3 5 7 0 2 0 2 0 2 f 3 3 6 4 5 0 i 14 22g 6c 7 3 4 1 d 11 2 0 6 0 3 1j 8 0 h m a 6 2 6 2 6 2 6 2 6 2 6 2 6 2 6 fb 2 q 8 8 4 3 4 5 2d 5 4 2 2h 2 3 6 16 2 2l i v 1d f e9 533 1t h3g 1w 19 3 7g 4 f b 1 l 1a h u 3 27 14 8 3 2u 3 29 l g 2 2 2 3 2 m u 1f f 1d 1r 5 4 0 2 1 c r b m q s 8 1a t 0 h 4 2 9 b 4 2 14 o 2 2 7 l m 4 0 4 1d 2 0 4 1 3 4 3 0 2 0 p 2 3 a 8 2 d 5 3 5 3 5 a 6 2 6 2 16 2 d 7 36 u 8mb d m 5 1c 6it a5 3 2x 13 6 d 4 6 0 2 9 2 c 2 4 2 0 2 1 2 1 2 2z y a2 j 1r 3 1h 15 b 39 4 2 3q 11 p 7 p c 2g 4 5 3 5 3 5 3 2 10 b 2 p 2 i 2 1 2 e 3 d z 3e 1y 1g 7g s 4 1c 1c v e t 6 11 b t 3 z 5 7 2 4 17 4d j z 5 z 5 13 9 1f d a 2 e 2 6 2 1 2 a 2 e 2 6 2 1 4 1f d 8m a l b 7 p 5 2 15 2 8 1y 5 3 0 2 17 2 1 4 0 3 m b m a u 1u i 2 1 b l b p 7 p 13 1j 7 1 1t 0 g 3 2 2 2 s 17 s 4 s 10 7 2 r s 1h b l b i e h 33 20 1k 1e e 1e e z 13 r a m 6z 15 7 1 h 5 1l s b 0 9 l 17 h 1b k s m d 1g 1m 1 3 0 e 18 x o r z u 0 3 0 9 y 4 0 d 1b f 3 m 0 2 0 10 h 2 o k 1 1s 6 2 0 2 3 2 e 2 9 8 1a 13 7 3 1 3 l 2 6 2 1 2 4 4 0 j 0 d 4 v 9 2 0 3 0 2 11 2 0 q 0 2 0 19 1g j 3 l 2 v 1b l 1 2 0 55 1a 16 3 11 1b l 0 1o 16 e 0 20 q 12 6 56 17 39 1r w 7 3 0 3 7 2 1 2 n g 0 2 0 2n 7 3 12 h 0 2 0 t 0 b 13 8 0 m 0 c 19 k 0 j 20 5k w w 8 2 10 i 0 1e t 35 6 2 1 2 11 m 0 q 5 2 1 2 v f 0 o 17 79 i g 0 2 c 2 x 3h 0 28 pl 2v 32 i 5f 219 2o g tr i 5 q 32y 6 g6 5a2 t 1cz fs 8 u i 26 i t j 1b h 3 w k 6 i c1 18 5w 1r x o 3 o 19 22 6 0 1v c 1t 1 2 0 f 4 a 5p1 16 v 2q 36 6pq 3 2 6 2 1 2 82 g 0 u 2 3 0 f 3 9 az 1s5 2y 6 c 4 8 8 9 4mf 2c 2 1y 2 1 3 0 3 1 3 3 2 b 2 0 2 6 2 1s 2 3 3 7 2 6 2 r 2 3 2 4 2 0 4 6 2 9f 3 o 2 o 2 u 2 o 2 u 2 o 2 u 2 o 2 u 2 o 2 7 1f9 u 7 5 7a 1p 43 18 b 6 h 0 8y t j 17 dh r 6d t 3 0 5s u 2 2 2 1 2 6 3 4 a 1 69 6 2 3 2 1 2 e 2 5g 1o 1v 8 0 xh 3 2 q 2 1 2 0 3 0 2 9 2 3 2 0 2 0 7 0 5 0 2 0 2 0 2 2 2 1 2 0 3 0 2 0 2 0 2 0 2 0 2 1 2 0 3 3 2 6 2 3 2 3 2 0 2 9 2 g 6 2 2 4 2 g 3et wyn x 3dp 3 4gd 3 5rk g h9 1wj f1 15v 3t6 6 6jt");
45}
46function initLargeIdContinueRanges() {
47 return restoreRanges("53 0 g9 33 o 0 70 4 7e 18 2 0 2 1 2 1 2 0 21 a 1d u 7 0 2u 6 3 5 3 1 2 3 3 9 o 0 v q 2k a g 9 y 8 a 0 p 3 2 8 2 2 2 4 18 2 1o 8 17 n 2 w 1j 2 2 h 2 6 b 1 3 9 i 2 1l 0 2 6 3 1 3 2 a 0 b 1 3 9 f 0 3 2 1l 0 2 4 5 1 3 2 4 0 l b 4 0 c 2 1l 0 2 7 2 2 2 2 l 1 3 9 b 5 2 2 1l 0 2 6 3 1 3 2 8 2 b 1 3 9 j 0 1o 4 4 2 2 3 a 0 f 9 h 4 1k 0 2 6 2 2 2 3 8 1 c 1 3 9 i 2 1l 0 2 6 2 2 2 3 8 1 c 1 3 9 4 0 d 3 1k 1 2 6 2 2 2 3 a 0 b 1 3 9 i 2 1z 0 5 5 2 0 2 7 7 9 3 1 1q 0 3 6 d 7 2 9 2g 0 3 8 c 6 2 9 1r 1 7 9 c 0 2 0 2 0 5 1 1e j 2 1 6 a 2 z a 0 2t j 2 9 d 3 5 2 2 2 3 6 4 3 e b 2 e jk 2 a 8 pt 3 t 2 u 1 v 1 1t v a 0 3 9 y 2 2 a 40 0 3b b 5 b b 9 3l a 1p 4 1m 9 2 s 3 a 7 9 n d 2 u 3 b l 4 1c g c 9 i 8 d 2 v c 3 9 19 d 1d j 9 9 7 9 3b 2 2 k 5 0 7 0 3 2 5j 1r el 1 1e 1 k 0 3g c 5 0 4 b 2db 2 3y 0 2p v ff 5 2y 1 2p 0 n51 9 1y 0 5 9 x 1 29 1 7l 0 4 0 5 0 o 4 5 0 2c 1 1f h b 9 7 h e a t 7 q c 19 3 1c d g 9 c 0 b 9 1c d d 0 9 1 3 9 y 2 1f 0 2 2 3 1 6 1 2 0 16 4 6 1 6l 7 2 1 3 9 fmt 0 ki f h f 4 1 p 2 5d 9 12 0 12 0 ig 0 6b 0 46 4 86 9 120 2 2 1 6 3 15 2 5 0 4m 1 fy 3 9 9 7 9 w 4 8u 1 26 5 1z a 1e 3 3f 2 1i e w a 3 1 b 3 1a a 8 0 1a 9 7 2 11 d 2 9 6 1 19 0 d 2 1d d 9 3 2 b 2b b 7 0 3 0 4e b 6 9 7 3 1k 1 2 6 3 1 3 2 a 0 b 1 3 6 4 4 1w 8 2 0 3 0 2 3 2 4 2 0 f 1 2b h a 9 5 0 2a j d 9 5y 6 3 8 s 1 2b g g 9 2a c 9 9 7 j 1m e 5 9 6r e 4m 9 1z 5 2 1 3 3 2 0 2 1 d 9 3c 6 3 6 4 0 t 9 15 6 2 3 9 0 a a 1b f 5j 7 3t 9 1i 7 2 7 h 9 1l l 2 d 3f 5 4 0 2 1 2 6 2 0 9 9 1d 4 2 1 2 4 9 9 1j 9 7e 3 a 1 2 0 1d 6 4 4 e a 44m 0 7 e 8uh r 1t3 9 2f 9 13 4 1o 6 q 9 ev 9 d2 0 2 1i 8 3 2a 0 c 1 f58 1 382 9 ef 19 3 m f3 4 4 5 9 7 3 6 v 3 45 2 13e 1d e9 1i 5 1d 9 0 f 0 n 4 2 e 11t 6 2 g 3 6 2 1 2 4 2t 0 4h 6 a 9 9x 0 1q d dv d 6t 1 2 9 6h 0 3 0 8 1 6 0 d7 6 32 6 6 9 3o7 9 gvt3 6n");
48}
49function isInRange(cp, ranges) {
50 let l = 0, r = (ranges.length / 2) | 0, i = 0, min = 0, max = 0;
51 while (l < r) {
52 i = ((l + r) / 2) | 0;
53 min = ranges[2 * i];
54 max = ranges[2 * i + 1];
55 if (cp < min) {
56 r = i;
57 }
58 else if (cp > max) {
59 l = i + 1;
60 }
61 else {
62 return true;
63 }
64 }
65 return false;
66}
67function restoreRanges(data) {
68 let last = 0;
69 return data.split(" ").map((s) => (last += parseInt(s, 36) | 0));
70}
71
72class DataSet {
73 constructor(raw2018, raw2019, raw2020, raw2021, raw2022, raw2023, raw2024, raw2025, raw2026) {
74 this._raw2018 = raw2018;
75 this._raw2019 = raw2019;
76 this._raw2020 = raw2020;
77 this._raw2021 = raw2021;
78 this._raw2022 = raw2022;
79 this._raw2023 = raw2023;
80 this._raw2024 = raw2024;
81 this._raw2025 = raw2025;
82 this._raw2026 = raw2026;
83 }
84 get es2018() {
85 var _a;
86 return ((_a = this._set2018) !== null && _a !== void 0 ? _a : (this._set2018 = new Set(this._raw2018.split(" "))));
87 }
88 get es2019() {
89 var _a;
90 return ((_a = this._set2019) !== null && _a !== void 0 ? _a : (this._set2019 = new Set(this._raw2019.split(" "))));
91 }
92 get es2020() {
93 var _a;
94 return ((_a = this._set2020) !== null && _a !== void 0 ? _a : (this._set2020 = new Set(this._raw2020.split(" "))));
95 }
96 get es2021() {
97 var _a;
98 return ((_a = this._set2021) !== null && _a !== void 0 ? _a : (this._set2021 = new Set(this._raw2021.split(" "))));
99 }
100 get es2022() {
101 var _a;
102 return ((_a = this._set2022) !== null && _a !== void 0 ? _a : (this._set2022 = new Set(this._raw2022.split(" "))));
103 }
104 get es2023() {
105 var _a;
106 return ((_a = this._set2023) !== null && _a !== void 0 ? _a : (this._set2023 = new Set(this._raw2023.split(" "))));
107 }
108 get es2024() {
109 var _a;
110 return ((_a = this._set2024) !== null && _a !== void 0 ? _a : (this._set2024 = new Set(this._raw2024.split(" "))));
111 }
112 get es2025() {
113 var _a;
114 return ((_a = this._set2025) !== null && _a !== void 0 ? _a : (this._set2025 = new Set(this._raw2025.split(" "))));
115 }
116 get es2026() {
117 var _a;
118 return ((_a = this._set2026) !== null && _a !== void 0 ? _a : (this._set2026 = new Set(this._raw2026.split(" "))));
119 }
120}
121const gcNameSet = new Set(["General_Category", "gc"]);
122const scNameSet = new Set(["Script", "Script_Extensions", "sc", "scx"]);
123const gcValueSets = new DataSet("C Cased_Letter Cc Cf Close_Punctuation Cn Co Combining_Mark Connector_Punctuation Control Cs Currency_Symbol Dash_Punctuation Decimal_Number Enclosing_Mark Final_Punctuation Format Initial_Punctuation L LC Letter Letter_Number Line_Separator Ll Lm Lo Lowercase_Letter Lt Lu M Mark Math_Symbol Mc Me Mn Modifier_Letter Modifier_Symbol N Nd Nl No Nonspacing_Mark Number Open_Punctuation Other Other_Letter Other_Number Other_Punctuation Other_Symbol P Paragraph_Separator Pc Pd Pe Pf Pi Po Private_Use Ps Punctuation S Sc Separator Sk Sm So Space_Separator Spacing_Mark Surrogate Symbol Titlecase_Letter Unassigned Uppercase_Letter Z Zl Zp Zs cntrl digit punct", "", "", "", "", "", "", "", "");
124const scValueSets = new DataSet("Adlam Adlm Aghb Ahom Anatolian_Hieroglyphs Arab Arabic Armenian Armi Armn Avestan Avst Bali Balinese Bamu Bamum Bass Bassa_Vah Batak Batk Beng Bengali Bhaiksuki Bhks Bopo Bopomofo Brah Brahmi Brai Braille Bugi Buginese Buhd Buhid Cakm Canadian_Aboriginal Cans Cari Carian Caucasian_Albanian Chakma Cham Cher Cherokee Common Copt Coptic Cprt Cuneiform Cypriot Cyrillic Cyrl Deseret Deva Devanagari Dsrt Dupl Duployan Egyp Egyptian_Hieroglyphs Elba Elbasan Ethi Ethiopic Geor Georgian Glag Glagolitic Gonm Goth Gothic Gran Grantha Greek Grek Gujarati Gujr Gurmukhi Guru Han Hang Hangul Hani Hano Hanunoo Hatr Hatran Hebr Hebrew Hira Hiragana Hluw Hmng Hung Imperial_Aramaic Inherited Inscriptional_Pahlavi Inscriptional_Parthian Ital Java Javanese Kaithi Kali Kana Kannada Katakana Kayah_Li Khar Kharoshthi Khmer Khmr Khoj Khojki Khudawadi Knda Kthi Lana Lao Laoo Latin Latn Lepc Lepcha Limb Limbu Lina Linb Linear_A Linear_B Lisu Lyci Lycian Lydi Lydian Mahajani Mahj Malayalam Mand Mandaic Mani Manichaean Marc Marchen Masaram_Gondi Meetei_Mayek Mend Mende_Kikakui Merc Mero Meroitic_Cursive Meroitic_Hieroglyphs Miao Mlym Modi Mong Mongolian Mro Mroo Mtei Mult Multani Myanmar Mymr Nabataean Narb Nbat New_Tai_Lue Newa Nko Nkoo Nshu Nushu Ogam Ogham Ol_Chiki Olck Old_Hungarian Old_Italic Old_North_Arabian Old_Permic Old_Persian Old_South_Arabian Old_Turkic Oriya Orkh Orya Osage Osge Osma Osmanya Pahawh_Hmong Palm Palmyrene Pau_Cin_Hau Pauc Perm Phag Phags_Pa Phli Phlp Phnx Phoenician Plrd Prti Psalter_Pahlavi Qaac Qaai Rejang Rjng Runic Runr Samaritan Samr Sarb Saur Saurashtra Sgnw Sharada Shavian Shaw Shrd Sidd Siddham SignWriting Sind Sinh Sinhala Sora Sora_Sompeng Soyo Soyombo Sund Sundanese Sylo Syloti_Nagri Syrc Syriac Tagalog Tagb Tagbanwa Tai_Le Tai_Tham Tai_Viet Takr Takri Tale Talu Tamil Taml Tang Tangut Tavt Telu Telugu Tfng Tglg Thaa Thaana Thai Tibetan Tibt Tifinagh Tirh Tirhuta Ugar Ugaritic Vai Vaii Wara Warang_Citi Xpeo Xsux Yi Yiii Zanabazar_Square Zanb Zinh Zyyy", "Dogr Dogra Gong Gunjala_Gondi Hanifi_Rohingya Maka Makasar Medefaidrin Medf Old_Sogdian Rohg Sogd Sogdian Sogo", "Elym Elymaic Hmnp Nand Nandinagari Nyiakeng_Puachue_Hmong Wancho Wcho", "Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi", "Cpmn Cypro_Minoan Old_Uyghur Ougr Tangsa Tnsa Toto Vith Vithkuqi", "Berf Beria_Erfe Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sidetic Sidt Sunu Sunuwar Tai_Yo Tayo Todhri Todr Tolong_Siki Tols Tulu_Tigalari Tutg Unknown Zzzz", "", "", "");
125const binPropertySets = new DataSet("AHex ASCII ASCII_Hex_Digit Alpha Alphabetic Any Assigned Bidi_C Bidi_Control Bidi_M Bidi_Mirrored CI CWCF CWCM CWKCF CWL CWT CWU Case_Ignorable Cased Changes_When_Casefolded Changes_When_Casemapped Changes_When_Lowercased Changes_When_NFKC_Casefolded Changes_When_Titlecased Changes_When_Uppercased DI Dash Default_Ignorable_Code_Point Dep Deprecated Dia Diacritic Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Ext Extender Gr_Base Gr_Ext Grapheme_Base Grapheme_Extend Hex Hex_Digit IDC IDS IDSB IDST IDS_Binary_Operator IDS_Trinary_Operator ID_Continue ID_Start Ideo Ideographic Join_C Join_Control LOE Logical_Order_Exception Lower Lowercase Math NChar Noncharacter_Code_Point Pat_Syn Pat_WS Pattern_Syntax Pattern_White_Space QMark Quotation_Mark RI Radical Regional_Indicator SD STerm Sentence_Terminal Soft_Dotted Term Terminal_Punctuation UIdeo Unified_Ideograph Upper Uppercase VS Variation_Selector White_Space XIDC XIDS XID_Continue XID_Start space", "Extended_Pictographic", "", "EBase EComp EMod EPres ExtPict", "", "", "", "", "");
126const binPropertyOfStringsSets = new DataSet("", "", "", "", "", "", "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji RGI_Emoji_Flag_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence", "", "");
127function isValidUnicodeProperty(version, name, value) {
128 if (gcNameSet.has(name)) {
129 return version >= 2018 && gcValueSets.es2018.has(value);
130 }
131 if (scNameSet.has(name)) {
132 return ((version >= 2018 && scValueSets.es2018.has(value)) ||
133 (version >= 2019 && scValueSets.es2019.has(value)) ||
134 (version >= 2020 && scValueSets.es2020.has(value)) ||
135 (version >= 2021 && scValueSets.es2021.has(value)) ||
136 (version >= 2022 && scValueSets.es2022.has(value)) ||
137 (version >= 2023 && scValueSets.es2023.has(value)));
138 }
139 return false;
140}
141function isValidLoneUnicodeProperty(version, value) {
142 return ((version >= 2018 && binPropertySets.es2018.has(value)) ||
143 (version >= 2019 && binPropertySets.es2019.has(value)) ||
144 (version >= 2021 && binPropertySets.es2021.has(value)));
145}
146function isValidLoneUnicodePropertyOfString(version, value) {
147 return version >= 2024 && binPropertyOfStringsSets.es2024.has(value);
148}
149
150const BACKSPACE = 0x08;
151const CHARACTER_TABULATION = 0x09;
152const LINE_FEED = 0x0a;
153const LINE_TABULATION = 0x0b;
154const FORM_FEED = 0x0c;
155const CARRIAGE_RETURN = 0x0d;
156const EXCLAMATION_MARK = 0x21;
157const NUMBER_SIGN = 0x23;
158const DOLLAR_SIGN = 0x24;
159const PERCENT_SIGN = 0x25;
160const AMPERSAND = 0x26;
161const LEFT_PARENTHESIS = 0x28;
162const RIGHT_PARENTHESIS = 0x29;
163const ASTERISK = 0x2a;
164const PLUS_SIGN = 0x2b;
165const COMMA = 0x2c;
166const HYPHEN_MINUS = 0x2d;
167const FULL_STOP = 0x2e;
168const SOLIDUS = 0x2f;
169const DIGIT_ZERO = 0x30;
170const DIGIT_ONE = 0x31;
171const DIGIT_SEVEN = 0x37;
172const DIGIT_NINE = 0x39;
173const COLON = 0x3a;
174const SEMICOLON = 0x3b;
175const LESS_THAN_SIGN = 0x3c;
176const EQUALS_SIGN = 0x3d;
177const GREATER_THAN_SIGN = 0x3e;
178const QUESTION_MARK = 0x3f;
179const COMMERCIAL_AT = 0x40;
180const LATIN_CAPITAL_LETTER_A = 0x41;
181const LATIN_CAPITAL_LETTER_B = 0x42;
182const LATIN_CAPITAL_LETTER_D = 0x44;
183const LATIN_CAPITAL_LETTER_F = 0x46;
184const LATIN_CAPITAL_LETTER_P = 0x50;
185const LATIN_CAPITAL_LETTER_S = 0x53;
186const LATIN_CAPITAL_LETTER_W = 0x57;
187const LATIN_CAPITAL_LETTER_Z = 0x5a;
188const LOW_LINE = 0x5f;
189const LATIN_SMALL_LETTER_A = 0x61;
190const LATIN_SMALL_LETTER_B = 0x62;
191const LATIN_SMALL_LETTER_C = 0x63;
192const LATIN_SMALL_LETTER_D = 0x64;
193const LATIN_SMALL_LETTER_F = 0x66;
194const LATIN_SMALL_LETTER_G = 0x67;
195const LATIN_SMALL_LETTER_I = 0x69;
196const LATIN_SMALL_LETTER_K = 0x6b;
197const LATIN_SMALL_LETTER_M = 0x6d;
198const LATIN_SMALL_LETTER_N = 0x6e;
199const LATIN_SMALL_LETTER_P = 0x70;
200const LATIN_SMALL_LETTER_Q = 0x71;
201const LATIN_SMALL_LETTER_R = 0x72;
202const LATIN_SMALL_LETTER_S = 0x73;
203const LATIN_SMALL_LETTER_T = 0x74;
204const LATIN_SMALL_LETTER_U = 0x75;
205const LATIN_SMALL_LETTER_V = 0x76;
206const LATIN_SMALL_LETTER_W = 0x77;
207const LATIN_SMALL_LETTER_X = 0x78;
208const LATIN_SMALL_LETTER_Y = 0x79;
209const LATIN_SMALL_LETTER_Z = 0x7a;
210const LEFT_SQUARE_BRACKET = 0x5b;
211const REVERSE_SOLIDUS = 0x5c;
212const RIGHT_SQUARE_BRACKET = 0x5d;
213const CIRCUMFLEX_ACCENT = 0x5e;
214const GRAVE_ACCENT = 0x60;
215const LEFT_CURLY_BRACKET = 0x7b;
216const VERTICAL_LINE = 0x7c;
217const RIGHT_CURLY_BRACKET = 0x7d;
218const TILDE = 0x7e;
219const ZERO_WIDTH_NON_JOINER = 0x200c;
220const ZERO_WIDTH_JOINER = 0x200d;
221const LINE_SEPARATOR = 0x2028;
222const PARAGRAPH_SEPARATOR = 0x2029;
223const MIN_CODE_POINT = 0x00;
224const MAX_CODE_POINT = 0x10ffff;
225function isLatinLetter(code) {
226 return ((code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_Z) ||
227 (code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_Z));
228}
229function isDecimalDigit(code) {
230 return code >= DIGIT_ZERO && code <= DIGIT_NINE;
231}
232function isOctalDigit(code) {
233 return code >= DIGIT_ZERO && code <= DIGIT_SEVEN;
234}
235function isHexDigit(code) {
236 return ((code >= DIGIT_ZERO && code <= DIGIT_NINE) ||
237 (code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) ||
238 (code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F));
239}
240function isLineTerminator(code) {
241 return (code === LINE_FEED ||
242 code === CARRIAGE_RETURN ||
243 code === LINE_SEPARATOR ||
244 code === PARAGRAPH_SEPARATOR);
245}
246function isValidUnicode(code) {
247 return code >= MIN_CODE_POINT && code <= MAX_CODE_POINT;
248}
249function digitToInt(code) {
250 if (code >= LATIN_SMALL_LETTER_A && code <= LATIN_SMALL_LETTER_F) {
251 return code - LATIN_SMALL_LETTER_A + 10;
252 }
253 if (code >= LATIN_CAPITAL_LETTER_A && code <= LATIN_CAPITAL_LETTER_F) {
254 return code - LATIN_CAPITAL_LETTER_A + 10;
255 }
256 return code - DIGIT_ZERO;
257}
258function isLeadSurrogate(code) {
259 return code >= 0xd800 && code <= 0xdbff;
260}
261function isTrailSurrogate(code) {
262 return code >= 0xdc00 && code <= 0xdfff;
263}
264function combineSurrogatePair(lead, trail) {
265 return (lead - 0xd800) * 0x400 + (trail - 0xdc00) + 0x10000;
266}
267
268class GroupSpecifiersAsES2018 {
269 constructor() {
270 this.groupName = new Set();
271 }
272 clear() {
273 this.groupName.clear();
274 }
275 isEmpty() {
276 return !this.groupName.size;
277 }
278 hasInPattern(name) {
279 return this.groupName.has(name);
280 }
281 hasInScope(name) {
282 return this.hasInPattern(name);
283 }
284 addToScope(name) {
285 this.groupName.add(name);
286 }
287 enterDisjunction() {
288 }
289 enterAlternative() {
290 }
291 leaveDisjunction() {
292 }
293}
294class BranchID {
295 constructor(parent, base) {
296 this.parent = parent;
297 this.base = base !== null && base !== void 0 ? base : this;
298 }
299 separatedFrom(other) {
300 var _a, _b;
301 if (this.base === other.base && this !== other) {
302 return true;
303 }
304 if (other.parent && this.separatedFrom(other.parent)) {
305 return true;
306 }
307 return (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.separatedFrom(other)) !== null && _b !== void 0 ? _b : false;
308 }
309 child() {
310 return new BranchID(this, null);
311 }
312 sibling() {
313 return new BranchID(this.parent, this.base);
314 }
315}
316class GroupSpecifiersAsES2025 {
317 constructor() {
318 this.branchID = new BranchID(null, null);
319 this.groupNames = new Map();
320 }
321 clear() {
322 this.branchID = new BranchID(null, null);
323 this.groupNames.clear();
324 }
325 isEmpty() {
326 return !this.groupNames.size;
327 }
328 enterDisjunction() {
329 this.branchID = this.branchID.child();
330 }
331 enterAlternative(index) {
332 if (index === 0) {
333 return;
334 }
335 this.branchID = this.branchID.sibling();
336 }
337 leaveDisjunction() {
338 this.branchID = this.branchID.parent;
339 }
340 hasInPattern(name) {
341 return this.groupNames.has(name);
342 }
343 hasInScope(name) {
344 const branches = this.groupNames.get(name);
345 if (!branches) {
346 return false;
347 }
348 for (const branch of branches) {
349 if (!branch.separatedFrom(this.branchID)) {
350 return true;
351 }
352 }
353 return false;
354 }
355 addToScope(name) {
356 const branches = this.groupNames.get(name);
357 if (branches) {
358 branches.push(this.branchID);
359 return;
360 }
361 this.groupNames.set(name, [this.branchID]);
362 }
363}
364
365const legacyImpl = {
366 at(s, end, i) {
367 return i < end ? s.charCodeAt(i) : -1;
368 },
369 width(c) {
370 return 1;
371 },
372};
373const unicodeImpl = {
374 at(s, end, i) {
375 return i < end ? s.codePointAt(i) : -1;
376 },
377 width(c) {
378 return c > 0xffff ? 2 : 1;
379 },
380};
381class Reader {
382 constructor() {
383 this._impl = legacyImpl;
384 this._s = "";
385 this._i = 0;
386 this._end = 0;
387 this._cp1 = -1;
388 this._w1 = 1;
389 this._cp2 = -1;
390 this._w2 = 1;
391 this._cp3 = -1;
392 this._w3 = 1;
393 this._cp4 = -1;
394 }
395 get source() {
396 return this._s;
397 }
398 get index() {
399 return this._i;
400 }
401 get currentCodePoint() {
402 return this._cp1;
403 }
404 get nextCodePoint() {
405 return this._cp2;
406 }
407 get nextCodePoint2() {
408 return this._cp3;
409 }
410 get nextCodePoint3() {
411 return this._cp4;
412 }
413 reset(source, start, end, uFlag) {
414 this._impl = uFlag ? unicodeImpl : legacyImpl;
415 this._s = source;
416 this._end = end;
417 this.rewind(start);
418 }
419 rewind(index) {
420 const impl = this._impl;
421 this._i = index;
422 this._cp1 = impl.at(this._s, this._end, index);
423 this._w1 = impl.width(this._cp1);
424 this._cp2 = impl.at(this._s, this._end, index + this._w1);
425 this._w2 = impl.width(this._cp2);
426 this._cp3 = impl.at(this._s, this._end, index + this._w1 + this._w2);
427 this._w3 = impl.width(this._cp3);
428 this._cp4 = impl.at(this._s, this._end, index + this._w1 + this._w2 + this._w3);
429 }
430 advance() {
431 if (this._cp1 !== -1) {
432 const impl = this._impl;
433 this._i += this._w1;
434 this._cp1 = this._cp2;
435 this._w1 = this._w2;
436 this._cp2 = this._cp3;
437 this._w2 = impl.width(this._cp2);
438 this._cp3 = this._cp4;
439 this._w3 = impl.width(this._cp3);
440 this._cp4 = impl.at(this._s, this._end, this._i + this._w1 + this._w2 + this._w3);
441 }
442 }
443 eat(cp) {
444 if (this._cp1 === cp) {
445 this.advance();
446 return true;
447 }
448 return false;
449 }
450 eat2(cp1, cp2) {
451 if (this._cp1 === cp1 && this._cp2 === cp2) {
452 this.advance();
453 this.advance();
454 return true;
455 }
456 return false;
457 }
458 eat3(cp1, cp2, cp3) {
459 if (this._cp1 === cp1 && this._cp2 === cp2 && this._cp3 === cp3) {
460 this.advance();
461 this.advance();
462 this.advance();
463 return true;
464 }
465 return false;
466 }
467}
468
469class RegExpSyntaxError extends SyntaxError {
470 constructor(message, index) {
471 super(message);
472 this.index = index;
473 }
474}
475function newRegExpSyntaxError(srcCtx, flags, index, message) {
476 let source = "";
477 if (srcCtx.kind === "literal") {
478 const literal = srcCtx.source.slice(srcCtx.start, srcCtx.end);
479 if (literal) {
480 source = `: ${literal}`;
481 }
482 }
483 else if (srcCtx.kind === "pattern") {
484 const pattern = srcCtx.source.slice(srcCtx.start, srcCtx.end);
485 const flagsText = `${flags.unicode ? "u" : ""}${flags.unicodeSets ? "v" : ""}`;
486 source = `: /${pattern}/${flagsText}`;
487 }
488 return new RegExpSyntaxError(`Invalid regular expression${source}: ${message}`, index);
489}
490
491const SYNTAX_CHARACTER = new Set([
492 CIRCUMFLEX_ACCENT,
493 DOLLAR_SIGN,
494 REVERSE_SOLIDUS,
495 FULL_STOP,
496 ASTERISK,
497 PLUS_SIGN,
498 QUESTION_MARK,
499 LEFT_PARENTHESIS,
500 RIGHT_PARENTHESIS,
501 LEFT_SQUARE_BRACKET,
502 RIGHT_SQUARE_BRACKET,
503 LEFT_CURLY_BRACKET,
504 RIGHT_CURLY_BRACKET,
505 VERTICAL_LINE,
506]);
507const CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR_CHARACTER = new Set([
508 AMPERSAND,
509 EXCLAMATION_MARK,
510 NUMBER_SIGN,
511 DOLLAR_SIGN,
512 PERCENT_SIGN,
513 ASTERISK,
514 PLUS_SIGN,
515 COMMA,
516 FULL_STOP,
517 COLON,
518 SEMICOLON,
519 LESS_THAN_SIGN,
520 EQUALS_SIGN,
521 GREATER_THAN_SIGN,
522 QUESTION_MARK,
523 COMMERCIAL_AT,
524 CIRCUMFLEX_ACCENT,
525 GRAVE_ACCENT,
526 TILDE,
527]);
528const CLASS_SET_SYNTAX_CHARACTER = new Set([
529 LEFT_PARENTHESIS,
530 RIGHT_PARENTHESIS,
531 LEFT_SQUARE_BRACKET,
532 RIGHT_SQUARE_BRACKET,
533 LEFT_CURLY_BRACKET,
534 RIGHT_CURLY_BRACKET,
535 SOLIDUS,
536 HYPHEN_MINUS,
537 REVERSE_SOLIDUS,
538 VERTICAL_LINE,
539]);
540const CLASS_SET_RESERVED_PUNCTUATOR = new Set([
541 AMPERSAND,
542 HYPHEN_MINUS,
543 EXCLAMATION_MARK,
544 NUMBER_SIGN,
545 PERCENT_SIGN,
546 COMMA,
547 COLON,
548 SEMICOLON,
549 LESS_THAN_SIGN,
550 EQUALS_SIGN,
551 GREATER_THAN_SIGN,
552 COMMERCIAL_AT,
553 GRAVE_ACCENT,
554 TILDE,
555]);
556const FLAG_PROP_TO_CODEPOINT = {
557 global: LATIN_SMALL_LETTER_G,
558 ignoreCase: LATIN_SMALL_LETTER_I,
559 multiline: LATIN_SMALL_LETTER_M,
560 unicode: LATIN_SMALL_LETTER_U,
561 sticky: LATIN_SMALL_LETTER_Y,
562 dotAll: LATIN_SMALL_LETTER_S,
563 hasIndices: LATIN_SMALL_LETTER_D,
564 unicodeSets: LATIN_SMALL_LETTER_V,
565};
566const FLAG_CODEPOINT_TO_PROP = Object.fromEntries(Object.entries(FLAG_PROP_TO_CODEPOINT).map(([k, v]) => [v, k]));
567function isSyntaxCharacter(cp) {
568 return SYNTAX_CHARACTER.has(cp);
569}
570function isClassSetReservedDoublePunctuatorCharacter(cp) {
571 return CLASS_SET_RESERVED_DOUBLE_PUNCTUATOR_CHARACTER.has(cp);
572}
573function isClassSetSyntaxCharacter(cp) {
574 return CLASS_SET_SYNTAX_CHARACTER.has(cp);
575}
576function isClassSetReservedPunctuator(cp) {
577 return CLASS_SET_RESERVED_PUNCTUATOR.has(cp);
578}
579function isIdentifierStartChar(cp) {
580 return isIdStart(cp) || cp === DOLLAR_SIGN || cp === LOW_LINE;
581}
582function isIdentifierPartChar(cp) {
583 return (isIdContinue(cp) ||
584 cp === DOLLAR_SIGN ||
585 cp === ZERO_WIDTH_NON_JOINER ||
586 cp === ZERO_WIDTH_JOINER);
587}
588function isUnicodePropertyNameCharacter(cp) {
589 return isLatinLetter(cp) || cp === LOW_LINE;
590}
591function isUnicodePropertyValueCharacter(cp) {
592 return isUnicodePropertyNameCharacter(cp) || isDecimalDigit(cp);
593}
594function isRegularExpressionModifier(ch) {
595 return (ch === LATIN_SMALL_LETTER_I ||
596 ch === LATIN_SMALL_LETTER_M ||
597 ch === LATIN_SMALL_LETTER_S);
598}
599class RegExpValidator {
600 constructor(options) {
601 this._reader = new Reader();
602 this._unicodeMode = false;
603 this._unicodeSetsMode = false;
604 this._nFlag = false;
605 this._lastIntValue = 0;
606 this._lastRange = {
607 min: 0,
608 max: Number.POSITIVE_INFINITY,
609 };
610 this._lastStrValue = "";
611 this._lastAssertionIsQuantifiable = false;
612 this._numCapturingParens = 0;
613 this._backreferenceNames = new Set();
614 this._srcCtx = null;
615 this._options = options !== null && options !== void 0 ? options : {};
616 this._groupSpecifiers =
617 this.ecmaVersion >= 2025
618 ? new GroupSpecifiersAsES2025()
619 : new GroupSpecifiersAsES2018();
620 }
621 validateLiteral(source, start = 0, end = source.length) {
622 this._srcCtx = { source, start, end, kind: "literal" };
623 this._unicodeSetsMode = this._unicodeMode = this._nFlag = false;
624 this.reset(source, start, end);
625 this.onLiteralEnter(start);
626 if (this.eat(SOLIDUS) && this.eatRegExpBody() && this.eat(SOLIDUS)) {
627 const flagStart = this.index;
628 const unicode = source.includes("u", flagStart);
629 const unicodeSets = source.includes("v", flagStart);
630 this.validateFlagsInternal(source, flagStart, end);
631 this.validatePatternInternal(source, start + 1, flagStart - 1, {
632 unicode,
633 unicodeSets,
634 });
635 }
636 else if (start >= end) {
637 this.raise("Empty");
638 }
639 else {
640 const c = String.fromCodePoint(this.currentCodePoint);
641 this.raise(`Unexpected character '${c}'`);
642 }
643 this.onLiteralLeave(start, end);
644 }
645 validateFlags(source, start = 0, end = source.length) {
646 this._srcCtx = { source, start, end, kind: "flags" };
647 this.validateFlagsInternal(source, start, end);
648 }
649 validatePattern(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
650 this._srcCtx = { source, start, end, kind: "pattern" };
651 this.validatePatternInternal(source, start, end, uFlagOrFlags);
652 }
653 validatePatternInternal(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
654 const mode = this._parseFlagsOptionToMode(uFlagOrFlags, end);
655 this._unicodeMode = mode.unicodeMode;
656 this._nFlag = mode.nFlag;
657 this._unicodeSetsMode = mode.unicodeSetsMode;
658 this.reset(source, start, end);
659 this.consumePattern();
660 if (!this._nFlag &&
661 this.ecmaVersion >= 2018 &&
662 !this._groupSpecifiers.isEmpty()) {
663 this._nFlag = true;
664 this.rewind(start);
665 this.consumePattern();
666 }
667 }
668 validateFlagsInternal(source, start, end) {
669 const flags = this.parseFlags(source, start, end);
670 this.onRegExpFlags(start, end, flags);
671 }
672 _parseFlagsOptionToMode(uFlagOrFlags, sourceEnd) {
673 let unicode = false;
674 let unicodeSets = false;
675 if (uFlagOrFlags && this.ecmaVersion >= 2015) {
676 if (typeof uFlagOrFlags === "object") {
677 unicode = Boolean(uFlagOrFlags.unicode);
678 if (this.ecmaVersion >= 2024) {
679 unicodeSets = Boolean(uFlagOrFlags.unicodeSets);
680 }
681 }
682 else {
683 unicode = uFlagOrFlags;
684 }
685 }
686 if (unicode && unicodeSets) {
687 this.raise("Invalid regular expression flags", {
688 index: sourceEnd + 1,
689 unicode,
690 unicodeSets,
691 });
692 }
693 const unicodeMode = unicode || unicodeSets;
694 const nFlag = (unicode && this.ecmaVersion >= 2018) ||
695 unicodeSets ||
696 Boolean(this._options.strict && this.ecmaVersion >= 2023);
697 const unicodeSetsMode = unicodeSets;
698 return { unicodeMode, nFlag, unicodeSetsMode };
699 }
700 get strict() {
701 return Boolean(this._options.strict) || this._unicodeMode;
702 }
703 get ecmaVersion() {
704 var _a;
705 return (_a = this._options.ecmaVersion) !== null && _a !== void 0 ? _a : latestEcmaVersion;
706 }
707 onLiteralEnter(start) {
708 if (this._options.onLiteralEnter) {
709 this._options.onLiteralEnter(start);
710 }
711 }
712 onLiteralLeave(start, end) {
713 if (this._options.onLiteralLeave) {
714 this._options.onLiteralLeave(start, end);
715 }
716 }
717 onRegExpFlags(start, end, flags) {
718 if (this._options.onRegExpFlags) {
719 this._options.onRegExpFlags(start, end, flags);
720 }
721 if (this._options.onFlags) {
722 this._options.onFlags(start, end, flags.global, flags.ignoreCase, flags.multiline, flags.unicode, flags.sticky, flags.dotAll, flags.hasIndices);
723 }
724 }
725 onPatternEnter(start) {
726 if (this._options.onPatternEnter) {
727 this._options.onPatternEnter(start);
728 }
729 }
730 onPatternLeave(start, end) {
731 if (this._options.onPatternLeave) {
732 this._options.onPatternLeave(start, end);
733 }
734 }
735 onDisjunctionEnter(start) {
736 if (this._options.onDisjunctionEnter) {
737 this._options.onDisjunctionEnter(start);
738 }
739 }
740 onDisjunctionLeave(start, end) {
741 if (this._options.onDisjunctionLeave) {
742 this._options.onDisjunctionLeave(start, end);
743 }
744 }
745 onAlternativeEnter(start, index) {
746 if (this._options.onAlternativeEnter) {
747 this._options.onAlternativeEnter(start, index);
748 }
749 }
750 onAlternativeLeave(start, end, index) {
751 if (this._options.onAlternativeLeave) {
752 this._options.onAlternativeLeave(start, end, index);
753 }
754 }
755 onGroupEnter(start) {
756 if (this._options.onGroupEnter) {
757 this._options.onGroupEnter(start);
758 }
759 }
760 onGroupLeave(start, end) {
761 if (this._options.onGroupLeave) {
762 this._options.onGroupLeave(start, end);
763 }
764 }
765 onModifiersEnter(start) {
766 if (this._options.onModifiersEnter) {
767 this._options.onModifiersEnter(start);
768 }
769 }
770 onModifiersLeave(start, end) {
771 if (this._options.onModifiersLeave) {
772 this._options.onModifiersLeave(start, end);
773 }
774 }
775 onAddModifiers(start, end, flags) {
776 if (this._options.onAddModifiers) {
777 this._options.onAddModifiers(start, end, flags);
778 }
779 }
780 onRemoveModifiers(start, end, flags) {
781 if (this._options.onRemoveModifiers) {
782 this._options.onRemoveModifiers(start, end, flags);
783 }
784 }
785 onCapturingGroupEnter(start, name) {
786 if (this._options.onCapturingGroupEnter) {
787 this._options.onCapturingGroupEnter(start, name);
788 }
789 }
790 onCapturingGroupLeave(start, end, name) {
791 if (this._options.onCapturingGroupLeave) {
792 this._options.onCapturingGroupLeave(start, end, name);
793 }
794 }
795 onQuantifier(start, end, min, max, greedy) {
796 if (this._options.onQuantifier) {
797 this._options.onQuantifier(start, end, min, max, greedy);
798 }
799 }
800 onLookaroundAssertionEnter(start, kind, negate) {
801 if (this._options.onLookaroundAssertionEnter) {
802 this._options.onLookaroundAssertionEnter(start, kind, negate);
803 }
804 }
805 onLookaroundAssertionLeave(start, end, kind, negate) {
806 if (this._options.onLookaroundAssertionLeave) {
807 this._options.onLookaroundAssertionLeave(start, end, kind, negate);
808 }
809 }
810 onEdgeAssertion(start, end, kind) {
811 if (this._options.onEdgeAssertion) {
812 this._options.onEdgeAssertion(start, end, kind);
813 }
814 }
815 onWordBoundaryAssertion(start, end, kind, negate) {
816 if (this._options.onWordBoundaryAssertion) {
817 this._options.onWordBoundaryAssertion(start, end, kind, negate);
818 }
819 }
820 onAnyCharacterSet(start, end, kind) {
821 if (this._options.onAnyCharacterSet) {
822 this._options.onAnyCharacterSet(start, end, kind);
823 }
824 }
825 onEscapeCharacterSet(start, end, kind, negate) {
826 if (this._options.onEscapeCharacterSet) {
827 this._options.onEscapeCharacterSet(start, end, kind, negate);
828 }
829 }
830 onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings) {
831 if (this._options.onUnicodePropertyCharacterSet) {
832 this._options.onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings);
833 }
834 }
835 onCharacter(start, end, value) {
836 if (this._options.onCharacter) {
837 this._options.onCharacter(start, end, value);
838 }
839 }
840 onBackreference(start, end, ref) {
841 if (this._options.onBackreference) {
842 this._options.onBackreference(start, end, ref);
843 }
844 }
845 onCharacterClassEnter(start, negate, unicodeSets) {
846 if (this._options.onCharacterClassEnter) {
847 this._options.onCharacterClassEnter(start, negate, unicodeSets);
848 }
849 }
850 onCharacterClassLeave(start, end, negate) {
851 if (this._options.onCharacterClassLeave) {
852 this._options.onCharacterClassLeave(start, end, negate);
853 }
854 }
855 onCharacterClassRange(start, end, min, max) {
856 if (this._options.onCharacterClassRange) {
857 this._options.onCharacterClassRange(start, end, min, max);
858 }
859 }
860 onClassIntersection(start, end) {
861 if (this._options.onClassIntersection) {
862 this._options.onClassIntersection(start, end);
863 }
864 }
865 onClassSubtraction(start, end) {
866 if (this._options.onClassSubtraction) {
867 this._options.onClassSubtraction(start, end);
868 }
869 }
870 onClassStringDisjunctionEnter(start) {
871 if (this._options.onClassStringDisjunctionEnter) {
872 this._options.onClassStringDisjunctionEnter(start);
873 }
874 }
875 onClassStringDisjunctionLeave(start, end) {
876 if (this._options.onClassStringDisjunctionLeave) {
877 this._options.onClassStringDisjunctionLeave(start, end);
878 }
879 }
880 onStringAlternativeEnter(start, index) {
881 if (this._options.onStringAlternativeEnter) {
882 this._options.onStringAlternativeEnter(start, index);
883 }
884 }
885 onStringAlternativeLeave(start, end, index) {
886 if (this._options.onStringAlternativeLeave) {
887 this._options.onStringAlternativeLeave(start, end, index);
888 }
889 }
890 get index() {
891 return this._reader.index;
892 }
893 get currentCodePoint() {
894 return this._reader.currentCodePoint;
895 }
896 get nextCodePoint() {
897 return this._reader.nextCodePoint;
898 }
899 get nextCodePoint2() {
900 return this._reader.nextCodePoint2;
901 }
902 get nextCodePoint3() {
903 return this._reader.nextCodePoint3;
904 }
905 reset(source, start, end) {
906 this._reader.reset(source, start, end, this._unicodeMode);
907 }
908 rewind(index) {
909 this._reader.rewind(index);
910 }
911 advance() {
912 this._reader.advance();
913 }
914 eat(cp) {
915 return this._reader.eat(cp);
916 }
917 eat2(cp1, cp2) {
918 return this._reader.eat2(cp1, cp2);
919 }
920 eat3(cp1, cp2, cp3) {
921 return this._reader.eat3(cp1, cp2, cp3);
922 }
923 raise(message, context) {
924 var _a, _b, _c;
925 throw newRegExpSyntaxError(this._srcCtx, {
926 unicode: (_a = context === null || context === void 0 ? void 0 : context.unicode) !== null && _a !== void 0 ? _a : (this._unicodeMode && !this._unicodeSetsMode),
927 unicodeSets: (_b = context === null || context === void 0 ? void 0 : context.unicodeSets) !== null && _b !== void 0 ? _b : this._unicodeSetsMode,
928 }, (_c = context === null || context === void 0 ? void 0 : context.index) !== null && _c !== void 0 ? _c : this.index, message);
929 }
930 eatRegExpBody() {
931 const start = this.index;
932 let inClass = false;
933 let escaped = false;
934 for (;;) {
935 const cp = this.currentCodePoint;
936 if (cp === -1 || isLineTerminator(cp)) {
937 const kind = inClass ? "character class" : "regular expression";
938 this.raise(`Unterminated ${kind}`);
939 }
940 if (escaped) {
941 escaped = false;
942 }
943 else if (cp === REVERSE_SOLIDUS) {
944 escaped = true;
945 }
946 else if (cp === LEFT_SQUARE_BRACKET) {
947 inClass = true;
948 }
949 else if (cp === RIGHT_SQUARE_BRACKET) {
950 inClass = false;
951 }
952 else if ((cp === SOLIDUS && !inClass) ||
953 (cp === ASTERISK && this.index === start)) {
954 break;
955 }
956 this.advance();
957 }
958 return this.index !== start;
959 }
960 consumePattern() {
961 const start = this.index;
962 this._numCapturingParens = this.countCapturingParens();
963 this._groupSpecifiers.clear();
964 this._backreferenceNames.clear();
965 this.onPatternEnter(start);
966 this.consumeDisjunction();
967 const cp = this.currentCodePoint;
968 if (this.currentCodePoint !== -1) {
969 if (cp === RIGHT_PARENTHESIS) {
970 this.raise("Unmatched ')'");
971 }
972 if (cp === REVERSE_SOLIDUS) {
973 this.raise("\\ at end of pattern");
974 }
975 if (cp === RIGHT_SQUARE_BRACKET || cp === RIGHT_CURLY_BRACKET) {
976 this.raise("Lone quantifier brackets");
977 }
978 const c = String.fromCodePoint(cp);
979 this.raise(`Unexpected character '${c}'`);
980 }
981 for (const name of this._backreferenceNames) {
982 if (!this._groupSpecifiers.hasInPattern(name)) {
983 this.raise("Invalid named capture referenced");
984 }
985 }
986 this.onPatternLeave(start, this.index);
987 }
988 countCapturingParens() {
989 const start = this.index;
990 let inClass = false;
991 let escaped = false;
992 let count = 0;
993 let cp = 0;
994 while ((cp = this.currentCodePoint) !== -1) {
995 if (escaped) {
996 escaped = false;
997 }
998 else if (cp === REVERSE_SOLIDUS) {
999 escaped = true;
1000 }
1001 else if (cp === LEFT_SQUARE_BRACKET) {
1002 inClass = true;
1003 }
1004 else if (cp === RIGHT_SQUARE_BRACKET) {
1005 inClass = false;
1006 }
1007 else if (cp === LEFT_PARENTHESIS &&
1008 !inClass &&
1009 (this.nextCodePoint !== QUESTION_MARK ||
1010 (this.nextCodePoint2 === LESS_THAN_SIGN &&
1011 this.nextCodePoint3 !== EQUALS_SIGN &&
1012 this.nextCodePoint3 !== EXCLAMATION_MARK))) {
1013 count += 1;
1014 }
1015 this.advance();
1016 }
1017 this.rewind(start);
1018 return count;
1019 }
1020 consumeDisjunction() {
1021 const start = this.index;
1022 let i = 0;
1023 this._groupSpecifiers.enterDisjunction();
1024 this.onDisjunctionEnter(start);
1025 do {
1026 this.consumeAlternative(i++);
1027 } while (this.eat(VERTICAL_LINE));
1028 if (this.consumeQuantifier(true)) {
1029 this.raise("Nothing to repeat");
1030 }
1031 if (this.eat(LEFT_CURLY_BRACKET)) {
1032 this.raise("Lone quantifier brackets");
1033 }
1034 this.onDisjunctionLeave(start, this.index);
1035 this._groupSpecifiers.leaveDisjunction();
1036 }
1037 consumeAlternative(i) {
1038 const start = this.index;
1039 this._groupSpecifiers.enterAlternative(i);
1040 this.onAlternativeEnter(start, i);
1041 while (this.currentCodePoint !== -1 && this.consumeTerm()) {
1042 }
1043 this.onAlternativeLeave(start, this.index, i);
1044 }
1045 consumeTerm() {
1046 if (this._unicodeMode || this.strict) {
1047 return (this.consumeAssertion() ||
1048 (this.consumeAtom() && this.consumeOptionalQuantifier()));
1049 }
1050 return ((this.consumeAssertion() &&
1051 (!this._lastAssertionIsQuantifiable ||
1052 this.consumeOptionalQuantifier())) ||
1053 (this.consumeExtendedAtom() && this.consumeOptionalQuantifier()));
1054 }
1055 consumeOptionalQuantifier() {
1056 this.consumeQuantifier();
1057 return true;
1058 }
1059 consumeAssertion() {
1060 const start = this.index;
1061 this._lastAssertionIsQuantifiable = false;
1062 if (this.eat(CIRCUMFLEX_ACCENT)) {
1063 this.onEdgeAssertion(start, this.index, "start");
1064 return true;
1065 }
1066 if (this.eat(DOLLAR_SIGN)) {
1067 this.onEdgeAssertion(start, this.index, "end");
1068 return true;
1069 }
1070 if (this.eat2(REVERSE_SOLIDUS, LATIN_CAPITAL_LETTER_B)) {
1071 this.onWordBoundaryAssertion(start, this.index, "word", true);
1072 return true;
1073 }
1074 if (this.eat2(REVERSE_SOLIDUS, LATIN_SMALL_LETTER_B)) {
1075 this.onWordBoundaryAssertion(start, this.index, "word", false);
1076 return true;
1077 }
1078 if (this.eat2(LEFT_PARENTHESIS, QUESTION_MARK)) {
1079 const lookbehind = this.ecmaVersion >= 2018 && this.eat(LESS_THAN_SIGN);
1080 let negate = false;
1081 if (this.eat(EQUALS_SIGN) ||
1082 (negate = this.eat(EXCLAMATION_MARK))) {
1083 const kind = lookbehind ? "lookbehind" : "lookahead";
1084 this.onLookaroundAssertionEnter(start, kind, negate);
1085 this.consumeDisjunction();
1086 if (!this.eat(RIGHT_PARENTHESIS)) {
1087 this.raise("Unterminated group");
1088 }
1089 this._lastAssertionIsQuantifiable = !lookbehind && !this.strict;
1090 this.onLookaroundAssertionLeave(start, this.index, kind, negate);
1091 return true;
1092 }
1093 this.rewind(start);
1094 }
1095 return false;
1096 }
1097 consumeQuantifier(noConsume = false) {
1098 const start = this.index;
1099 let min = 0;
1100 let max = 0;
1101 let greedy = false;
1102 if (this.eat(ASTERISK)) {
1103 min = 0;
1104 max = Number.POSITIVE_INFINITY;
1105 }
1106 else if (this.eat(PLUS_SIGN)) {
1107 min = 1;
1108 max = Number.POSITIVE_INFINITY;
1109 }
1110 else if (this.eat(QUESTION_MARK)) {
1111 min = 0;
1112 max = 1;
1113 }
1114 else if (this.eatBracedQuantifier(noConsume)) {
1115 ({ min, max } = this._lastRange);
1116 }
1117 else {
1118 return false;
1119 }
1120 greedy = !this.eat(QUESTION_MARK);
1121 if (!noConsume) {
1122 this.onQuantifier(start, this.index, min, max, greedy);
1123 }
1124 return true;
1125 }
1126 eatBracedQuantifier(noError) {
1127 const start = this.index;
1128 if (this.eat(LEFT_CURLY_BRACKET)) {
1129 if (this.eatDecimalDigits()) {
1130 const min = this._lastIntValue;
1131 let max = min;
1132 if (this.eat(COMMA)) {
1133 max = this.eatDecimalDigits()
1134 ? this._lastIntValue
1135 : Number.POSITIVE_INFINITY;
1136 }
1137 if (this.eat(RIGHT_CURLY_BRACKET)) {
1138 if (!noError && max < min) {
1139 this.raise("numbers out of order in {} quantifier");
1140 }
1141 this._lastRange = { min, max };
1142 return true;
1143 }
1144 }
1145 if (!noError && (this._unicodeMode || this.strict)) {
1146 this.raise("Incomplete quantifier");
1147 }
1148 this.rewind(start);
1149 }
1150 return false;
1151 }
1152 consumeAtom() {
1153 return (this.consumePatternCharacter() ||
1154 this.consumeDot() ||
1155 this.consumeReverseSolidusAtomEscape() ||
1156 Boolean(this.consumeCharacterClass()) ||
1157 this.consumeCapturingGroup() ||
1158 this.consumeUncapturingGroup());
1159 }
1160 consumeDot() {
1161 if (this.eat(FULL_STOP)) {
1162 this.onAnyCharacterSet(this.index - 1, this.index, "any");
1163 return true;
1164 }
1165 return false;
1166 }
1167 consumeReverseSolidusAtomEscape() {
1168 const start = this.index;
1169 if (this.eat(REVERSE_SOLIDUS)) {
1170 if (this.consumeAtomEscape()) {
1171 return true;
1172 }
1173 this.rewind(start);
1174 }
1175 return false;
1176 }
1177 consumeUncapturingGroup() {
1178 const start = this.index;
1179 if (this.eat2(LEFT_PARENTHESIS, QUESTION_MARK)) {
1180 this.onGroupEnter(start);
1181 if (this.ecmaVersion >= 2025) {
1182 this.consumeModifiers();
1183 }
1184 if (!this.eat(COLON)) {
1185 this.rewind(start + 1);
1186 this.raise("Invalid group");
1187 }
1188 this.consumeDisjunction();
1189 if (!this.eat(RIGHT_PARENTHESIS)) {
1190 this.raise("Unterminated group");
1191 }
1192 this.onGroupLeave(start, this.index);
1193 return true;
1194 }
1195 return false;
1196 }
1197 consumeModifiers() {
1198 const start = this.index;
1199 const hasAddModifiers = this.eatModifiers();
1200 const addModifiersEnd = this.index;
1201 const hasHyphen = this.eat(HYPHEN_MINUS);
1202 if (!hasAddModifiers && !hasHyphen) {
1203 return false;
1204 }
1205 this.onModifiersEnter(start);
1206 const addModifiers = this.parseModifiers(start, addModifiersEnd);
1207 this.onAddModifiers(start, addModifiersEnd, addModifiers);
1208 if (hasHyphen) {
1209 const modifiersStart = this.index;
1210 if (!this.eatModifiers() &&
1211 !hasAddModifiers &&
1212 this.currentCodePoint === COLON) {
1213 this.raise("Invalid empty flags");
1214 }
1215 const modifiers = this.parseModifiers(modifiersStart, this.index);
1216 for (const [flagName] of Object.entries(modifiers).filter(([, enable]) => enable)) {
1217 if (addModifiers[flagName]) {
1218 this.raise(`Duplicated flag '${String.fromCodePoint(FLAG_PROP_TO_CODEPOINT[flagName])}'`);
1219 }
1220 }
1221 this.onRemoveModifiers(modifiersStart, this.index, modifiers);
1222 }
1223 this.onModifiersLeave(start, this.index);
1224 return true;
1225 }
1226 consumeCapturingGroup() {
1227 const start = this.index;
1228 if (this.eat(LEFT_PARENTHESIS)) {
1229 let name = null;
1230 if (this.ecmaVersion >= 2018) {
1231 if (this.consumeGroupSpecifier()) {
1232 name = this._lastStrValue;
1233 }
1234 else if (this.currentCodePoint === QUESTION_MARK) {
1235 this.rewind(start);
1236 return false;
1237 }
1238 }
1239 else if (this.currentCodePoint === QUESTION_MARK) {
1240 this.rewind(start);
1241 return false;
1242 }
1243 this.onCapturingGroupEnter(start, name);
1244 this.consumeDisjunction();
1245 if (!this.eat(RIGHT_PARENTHESIS)) {
1246 this.raise("Unterminated group");
1247 }
1248 this.onCapturingGroupLeave(start, this.index, name);
1249 return true;
1250 }
1251 return false;
1252 }
1253 consumeExtendedAtom() {
1254 return (this.consumeDot() ||
1255 this.consumeReverseSolidusAtomEscape() ||
1256 this.consumeReverseSolidusFollowedByC() ||
1257 Boolean(this.consumeCharacterClass()) ||
1258 this.consumeCapturingGroup() ||
1259 this.consumeUncapturingGroup() ||
1260 this.consumeInvalidBracedQuantifier() ||
1261 this.consumeExtendedPatternCharacter());
1262 }
1263 consumeReverseSolidusFollowedByC() {
1264 const start = this.index;
1265 if (this.currentCodePoint === REVERSE_SOLIDUS &&
1266 this.nextCodePoint === LATIN_SMALL_LETTER_C) {
1267 this._lastIntValue = this.currentCodePoint;
1268 this.advance();
1269 this.onCharacter(start, this.index, REVERSE_SOLIDUS);
1270 return true;
1271 }
1272 return false;
1273 }
1274 consumeInvalidBracedQuantifier() {
1275 if (this.eatBracedQuantifier(true)) {
1276 this.raise("Nothing to repeat");
1277 }
1278 return false;
1279 }
1280 consumePatternCharacter() {
1281 const start = this.index;
1282 const cp = this.currentCodePoint;
1283 if (cp !== -1 && !isSyntaxCharacter(cp)) {
1284 this.advance();
1285 this.onCharacter(start, this.index, cp);
1286 return true;
1287 }
1288 return false;
1289 }
1290 consumeExtendedPatternCharacter() {
1291 const start = this.index;
1292 const cp = this.currentCodePoint;
1293 if (cp !== -1 &&
1294 cp !== CIRCUMFLEX_ACCENT &&
1295 cp !== DOLLAR_SIGN &&
1296 cp !== REVERSE_SOLIDUS &&
1297 cp !== FULL_STOP &&
1298 cp !== ASTERISK &&
1299 cp !== PLUS_SIGN &&
1300 cp !== QUESTION_MARK &&
1301 cp !== LEFT_PARENTHESIS &&
1302 cp !== RIGHT_PARENTHESIS &&
1303 cp !== LEFT_SQUARE_BRACKET &&
1304 cp !== VERTICAL_LINE) {
1305 this.advance();
1306 this.onCharacter(start, this.index, cp);
1307 return true;
1308 }
1309 return false;
1310 }
1311 consumeGroupSpecifier() {
1312 const start = this.index;
1313 if (this.eat(QUESTION_MARK)) {
1314 if (this.eatGroupName()) {
1315 if (!this._groupSpecifiers.hasInScope(this._lastStrValue)) {
1316 this._groupSpecifiers.addToScope(this._lastStrValue);
1317 return true;
1318 }
1319 this.raise("Duplicate capture group name");
1320 }
1321 this.rewind(start);
1322 }
1323 return false;
1324 }
1325 consumeAtomEscape() {
1326 if (this.consumeBackreference() ||
1327 this.consumeCharacterClassEscape() ||
1328 this.consumeCharacterEscape() ||
1329 (this._nFlag && this.consumeKGroupName())) {
1330 return true;
1331 }
1332 if (this.strict || this._unicodeMode) {
1333 this.raise("Invalid escape");
1334 }
1335 return false;
1336 }
1337 consumeBackreference() {
1338 const start = this.index;
1339 if (this.eatDecimalEscape()) {
1340 const n = this._lastIntValue;
1341 if (n <= this._numCapturingParens) {
1342 this.onBackreference(start - 1, this.index, n);
1343 return true;
1344 }
1345 if (this.strict || this._unicodeMode) {
1346 this.raise("Invalid escape");
1347 }
1348 this.rewind(start);
1349 }
1350 return false;
1351 }
1352 consumeCharacterClassEscape() {
1353 var _a;
1354 const start = this.index;
1355 if (this.eat(LATIN_SMALL_LETTER_D)) {
1356 this._lastIntValue = -1;
1357 this.onEscapeCharacterSet(start - 1, this.index, "digit", false);
1358 return {};
1359 }
1360 if (this.eat(LATIN_CAPITAL_LETTER_D)) {
1361 this._lastIntValue = -1;
1362 this.onEscapeCharacterSet(start - 1, this.index, "digit", true);
1363 return {};
1364 }
1365 if (this.eat(LATIN_SMALL_LETTER_S)) {
1366 this._lastIntValue = -1;
1367 this.onEscapeCharacterSet(start - 1, this.index, "space", false);
1368 return {};
1369 }
1370 if (this.eat(LATIN_CAPITAL_LETTER_S)) {
1371 this._lastIntValue = -1;
1372 this.onEscapeCharacterSet(start - 1, this.index, "space", true);
1373 return {};
1374 }
1375 if (this.eat(LATIN_SMALL_LETTER_W)) {
1376 this._lastIntValue = -1;
1377 this.onEscapeCharacterSet(start - 1, this.index, "word", false);
1378 return {};
1379 }
1380 if (this.eat(LATIN_CAPITAL_LETTER_W)) {
1381 this._lastIntValue = -1;
1382 this.onEscapeCharacterSet(start - 1, this.index, "word", true);
1383 return {};
1384 }
1385 let negate = false;
1386 if (this._unicodeMode &&
1387 this.ecmaVersion >= 2018 &&
1388 (this.eat(LATIN_SMALL_LETTER_P) ||
1389 (negate = this.eat(LATIN_CAPITAL_LETTER_P)))) {
1390 this._lastIntValue = -1;
1391 let result = null;
1392 if (this.eat(LEFT_CURLY_BRACKET) &&
1393 (result = this.eatUnicodePropertyValueExpression()) &&
1394 this.eat(RIGHT_CURLY_BRACKET)) {
1395 if (negate && result.strings) {
1396 this.raise("Invalid property name");
1397 }
1398 this.onUnicodePropertyCharacterSet(start - 1, this.index, "property", result.key, result.value, negate, (_a = result.strings) !== null && _a !== void 0 ? _a : false);
1399 return { mayContainStrings: result.strings };
1400 }
1401 this.raise("Invalid property name");
1402 }
1403 return null;
1404 }
1405 consumeCharacterEscape() {
1406 const start = this.index;
1407 if (this.eatControlEscape() ||
1408 this.eatCControlLetter() ||
1409 this.eatZero() ||
1410 this.eatHexEscapeSequence() ||
1411 this.eatRegExpUnicodeEscapeSequence() ||
1412 (!this.strict &&
1413 !this._unicodeMode &&
1414 this.eatLegacyOctalEscapeSequence()) ||
1415 this.eatIdentityEscape()) {
1416 this.onCharacter(start - 1, this.index, this._lastIntValue);
1417 return true;
1418 }
1419 return false;
1420 }
1421 consumeKGroupName() {
1422 const start = this.index;
1423 if (this.eat(LATIN_SMALL_LETTER_K)) {
1424 if (this.eatGroupName()) {
1425 const groupName = this._lastStrValue;
1426 this._backreferenceNames.add(groupName);
1427 this.onBackreference(start - 1, this.index, groupName);
1428 return true;
1429 }
1430 this.raise("Invalid named reference");
1431 }
1432 return false;
1433 }
1434 consumeCharacterClass() {
1435 const start = this.index;
1436 if (this.eat(LEFT_SQUARE_BRACKET)) {
1437 const negate = this.eat(CIRCUMFLEX_ACCENT);
1438 this.onCharacterClassEnter(start, negate, this._unicodeSetsMode);
1439 const result = this.consumeClassContents();
1440 if (!this.eat(RIGHT_SQUARE_BRACKET)) {
1441 if (this.currentCodePoint === -1) {
1442 this.raise("Unterminated character class");
1443 }
1444 this.raise("Invalid character in character class");
1445 }
1446 if (negate && result.mayContainStrings) {
1447 this.raise("Negated character class may contain strings");
1448 }
1449 this.onCharacterClassLeave(start, this.index, negate);
1450 return result;
1451 }
1452 return null;
1453 }
1454 consumeClassContents() {
1455 if (this._unicodeSetsMode) {
1456 if (this.currentCodePoint === RIGHT_SQUARE_BRACKET) {
1457 return {};
1458 }
1459 const result = this.consumeClassSetExpression();
1460 return result;
1461 }
1462 const strict = this.strict || this._unicodeMode;
1463 for (;;) {
1464 const rangeStart = this.index;
1465 if (!this.consumeClassAtom()) {
1466 break;
1467 }
1468 const min = this._lastIntValue;
1469 if (!this.eat(HYPHEN_MINUS)) {
1470 continue;
1471 }
1472 this.onCharacter(this.index - 1, this.index, HYPHEN_MINUS);
1473 if (!this.consumeClassAtom()) {
1474 break;
1475 }
1476 const max = this._lastIntValue;
1477 if (min === -1 || max === -1) {
1478 if (strict) {
1479 this.raise("Invalid character class");
1480 }
1481 continue;
1482 }
1483 if (min > max) {
1484 this.raise("Range out of order in character class");
1485 }
1486 this.onCharacterClassRange(rangeStart, this.index, min, max);
1487 }
1488 return {};
1489 }
1490 consumeClassAtom() {
1491 const start = this.index;
1492 const cp = this.currentCodePoint;
1493 if (cp !== -1 &&
1494 cp !== REVERSE_SOLIDUS &&
1495 cp !== RIGHT_SQUARE_BRACKET) {
1496 this.advance();
1497 this._lastIntValue = cp;
1498 this.onCharacter(start, this.index, this._lastIntValue);
1499 return true;
1500 }
1501 if (this.eat(REVERSE_SOLIDUS)) {
1502 if (this.consumeClassEscape()) {
1503 return true;
1504 }
1505 if (!this.strict &&
1506 this.currentCodePoint === LATIN_SMALL_LETTER_C) {
1507 this._lastIntValue = REVERSE_SOLIDUS;
1508 this.onCharacter(start, this.index, this._lastIntValue);
1509 return true;
1510 }
1511 if (this.strict || this._unicodeMode) {
1512 this.raise("Invalid escape");
1513 }
1514 this.rewind(start);
1515 }
1516 return false;
1517 }
1518 consumeClassEscape() {
1519 const start = this.index;
1520 if (this.eat(LATIN_SMALL_LETTER_B)) {
1521 this._lastIntValue = BACKSPACE;
1522 this.onCharacter(start - 1, this.index, this._lastIntValue);
1523 return true;
1524 }
1525 if (this._unicodeMode && this.eat(HYPHEN_MINUS)) {
1526 this._lastIntValue = HYPHEN_MINUS;
1527 this.onCharacter(start - 1, this.index, this._lastIntValue);
1528 return true;
1529 }
1530 let cp = 0;
1531 if (!this.strict &&
1532 !this._unicodeMode &&
1533 this.currentCodePoint === LATIN_SMALL_LETTER_C &&
1534 (isDecimalDigit((cp = this.nextCodePoint)) || cp === LOW_LINE)) {
1535 this.advance();
1536 this.advance();
1537 this._lastIntValue = cp % 0x20;
1538 this.onCharacter(start - 1, this.index, this._lastIntValue);
1539 return true;
1540 }
1541 return (Boolean(this.consumeCharacterClassEscape()) ||
1542 this.consumeCharacterEscape());
1543 }
1544 consumeClassSetExpression() {
1545 const start = this.index;
1546 let mayContainStrings = false;
1547 let result = null;
1548 if (this.consumeClassSetCharacter()) {
1549 if (this.consumeClassSetRangeFromOperator(start)) {
1550 this.consumeClassUnionRight({});
1551 return {};
1552 }
1553 mayContainStrings = false;
1554 }
1555 else if ((result = this.consumeClassSetOperand())) {
1556 mayContainStrings = result.mayContainStrings;
1557 }
1558 else {
1559 const cp = this.currentCodePoint;
1560 if (cp === REVERSE_SOLIDUS) {
1561 this.advance();
1562 this.raise("Invalid escape");
1563 }
1564 if (cp === this.nextCodePoint &&
1565 isClassSetReservedDoublePunctuatorCharacter(cp)) {
1566 this.raise("Invalid set operation in character class");
1567 }
1568 this.raise("Invalid character in character class");
1569 }
1570 if (this.eat2(AMPERSAND, AMPERSAND)) {
1571 while (this.currentCodePoint !== AMPERSAND &&
1572 (result = this.consumeClassSetOperand())) {
1573 this.onClassIntersection(start, this.index);
1574 if (!result.mayContainStrings) {
1575 mayContainStrings = false;
1576 }
1577 if (this.eat2(AMPERSAND, AMPERSAND)) {
1578 continue;
1579 }
1580 return { mayContainStrings };
1581 }
1582 this.raise("Invalid character in character class");
1583 }
1584 if (this.eat2(HYPHEN_MINUS, HYPHEN_MINUS)) {
1585 while (this.consumeClassSetOperand()) {
1586 this.onClassSubtraction(start, this.index);
1587 if (this.eat2(HYPHEN_MINUS, HYPHEN_MINUS)) {
1588 continue;
1589 }
1590 return { mayContainStrings };
1591 }
1592 this.raise("Invalid character in character class");
1593 }
1594 return this.consumeClassUnionRight({ mayContainStrings });
1595 }
1596 consumeClassUnionRight(leftResult) {
1597 let mayContainStrings = leftResult.mayContainStrings;
1598 for (;;) {
1599 const start = this.index;
1600 if (this.consumeClassSetCharacter()) {
1601 this.consumeClassSetRangeFromOperator(start);
1602 continue;
1603 }
1604 const result = this.consumeClassSetOperand();
1605 if (result) {
1606 if (result.mayContainStrings) {
1607 mayContainStrings = true;
1608 }
1609 continue;
1610 }
1611 break;
1612 }
1613 return { mayContainStrings };
1614 }
1615 consumeClassSetRangeFromOperator(start) {
1616 const currentStart = this.index;
1617 const min = this._lastIntValue;
1618 if (this.eat(HYPHEN_MINUS)) {
1619 if (this.consumeClassSetCharacter()) {
1620 const max = this._lastIntValue;
1621 if (min === -1 || max === -1) {
1622 this.raise("Invalid character class");
1623 }
1624 if (min > max) {
1625 this.raise("Range out of order in character class");
1626 }
1627 this.onCharacterClassRange(start, this.index, min, max);
1628 return true;
1629 }
1630 this.rewind(currentStart);
1631 }
1632 return false;
1633 }
1634 consumeClassSetOperand() {
1635 let result = null;
1636 if ((result = this.consumeNestedClass())) {
1637 return result;
1638 }
1639 if ((result = this.consumeClassStringDisjunction())) {
1640 return result;
1641 }
1642 if (this.consumeClassSetCharacter()) {
1643 return {};
1644 }
1645 return null;
1646 }
1647 consumeNestedClass() {
1648 const start = this.index;
1649 if (this.eat(LEFT_SQUARE_BRACKET)) {
1650 const negate = this.eat(CIRCUMFLEX_ACCENT);
1651 this.onCharacterClassEnter(start, negate, true);
1652 const result = this.consumeClassContents();
1653 if (!this.eat(RIGHT_SQUARE_BRACKET)) {
1654 this.raise("Unterminated character class");
1655 }
1656 if (negate && result.mayContainStrings) {
1657 this.raise("Negated character class may contain strings");
1658 }
1659 this.onCharacterClassLeave(start, this.index, negate);
1660 return result;
1661 }
1662 if (this.eat(REVERSE_SOLIDUS)) {
1663 const result = this.consumeCharacterClassEscape();
1664 if (result) {
1665 return result;
1666 }
1667 this.rewind(start);
1668 }
1669 return null;
1670 }
1671 consumeClassStringDisjunction() {
1672 const start = this.index;
1673 if (this.eat3(REVERSE_SOLIDUS, LATIN_SMALL_LETTER_Q, LEFT_CURLY_BRACKET)) {
1674 this.onClassStringDisjunctionEnter(start);
1675 let i = 0;
1676 let mayContainStrings = false;
1677 do {
1678 if (this.consumeClassString(i++).mayContainStrings) {
1679 mayContainStrings = true;
1680 }
1681 } while (this.eat(VERTICAL_LINE));
1682 if (this.eat(RIGHT_CURLY_BRACKET)) {
1683 this.onClassStringDisjunctionLeave(start, this.index);
1684 return { mayContainStrings };
1685 }
1686 this.raise("Unterminated class string disjunction");
1687 }
1688 return null;
1689 }
1690 consumeClassString(i) {
1691 const start = this.index;
1692 let count = 0;
1693 this.onStringAlternativeEnter(start, i);
1694 while (this.currentCodePoint !== -1 &&
1695 this.consumeClassSetCharacter()) {
1696 count++;
1697 }
1698 this.onStringAlternativeLeave(start, this.index, i);
1699 return { mayContainStrings: count !== 1 };
1700 }
1701 consumeClassSetCharacter() {
1702 const start = this.index;
1703 const cp = this.currentCodePoint;
1704 if (cp !== this.nextCodePoint ||
1705 !isClassSetReservedDoublePunctuatorCharacter(cp)) {
1706 if (cp !== -1 && !isClassSetSyntaxCharacter(cp)) {
1707 this._lastIntValue = cp;
1708 this.advance();
1709 this.onCharacter(start, this.index, this._lastIntValue);
1710 return true;
1711 }
1712 }
1713 if (this.eat(REVERSE_SOLIDUS)) {
1714 if (this.consumeCharacterEscape()) {
1715 return true;
1716 }
1717 if (isClassSetReservedPunctuator(this.currentCodePoint)) {
1718 this._lastIntValue = this.currentCodePoint;
1719 this.advance();
1720 this.onCharacter(start, this.index, this._lastIntValue);
1721 return true;
1722 }
1723 if (this.eat(LATIN_SMALL_LETTER_B)) {
1724 this._lastIntValue = BACKSPACE;
1725 this.onCharacter(start, this.index, this._lastIntValue);
1726 return true;
1727 }
1728 this.rewind(start);
1729 }
1730 return false;
1731 }
1732 eatGroupName() {
1733 if (this.eat(LESS_THAN_SIGN)) {
1734 if (this.eatRegExpIdentifierName() && this.eat(GREATER_THAN_SIGN)) {
1735 return true;
1736 }
1737 this.raise("Invalid capture group name");
1738 }
1739 return false;
1740 }
1741 eatRegExpIdentifierName() {
1742 if (this.eatRegExpIdentifierStart()) {
1743 this._lastStrValue = String.fromCodePoint(this._lastIntValue);
1744 while (this.eatRegExpIdentifierPart()) {
1745 this._lastStrValue += String.fromCodePoint(this._lastIntValue);
1746 }
1747 return true;
1748 }
1749 return false;
1750 }
1751 eatRegExpIdentifierStart() {
1752 const start = this.index;
1753 const forceUFlag = !this._unicodeMode && this.ecmaVersion >= 2020;
1754 let cp = this.currentCodePoint;
1755 this.advance();
1756 if (cp === REVERSE_SOLIDUS &&
1757 this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
1758 cp = this._lastIntValue;
1759 }
1760 else if (forceUFlag &&
1761 isLeadSurrogate(cp) &&
1762 isTrailSurrogate(this.currentCodePoint)) {
1763 cp = combineSurrogatePair(cp, this.currentCodePoint);
1764 this.advance();
1765 }
1766 if (isIdentifierStartChar(cp)) {
1767 this._lastIntValue = cp;
1768 return true;
1769 }
1770 if (this.index !== start) {
1771 this.rewind(start);
1772 }
1773 return false;
1774 }
1775 eatRegExpIdentifierPart() {
1776 const start = this.index;
1777 const forceUFlag = !this._unicodeMode && this.ecmaVersion >= 2020;
1778 let cp = this.currentCodePoint;
1779 this.advance();
1780 if (cp === REVERSE_SOLIDUS &&
1781 this.eatRegExpUnicodeEscapeSequence(forceUFlag)) {
1782 cp = this._lastIntValue;
1783 }
1784 else if (forceUFlag &&
1785 isLeadSurrogate(cp) &&
1786 isTrailSurrogate(this.currentCodePoint)) {
1787 cp = combineSurrogatePair(cp, this.currentCodePoint);
1788 this.advance();
1789 }
1790 if (isIdentifierPartChar(cp)) {
1791 this._lastIntValue = cp;
1792 return true;
1793 }
1794 if (this.index !== start) {
1795 this.rewind(start);
1796 }
1797 return false;
1798 }
1799 eatCControlLetter() {
1800 const start = this.index;
1801 if (this.eat(LATIN_SMALL_LETTER_C)) {
1802 if (this.eatControlLetter()) {
1803 return true;
1804 }
1805 this.rewind(start);
1806 }
1807 return false;
1808 }
1809 eatZero() {
1810 if (this.currentCodePoint === DIGIT_ZERO &&
1811 !isDecimalDigit(this.nextCodePoint)) {
1812 this._lastIntValue = 0;
1813 this.advance();
1814 return true;
1815 }
1816 return false;
1817 }
1818 eatControlEscape() {
1819 if (this.eat(LATIN_SMALL_LETTER_F)) {
1820 this._lastIntValue = FORM_FEED;
1821 return true;
1822 }
1823 if (this.eat(LATIN_SMALL_LETTER_N)) {
1824 this._lastIntValue = LINE_FEED;
1825 return true;
1826 }
1827 if (this.eat(LATIN_SMALL_LETTER_R)) {
1828 this._lastIntValue = CARRIAGE_RETURN;
1829 return true;
1830 }
1831 if (this.eat(LATIN_SMALL_LETTER_T)) {
1832 this._lastIntValue = CHARACTER_TABULATION;
1833 return true;
1834 }
1835 if (this.eat(LATIN_SMALL_LETTER_V)) {
1836 this._lastIntValue = LINE_TABULATION;
1837 return true;
1838 }
1839 return false;
1840 }
1841 eatControlLetter() {
1842 const cp = this.currentCodePoint;
1843 if (isLatinLetter(cp)) {
1844 this.advance();
1845 this._lastIntValue = cp % 0x20;
1846 return true;
1847 }
1848 return false;
1849 }
1850 eatRegExpUnicodeEscapeSequence(forceUFlag = false) {
1851 const start = this.index;
1852 const uFlag = forceUFlag || this._unicodeMode;
1853 if (this.eat(LATIN_SMALL_LETTER_U)) {
1854 if ((uFlag && this.eatRegExpUnicodeSurrogatePairEscape()) ||
1855 this.eatFixedHexDigits(4) ||
1856 (uFlag && this.eatRegExpUnicodeCodePointEscape())) {
1857 return true;
1858 }
1859 if (this.strict || uFlag) {
1860 this.raise("Invalid unicode escape");
1861 }
1862 this.rewind(start);
1863 }
1864 return false;
1865 }
1866 eatRegExpUnicodeSurrogatePairEscape() {
1867 const start = this.index;
1868 if (this.eatFixedHexDigits(4)) {
1869 const lead = this._lastIntValue;
1870 if (isLeadSurrogate(lead) &&
1871 this.eat(REVERSE_SOLIDUS) &&
1872 this.eat(LATIN_SMALL_LETTER_U) &&
1873 this.eatFixedHexDigits(4)) {
1874 const trail = this._lastIntValue;
1875 if (isTrailSurrogate(trail)) {
1876 this._lastIntValue = combineSurrogatePair(lead, trail);
1877 return true;
1878 }
1879 }
1880 this.rewind(start);
1881 }
1882 return false;
1883 }
1884 eatRegExpUnicodeCodePointEscape() {
1885 const start = this.index;
1886 if (this.eat(LEFT_CURLY_BRACKET) &&
1887 this.eatHexDigits() &&
1888 this.eat(RIGHT_CURLY_BRACKET) &&
1889 isValidUnicode(this._lastIntValue)) {
1890 return true;
1891 }
1892 this.rewind(start);
1893 return false;
1894 }
1895 eatIdentityEscape() {
1896 const cp = this.currentCodePoint;
1897 if (this.isValidIdentityEscape(cp)) {
1898 this._lastIntValue = cp;
1899 this.advance();
1900 return true;
1901 }
1902 return false;
1903 }
1904 isValidIdentityEscape(cp) {
1905 if (cp === -1) {
1906 return false;
1907 }
1908 if (this._unicodeMode) {
1909 return isSyntaxCharacter(cp) || cp === SOLIDUS;
1910 }
1911 if (this.strict) {
1912 return !isIdContinue(cp);
1913 }
1914 if (this._nFlag) {
1915 return !(cp === LATIN_SMALL_LETTER_C || cp === LATIN_SMALL_LETTER_K);
1916 }
1917 return cp !== LATIN_SMALL_LETTER_C;
1918 }
1919 eatDecimalEscape() {
1920 this._lastIntValue = 0;
1921 let cp = this.currentCodePoint;
1922 if (cp >= DIGIT_ONE && cp <= DIGIT_NINE) {
1923 do {
1924 this._lastIntValue = 10 * this._lastIntValue + (cp - DIGIT_ZERO);
1925 this.advance();
1926 } while ((cp = this.currentCodePoint) >= DIGIT_ZERO &&
1927 cp <= DIGIT_NINE);
1928 return true;
1929 }
1930 return false;
1931 }
1932 eatUnicodePropertyValueExpression() {
1933 const start = this.index;
1934 if (this.eatUnicodePropertyName() && this.eat(EQUALS_SIGN)) {
1935 const key = this._lastStrValue;
1936 if (this.eatUnicodePropertyValue()) {
1937 const value = this._lastStrValue;
1938 if (isValidUnicodeProperty(this.ecmaVersion, key, value)) {
1939 return {
1940 key,
1941 value: value || null,
1942 };
1943 }
1944 this.raise("Invalid property name");
1945 }
1946 }
1947 this.rewind(start);
1948 if (this.eatLoneUnicodePropertyNameOrValue()) {
1949 const nameOrValue = this._lastStrValue;
1950 if (isValidUnicodeProperty(this.ecmaVersion, "General_Category", nameOrValue)) {
1951 return {
1952 key: "General_Category",
1953 value: nameOrValue || null,
1954 };
1955 }
1956 if (isValidLoneUnicodeProperty(this.ecmaVersion, nameOrValue)) {
1957 return {
1958 key: nameOrValue,
1959 value: null,
1960 };
1961 }
1962 if (this._unicodeSetsMode &&
1963 isValidLoneUnicodePropertyOfString(this.ecmaVersion, nameOrValue)) {
1964 return {
1965 key: nameOrValue,
1966 value: null,
1967 strings: true,
1968 };
1969 }
1970 this.raise("Invalid property name");
1971 }
1972 return null;
1973 }
1974 eatUnicodePropertyName() {
1975 this._lastStrValue = "";
1976 while (isUnicodePropertyNameCharacter(this.currentCodePoint)) {
1977 this._lastStrValue += String.fromCodePoint(this.currentCodePoint);
1978 this.advance();
1979 }
1980 return this._lastStrValue !== "";
1981 }
1982 eatUnicodePropertyValue() {
1983 this._lastStrValue = "";
1984 while (isUnicodePropertyValueCharacter(this.currentCodePoint)) {
1985 this._lastStrValue += String.fromCodePoint(this.currentCodePoint);
1986 this.advance();
1987 }
1988 return this._lastStrValue !== "";
1989 }
1990 eatLoneUnicodePropertyNameOrValue() {
1991 return this.eatUnicodePropertyValue();
1992 }
1993 eatHexEscapeSequence() {
1994 const start = this.index;
1995 if (this.eat(LATIN_SMALL_LETTER_X)) {
1996 if (this.eatFixedHexDigits(2)) {
1997 return true;
1998 }
1999 if (this._unicodeMode || this.strict) {
2000 this.raise("Invalid escape");
2001 }
2002 this.rewind(start);
2003 }
2004 return false;
2005 }
2006 eatDecimalDigits() {
2007 const start = this.index;
2008 this._lastIntValue = 0;
2009 while (isDecimalDigit(this.currentCodePoint)) {
2010 this._lastIntValue =
2011 10 * this._lastIntValue + digitToInt(this.currentCodePoint);
2012 this.advance();
2013 }
2014 return this.index !== start;
2015 }
2016 eatHexDigits() {
2017 const start = this.index;
2018 this._lastIntValue = 0;
2019 while (isHexDigit(this.currentCodePoint)) {
2020 this._lastIntValue =
2021 16 * this._lastIntValue + digitToInt(this.currentCodePoint);
2022 this.advance();
2023 }
2024 return this.index !== start;
2025 }
2026 eatLegacyOctalEscapeSequence() {
2027 if (this.eatOctalDigit()) {
2028 const n1 = this._lastIntValue;
2029 if (this.eatOctalDigit()) {
2030 const n2 = this._lastIntValue;
2031 if (n1 <= 3 && this.eatOctalDigit()) {
2032 this._lastIntValue = n1 * 64 + n2 * 8 + this._lastIntValue;
2033 }
2034 else {
2035 this._lastIntValue = n1 * 8 + n2;
2036 }
2037 }
2038 else {
2039 this._lastIntValue = n1;
2040 }
2041 return true;
2042 }
2043 return false;
2044 }
2045 eatOctalDigit() {
2046 const cp = this.currentCodePoint;
2047 if (isOctalDigit(cp)) {
2048 this.advance();
2049 this._lastIntValue = cp - DIGIT_ZERO;
2050 return true;
2051 }
2052 this._lastIntValue = 0;
2053 return false;
2054 }
2055 eatFixedHexDigits(length) {
2056 const start = this.index;
2057 this._lastIntValue = 0;
2058 for (let i = 0; i < length; ++i) {
2059 const cp = this.currentCodePoint;
2060 if (!isHexDigit(cp)) {
2061 this.rewind(start);
2062 return false;
2063 }
2064 this._lastIntValue = 16 * this._lastIntValue + digitToInt(cp);
2065 this.advance();
2066 }
2067 return true;
2068 }
2069 eatModifiers() {
2070 let ate = false;
2071 while (isRegularExpressionModifier(this.currentCodePoint)) {
2072 this.advance();
2073 ate = true;
2074 }
2075 return ate;
2076 }
2077 parseModifiers(start, end) {
2078 const { ignoreCase, multiline, dotAll } = this.parseFlags(this._reader.source, start, end);
2079 return { ignoreCase, multiline, dotAll };
2080 }
2081 parseFlags(source, start, end) {
2082 const flags = {
2083 global: false,
2084 ignoreCase: false,
2085 multiline: false,
2086 unicode: false,
2087 sticky: false,
2088 dotAll: false,
2089 hasIndices: false,
2090 unicodeSets: false,
2091 };
2092 const validFlags = new Set();
2093 validFlags.add(LATIN_SMALL_LETTER_G);
2094 validFlags.add(LATIN_SMALL_LETTER_I);
2095 validFlags.add(LATIN_SMALL_LETTER_M);
2096 if (this.ecmaVersion >= 2015) {
2097 validFlags.add(LATIN_SMALL_LETTER_U);
2098 validFlags.add(LATIN_SMALL_LETTER_Y);
2099 if (this.ecmaVersion >= 2018) {
2100 validFlags.add(LATIN_SMALL_LETTER_S);
2101 if (this.ecmaVersion >= 2022) {
2102 validFlags.add(LATIN_SMALL_LETTER_D);
2103 if (this.ecmaVersion >= 2024) {
2104 validFlags.add(LATIN_SMALL_LETTER_V);
2105 }
2106 }
2107 }
2108 }
2109 for (let i = start; i < end; ++i) {
2110 const flag = source.charCodeAt(i);
2111 if (validFlags.has(flag)) {
2112 const prop = FLAG_CODEPOINT_TO_PROP[flag];
2113 if (flags[prop]) {
2114 this.raise(`Duplicated flag '${source[i]}'`, {
2115 index: start,
2116 });
2117 }
2118 flags[prop] = true;
2119 }
2120 else {
2121 this.raise(`Invalid flag '${source[i]}'`, { index: start });
2122 }
2123 }
2124 return flags;
2125 }
2126}
2127
2128const DUMMY_PATTERN = {};
2129const DUMMY_FLAGS = {};
2130const DUMMY_CAPTURING_GROUP = {};
2131function isClassSetOperand(node) {
2132 return (node.type === "Character" ||
2133 node.type === "CharacterSet" ||
2134 node.type === "CharacterClass" ||
2135 node.type === "ExpressionCharacterClass" ||
2136 node.type === "ClassStringDisjunction");
2137}
2138class RegExpParserState {
2139 constructor(options) {
2140 var _a;
2141 this._node = DUMMY_PATTERN;
2142 this._expressionBufferMap = new Map();
2143 this._flags = DUMMY_FLAGS;
2144 this._backreferences = [];
2145 this._capturingGroups = [];
2146 this.source = "";
2147 this.strict = Boolean(options === null || options === void 0 ? void 0 : options.strict);
2148 this.ecmaVersion = (_a = options === null || options === void 0 ? void 0 : options.ecmaVersion) !== null && _a !== void 0 ? _a : latestEcmaVersion;
2149 }
2150 get pattern() {
2151 if (this._node.type !== "Pattern") {
2152 throw new Error("UnknownError");
2153 }
2154 return this._node;
2155 }
2156 get flags() {
2157 if (this._flags.type !== "Flags") {
2158 throw new Error("UnknownError");
2159 }
2160 return this._flags;
2161 }
2162 onRegExpFlags(start, end, { global, ignoreCase, multiline, unicode, sticky, dotAll, hasIndices, unicodeSets, }) {
2163 this._flags = {
2164 type: "Flags",
2165 parent: null,
2166 start,
2167 end,
2168 raw: this.source.slice(start, end),
2169 global,
2170 ignoreCase,
2171 multiline,
2172 unicode,
2173 sticky,
2174 dotAll,
2175 hasIndices,
2176 unicodeSets,
2177 };
2178 }
2179 onPatternEnter(start) {
2180 this._node = {
2181 type: "Pattern",
2182 parent: null,
2183 start,
2184 end: start,
2185 raw: "",
2186 alternatives: [],
2187 };
2188 this._backreferences.length = 0;
2189 this._capturingGroups.length = 0;
2190 }
2191 onPatternLeave(start, end) {
2192 this._node.end = end;
2193 this._node.raw = this.source.slice(start, end);
2194 for (const reference of this._backreferences) {
2195 const ref = reference.ref;
2196 const groups = typeof ref === "number"
2197 ? [this._capturingGroups[ref - 1]]
2198 : this._capturingGroups.filter((g) => g.name === ref);
2199 if (groups.length === 1) {
2200 const group = groups[0];
2201 reference.ambiguous = false;
2202 reference.resolved = group;
2203 }
2204 else {
2205 reference.ambiguous = true;
2206 reference.resolved = groups;
2207 }
2208 for (const group of groups) {
2209 group.references.push(reference);
2210 }
2211 }
2212 }
2213 onAlternativeEnter(start) {
2214 const parent = this._node;
2215 if (parent.type !== "Assertion" &&
2216 parent.type !== "CapturingGroup" &&
2217 parent.type !== "Group" &&
2218 parent.type !== "Pattern") {
2219 throw new Error("UnknownError");
2220 }
2221 this._node = {
2222 type: "Alternative",
2223 parent,
2224 start,
2225 end: start,
2226 raw: "",
2227 elements: [],
2228 };
2229 parent.alternatives.push(this._node);
2230 }
2231 onAlternativeLeave(start, end) {
2232 const node = this._node;
2233 if (node.type !== "Alternative") {
2234 throw new Error("UnknownError");
2235 }
2236 node.end = end;
2237 node.raw = this.source.slice(start, end);
2238 this._node = node.parent;
2239 }
2240 onGroupEnter(start) {
2241 const parent = this._node;
2242 if (parent.type !== "Alternative") {
2243 throw new Error("UnknownError");
2244 }
2245 const group = {
2246 type: "Group",
2247 parent,
2248 start,
2249 end: start,
2250 raw: "",
2251 modifiers: null,
2252 alternatives: [],
2253 };
2254 this._node = group;
2255 parent.elements.push(this._node);
2256 }
2257 onGroupLeave(start, end) {
2258 const node = this._node;
2259 if (node.type !== "Group" || node.parent.type !== "Alternative") {
2260 throw new Error("UnknownError");
2261 }
2262 node.end = end;
2263 node.raw = this.source.slice(start, end);
2264 this._node = node.parent;
2265 }
2266 onModifiersEnter(start) {
2267 const parent = this._node;
2268 if (parent.type !== "Group") {
2269 throw new Error("UnknownError");
2270 }
2271 this._node = {
2272 type: "Modifiers",
2273 parent,
2274 start,
2275 end: start,
2276 raw: "",
2277 add: null,
2278 remove: null,
2279 };
2280 parent.modifiers = this._node;
2281 }
2282 onModifiersLeave(start, end) {
2283 const node = this._node;
2284 if (node.type !== "Modifiers" || node.parent.type !== "Group") {
2285 throw new Error("UnknownError");
2286 }
2287 node.end = end;
2288 node.raw = this.source.slice(start, end);
2289 this._node = node.parent;
2290 }
2291 onAddModifiers(start, end, { ignoreCase, multiline, dotAll, }) {
2292 const parent = this._node;
2293 if (parent.type !== "Modifiers") {
2294 throw new Error("UnknownError");
2295 }
2296 parent.add = {
2297 type: "ModifierFlags",
2298 parent,
2299 start,
2300 end,
2301 raw: this.source.slice(start, end),
2302 ignoreCase,
2303 multiline,
2304 dotAll,
2305 };
2306 }
2307 onRemoveModifiers(start, end, { ignoreCase, multiline, dotAll, }) {
2308 const parent = this._node;
2309 if (parent.type !== "Modifiers") {
2310 throw new Error("UnknownError");
2311 }
2312 parent.remove = {
2313 type: "ModifierFlags",
2314 parent,
2315 start,
2316 end,
2317 raw: this.source.slice(start, end),
2318 ignoreCase,
2319 multiline,
2320 dotAll,
2321 };
2322 }
2323 onCapturingGroupEnter(start, name) {
2324 const parent = this._node;
2325 if (parent.type !== "Alternative") {
2326 throw new Error("UnknownError");
2327 }
2328 this._node = {
2329 type: "CapturingGroup",
2330 parent,
2331 start,
2332 end: start,
2333 raw: "",
2334 name,
2335 alternatives: [],
2336 references: [],
2337 };
2338 parent.elements.push(this._node);
2339 this._capturingGroups.push(this._node);
2340 }
2341 onCapturingGroupLeave(start, end) {
2342 const node = this._node;
2343 if (node.type !== "CapturingGroup" ||
2344 node.parent.type !== "Alternative") {
2345 throw new Error("UnknownError");
2346 }
2347 node.end = end;
2348 node.raw = this.source.slice(start, end);
2349 this._node = node.parent;
2350 }
2351 onQuantifier(start, end, min, max, greedy) {
2352 const parent = this._node;
2353 if (parent.type !== "Alternative") {
2354 throw new Error("UnknownError");
2355 }
2356 const element = parent.elements.pop();
2357 if (element == null ||
2358 element.type === "Quantifier" ||
2359 (element.type === "Assertion" && element.kind !== "lookahead")) {
2360 throw new Error("UnknownError");
2361 }
2362 const node = {
2363 type: "Quantifier",
2364 parent,
2365 start: element.start,
2366 end,
2367 raw: this.source.slice(element.start, end),
2368 min,
2369 max,
2370 greedy,
2371 element,
2372 };
2373 parent.elements.push(node);
2374 element.parent = node;
2375 }
2376 onLookaroundAssertionEnter(start, kind, negate) {
2377 const parent = this._node;
2378 if (parent.type !== "Alternative") {
2379 throw new Error("UnknownError");
2380 }
2381 const node = (this._node = {
2382 type: "Assertion",
2383 parent,
2384 start,
2385 end: start,
2386 raw: "",
2387 kind,
2388 negate,
2389 alternatives: [],
2390 });
2391 parent.elements.push(node);
2392 }
2393 onLookaroundAssertionLeave(start, end) {
2394 const node = this._node;
2395 if (node.type !== "Assertion" || node.parent.type !== "Alternative") {
2396 throw new Error("UnknownError");
2397 }
2398 node.end = end;
2399 node.raw = this.source.slice(start, end);
2400 this._node = node.parent;
2401 }
2402 onEdgeAssertion(start, end, kind) {
2403 const parent = this._node;
2404 if (parent.type !== "Alternative") {
2405 throw new Error("UnknownError");
2406 }
2407 parent.elements.push({
2408 type: "Assertion",
2409 parent,
2410 start,
2411 end,
2412 raw: this.source.slice(start, end),
2413 kind,
2414 });
2415 }
2416 onWordBoundaryAssertion(start, end, kind, negate) {
2417 const parent = this._node;
2418 if (parent.type !== "Alternative") {
2419 throw new Error("UnknownError");
2420 }
2421 parent.elements.push({
2422 type: "Assertion",
2423 parent,
2424 start,
2425 end,
2426 raw: this.source.slice(start, end),
2427 kind,
2428 negate,
2429 });
2430 }
2431 onAnyCharacterSet(start, end, kind) {
2432 const parent = this._node;
2433 if (parent.type !== "Alternative") {
2434 throw new Error("UnknownError");
2435 }
2436 parent.elements.push({
2437 type: "CharacterSet",
2438 parent,
2439 start,
2440 end,
2441 raw: this.source.slice(start, end),
2442 kind,
2443 });
2444 }
2445 onEscapeCharacterSet(start, end, kind, negate) {
2446 const parent = this._node;
2447 if (parent.type !== "Alternative" && parent.type !== "CharacterClass") {
2448 throw new Error("UnknownError");
2449 }
2450 parent.elements.push({
2451 type: "CharacterSet",
2452 parent,
2453 start,
2454 end,
2455 raw: this.source.slice(start, end),
2456 kind,
2457 negate,
2458 });
2459 }
2460 onUnicodePropertyCharacterSet(start, end, kind, key, value, negate, strings) {
2461 const parent = this._node;
2462 if (parent.type !== "Alternative" && parent.type !== "CharacterClass") {
2463 throw new Error("UnknownError");
2464 }
2465 const base = {
2466 type: "CharacterSet",
2467 parent: null,
2468 start,
2469 end,
2470 raw: this.source.slice(start, end),
2471 kind,
2472 strings: null,
2473 key,
2474 };
2475 if (strings) {
2476 if ((parent.type === "CharacterClass" && !parent.unicodeSets) ||
2477 negate ||
2478 value !== null) {
2479 throw new Error("UnknownError");
2480 }
2481 parent.elements.push(Object.assign(Object.assign({}, base), { parent, strings, value, negate }));
2482 }
2483 else {
2484 parent.elements.push(Object.assign(Object.assign({}, base), { parent, strings, value, negate }));
2485 }
2486 }
2487 onCharacter(start, end, value) {
2488 const parent = this._node;
2489 if (parent.type !== "Alternative" &&
2490 parent.type !== "CharacterClass" &&
2491 parent.type !== "StringAlternative") {
2492 throw new Error("UnknownError");
2493 }
2494 parent.elements.push({
2495 type: "Character",
2496 parent,
2497 start,
2498 end,
2499 raw: this.source.slice(start, end),
2500 value,
2501 });
2502 }
2503 onBackreference(start, end, ref) {
2504 const parent = this._node;
2505 if (parent.type !== "Alternative") {
2506 throw new Error("UnknownError");
2507 }
2508 const node = {
2509 type: "Backreference",
2510 parent,
2511 start,
2512 end,
2513 raw: this.source.slice(start, end),
2514 ref,
2515 ambiguous: false,
2516 resolved: DUMMY_CAPTURING_GROUP,
2517 };
2518 parent.elements.push(node);
2519 this._backreferences.push(node);
2520 }
2521 onCharacterClassEnter(start, negate, unicodeSets) {
2522 const parent = this._node;
2523 const base = {
2524 type: "CharacterClass",
2525 parent,
2526 start,
2527 end: start,
2528 raw: "",
2529 unicodeSets,
2530 negate,
2531 elements: [],
2532 };
2533 if (parent.type === "Alternative") {
2534 const node = Object.assign(Object.assign({}, base), { parent });
2535 this._node = node;
2536 parent.elements.push(node);
2537 }
2538 else if (parent.type === "CharacterClass" &&
2539 parent.unicodeSets &&
2540 unicodeSets) {
2541 const node = Object.assign(Object.assign({}, base), { parent,
2542 unicodeSets });
2543 this._node = node;
2544 parent.elements.push(node);
2545 }
2546 else {
2547 throw new Error("UnknownError");
2548 }
2549 }
2550 onCharacterClassLeave(start, end) {
2551 const node = this._node;
2552 if (node.type !== "CharacterClass" ||
2553 (node.parent.type !== "Alternative" &&
2554 node.parent.type !== "CharacterClass")) {
2555 throw new Error("UnknownError");
2556 }
2557 const parent = node.parent;
2558 node.end = end;
2559 node.raw = this.source.slice(start, end);
2560 this._node = parent;
2561 const expression = this._expressionBufferMap.get(node);
2562 if (!expression) {
2563 return;
2564 }
2565 if (node.elements.length > 0) {
2566 throw new Error("UnknownError");
2567 }
2568 this._expressionBufferMap.delete(node);
2569 const newNode = {
2570 type: "ExpressionCharacterClass",
2571 parent,
2572 start: node.start,
2573 end: node.end,
2574 raw: node.raw,
2575 negate: node.negate,
2576 expression,
2577 };
2578 expression.parent = newNode;
2579 if (node !== parent.elements.pop()) {
2580 throw new Error("UnknownError");
2581 }
2582 parent.elements.push(newNode);
2583 }
2584 onCharacterClassRange(start, end) {
2585 const parent = this._node;
2586 if (parent.type !== "CharacterClass") {
2587 throw new Error("UnknownError");
2588 }
2589 const elements = parent.elements;
2590 const max = elements.pop();
2591 if (!max || max.type !== "Character") {
2592 throw new Error("UnknownError");
2593 }
2594 if (!parent.unicodeSets) {
2595 const hyphen = elements.pop();
2596 if (!hyphen ||
2597 hyphen.type !== "Character" ||
2598 hyphen.value !== HYPHEN_MINUS) {
2599 throw new Error("UnknownError");
2600 }
2601 }
2602 const min = elements.pop();
2603 if (!min || min.type !== "Character") {
2604 throw new Error("UnknownError");
2605 }
2606 const node = {
2607 type: "CharacterClassRange",
2608 parent,
2609 start,
2610 end,
2611 raw: this.source.slice(start, end),
2612 min,
2613 max,
2614 };
2615 min.parent = node;
2616 max.parent = node;
2617 elements.push(node);
2618 }
2619 onClassIntersection(start, end) {
2620 var _a;
2621 const parent = this._node;
2622 if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
2623 throw new Error("UnknownError");
2624 }
2625 const right = parent.elements.pop();
2626 const left = (_a = this._expressionBufferMap.get(parent)) !== null && _a !== void 0 ? _a : parent.elements.pop();
2627 if (!left ||
2628 !right ||
2629 left.type === "ClassSubtraction" ||
2630 (left.type !== "ClassIntersection" && !isClassSetOperand(left)) ||
2631 !isClassSetOperand(right)) {
2632 throw new Error("UnknownError");
2633 }
2634 const node = {
2635 type: "ClassIntersection",
2636 parent: parent,
2637 start,
2638 end,
2639 raw: this.source.slice(start, end),
2640 left,
2641 right,
2642 };
2643 left.parent = node;
2644 right.parent = node;
2645 this._expressionBufferMap.set(parent, node);
2646 }
2647 onClassSubtraction(start, end) {
2648 var _a;
2649 const parent = this._node;
2650 if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
2651 throw new Error("UnknownError");
2652 }
2653 const right = parent.elements.pop();
2654 const left = (_a = this._expressionBufferMap.get(parent)) !== null && _a !== void 0 ? _a : parent.elements.pop();
2655 if (!left ||
2656 !right ||
2657 left.type === "ClassIntersection" ||
2658 (left.type !== "ClassSubtraction" && !isClassSetOperand(left)) ||
2659 !isClassSetOperand(right)) {
2660 throw new Error("UnknownError");
2661 }
2662 const node = {
2663 type: "ClassSubtraction",
2664 parent: parent,
2665 start,
2666 end,
2667 raw: this.source.slice(start, end),
2668 left,
2669 right,
2670 };
2671 left.parent = node;
2672 right.parent = node;
2673 this._expressionBufferMap.set(parent, node);
2674 }
2675 onClassStringDisjunctionEnter(start) {
2676 const parent = this._node;
2677 if (parent.type !== "CharacterClass" || !parent.unicodeSets) {
2678 throw new Error("UnknownError");
2679 }
2680 this._node = {
2681 type: "ClassStringDisjunction",
2682 parent,
2683 start,
2684 end: start,
2685 raw: "",
2686 alternatives: [],
2687 };
2688 parent.elements.push(this._node);
2689 }
2690 onClassStringDisjunctionLeave(start, end) {
2691 const node = this._node;
2692 if (node.type !== "ClassStringDisjunction" ||
2693 node.parent.type !== "CharacterClass") {
2694 throw new Error("UnknownError");
2695 }
2696 node.end = end;
2697 node.raw = this.source.slice(start, end);
2698 this._node = node.parent;
2699 }
2700 onStringAlternativeEnter(start) {
2701 const parent = this._node;
2702 if (parent.type !== "ClassStringDisjunction") {
2703 throw new Error("UnknownError");
2704 }
2705 this._node = {
2706 type: "StringAlternative",
2707 parent,
2708 start,
2709 end: start,
2710 raw: "",
2711 elements: [],
2712 };
2713 parent.alternatives.push(this._node);
2714 }
2715 onStringAlternativeLeave(start, end) {
2716 const node = this._node;
2717 if (node.type !== "StringAlternative") {
2718 throw new Error("UnknownError");
2719 }
2720 node.end = end;
2721 node.raw = this.source.slice(start, end);
2722 this._node = node.parent;
2723 }
2724}
2725class RegExpParser {
2726 constructor(options) {
2727 this._state = new RegExpParserState(options);
2728 this._validator = new RegExpValidator(this._state);
2729 }
2730 parseLiteral(source, start = 0, end = source.length) {
2731 this._state.source = source;
2732 this._validator.validateLiteral(source, start, end);
2733 const pattern = this._state.pattern;
2734 const flags = this._state.flags;
2735 const literal = {
2736 type: "RegExpLiteral",
2737 parent: null,
2738 start,
2739 end,
2740 raw: source,
2741 pattern,
2742 flags,
2743 };
2744 pattern.parent = literal;
2745 flags.parent = literal;
2746 return literal;
2747 }
2748 parseFlags(source, start = 0, end = source.length) {
2749 this._state.source = source;
2750 this._validator.validateFlags(source, start, end);
2751 return this._state.flags;
2752 }
2753 parsePattern(source, start = 0, end = source.length, uFlagOrFlags = undefined) {
2754 this._state.source = source;
2755 this._validator.validatePattern(source, start, end, uFlagOrFlags);
2756 return this._state.pattern;
2757 }
2758}
2759
2760class RegExpVisitor {
2761 constructor(handlers) {
2762 this._handlers = handlers;
2763 }
2764 visit(node) {
2765 switch (node.type) {
2766 case "Alternative":
2767 this.visitAlternative(node);
2768 break;
2769 case "Assertion":
2770 this.visitAssertion(node);
2771 break;
2772 case "Backreference":
2773 this.visitBackreference(node);
2774 break;
2775 case "CapturingGroup":
2776 this.visitCapturingGroup(node);
2777 break;
2778 case "Character":
2779 this.visitCharacter(node);
2780 break;
2781 case "CharacterClass":
2782 this.visitCharacterClass(node);
2783 break;
2784 case "CharacterClassRange":
2785 this.visitCharacterClassRange(node);
2786 break;
2787 case "CharacterSet":
2788 this.visitCharacterSet(node);
2789 break;
2790 case "ClassIntersection":
2791 this.visitClassIntersection(node);
2792 break;
2793 case "ClassStringDisjunction":
2794 this.visitClassStringDisjunction(node);
2795 break;
2796 case "ClassSubtraction":
2797 this.visitClassSubtraction(node);
2798 break;
2799 case "ExpressionCharacterClass":
2800 this.visitExpressionCharacterClass(node);
2801 break;
2802 case "Flags":
2803 this.visitFlags(node);
2804 break;
2805 case "Group":
2806 this.visitGroup(node);
2807 break;
2808 case "Modifiers":
2809 this.visitModifiers(node);
2810 break;
2811 case "ModifierFlags":
2812 this.visitModifierFlags(node);
2813 break;
2814 case "Pattern":
2815 this.visitPattern(node);
2816 break;
2817 case "Quantifier":
2818 this.visitQuantifier(node);
2819 break;
2820 case "RegExpLiteral":
2821 this.visitRegExpLiteral(node);
2822 break;
2823 case "StringAlternative":
2824 this.visitStringAlternative(node);
2825 break;
2826 default:
2827 throw new Error(`Unknown type: ${node.type}`);
2828 }
2829 }
2830 visitAlternative(node) {
2831 if (this._handlers.onAlternativeEnter) {
2832 this._handlers.onAlternativeEnter(node);
2833 }
2834 node.elements.forEach(this.visit, this);
2835 if (this._handlers.onAlternativeLeave) {
2836 this._handlers.onAlternativeLeave(node);
2837 }
2838 }
2839 visitAssertion(node) {
2840 if (this._handlers.onAssertionEnter) {
2841 this._handlers.onAssertionEnter(node);
2842 }
2843 if (node.kind === "lookahead" || node.kind === "lookbehind") {
2844 node.alternatives.forEach(this.visit, this);
2845 }
2846 if (this._handlers.onAssertionLeave) {
2847 this._handlers.onAssertionLeave(node);
2848 }
2849 }
2850 visitBackreference(node) {
2851 if (this._handlers.onBackreferenceEnter) {
2852 this._handlers.onBackreferenceEnter(node);
2853 }
2854 if (this._handlers.onBackreferenceLeave) {
2855 this._handlers.onBackreferenceLeave(node);
2856 }
2857 }
2858 visitCapturingGroup(node) {
2859 if (this._handlers.onCapturingGroupEnter) {
2860 this._handlers.onCapturingGroupEnter(node);
2861 }
2862 node.alternatives.forEach(this.visit, this);
2863 if (this._handlers.onCapturingGroupLeave) {
2864 this._handlers.onCapturingGroupLeave(node);
2865 }
2866 }
2867 visitCharacter(node) {
2868 if (this._handlers.onCharacterEnter) {
2869 this._handlers.onCharacterEnter(node);
2870 }
2871 if (this._handlers.onCharacterLeave) {
2872 this._handlers.onCharacterLeave(node);
2873 }
2874 }
2875 visitCharacterClass(node) {
2876 if (this._handlers.onCharacterClassEnter) {
2877 this._handlers.onCharacterClassEnter(node);
2878 }
2879 node.elements.forEach(this.visit, this);
2880 if (this._handlers.onCharacterClassLeave) {
2881 this._handlers.onCharacterClassLeave(node);
2882 }
2883 }
2884 visitCharacterClassRange(node) {
2885 if (this._handlers.onCharacterClassRangeEnter) {
2886 this._handlers.onCharacterClassRangeEnter(node);
2887 }
2888 this.visitCharacter(node.min);
2889 this.visitCharacter(node.max);
2890 if (this._handlers.onCharacterClassRangeLeave) {
2891 this._handlers.onCharacterClassRangeLeave(node);
2892 }
2893 }
2894 visitCharacterSet(node) {
2895 if (this._handlers.onCharacterSetEnter) {
2896 this._handlers.onCharacterSetEnter(node);
2897 }
2898 if (this._handlers.onCharacterSetLeave) {
2899 this._handlers.onCharacterSetLeave(node);
2900 }
2901 }
2902 visitClassIntersection(node) {
2903 if (this._handlers.onClassIntersectionEnter) {
2904 this._handlers.onClassIntersectionEnter(node);
2905 }
2906 this.visit(node.left);
2907 this.visit(node.right);
2908 if (this._handlers.onClassIntersectionLeave) {
2909 this._handlers.onClassIntersectionLeave(node);
2910 }
2911 }
2912 visitClassStringDisjunction(node) {
2913 if (this._handlers.onClassStringDisjunctionEnter) {
2914 this._handlers.onClassStringDisjunctionEnter(node);
2915 }
2916 node.alternatives.forEach(this.visit, this);
2917 if (this._handlers.onClassStringDisjunctionLeave) {
2918 this._handlers.onClassStringDisjunctionLeave(node);
2919 }
2920 }
2921 visitClassSubtraction(node) {
2922 if (this._handlers.onClassSubtractionEnter) {
2923 this._handlers.onClassSubtractionEnter(node);
2924 }
2925 this.visit(node.left);
2926 this.visit(node.right);
2927 if (this._handlers.onClassSubtractionLeave) {
2928 this._handlers.onClassSubtractionLeave(node);
2929 }
2930 }
2931 visitExpressionCharacterClass(node) {
2932 if (this._handlers.onExpressionCharacterClassEnter) {
2933 this._handlers.onExpressionCharacterClassEnter(node);
2934 }
2935 this.visit(node.expression);
2936 if (this._handlers.onExpressionCharacterClassLeave) {
2937 this._handlers.onExpressionCharacterClassLeave(node);
2938 }
2939 }
2940 visitFlags(node) {
2941 if (this._handlers.onFlagsEnter) {
2942 this._handlers.onFlagsEnter(node);
2943 }
2944 if (this._handlers.onFlagsLeave) {
2945 this._handlers.onFlagsLeave(node);
2946 }
2947 }
2948 visitGroup(node) {
2949 if (this._handlers.onGroupEnter) {
2950 this._handlers.onGroupEnter(node);
2951 }
2952 if (node.modifiers) {
2953 this.visit(node.modifiers);
2954 }
2955 node.alternatives.forEach(this.visit, this);
2956 if (this._handlers.onGroupLeave) {
2957 this._handlers.onGroupLeave(node);
2958 }
2959 }
2960 visitModifiers(node) {
2961 if (this._handlers.onModifiersEnter) {
2962 this._handlers.onModifiersEnter(node);
2963 }
2964 if (node.add) {
2965 this.visit(node.add);
2966 }
2967 if (node.remove) {
2968 this.visit(node.remove);
2969 }
2970 if (this._handlers.onModifiersLeave) {
2971 this._handlers.onModifiersLeave(node);
2972 }
2973 }
2974 visitModifierFlags(node) {
2975 if (this._handlers.onModifierFlagsEnter) {
2976 this._handlers.onModifierFlagsEnter(node);
2977 }
2978 if (this._handlers.onModifierFlagsLeave) {
2979 this._handlers.onModifierFlagsLeave(node);
2980 }
2981 }
2982 visitPattern(node) {
2983 if (this._handlers.onPatternEnter) {
2984 this._handlers.onPatternEnter(node);
2985 }
2986 node.alternatives.forEach(this.visit, this);
2987 if (this._handlers.onPatternLeave) {
2988 this._handlers.onPatternLeave(node);
2989 }
2990 }
2991 visitQuantifier(node) {
2992 if (this._handlers.onQuantifierEnter) {
2993 this._handlers.onQuantifierEnter(node);
2994 }
2995 this.visit(node.element);
2996 if (this._handlers.onQuantifierLeave) {
2997 this._handlers.onQuantifierLeave(node);
2998 }
2999 }
3000 visitRegExpLiteral(node) {
3001 if (this._handlers.onRegExpLiteralEnter) {
3002 this._handlers.onRegExpLiteralEnter(node);
3003 }
3004 this.visitPattern(node.pattern);
3005 this.visitFlags(node.flags);
3006 if (this._handlers.onRegExpLiteralLeave) {
3007 this._handlers.onRegExpLiteralLeave(node);
3008 }
3009 }
3010 visitStringAlternative(node) {
3011 if (this._handlers.onStringAlternativeEnter) {
3012 this._handlers.onStringAlternativeEnter(node);
3013 }
3014 node.elements.forEach(this.visit, this);
3015 if (this._handlers.onStringAlternativeLeave) {
3016 this._handlers.onStringAlternativeLeave(node);
3017 }
3018 }
3019}
3020
3021function parseRegExpLiteral(source, options) {
3022 return new RegExpParser(options).parseLiteral(String(source));
3023}
3024function validateRegExpLiteral(source, options) {
3025 new RegExpValidator(options).validateLiteral(source);
3026}
3027function visitRegExpAST(node, handlers) {
3028 new RegExpVisitor(handlers).visit(node);
3029}
3030
3031export { ast as AST, RegExpParser, RegExpSyntaxError, RegExpValidator, parseRegExpLiteral, validateRegExpLiteral, visitRegExpAST };
3032//# sourceMappingURL=index.mjs.map
Note: See TracBrowser for help on using the repository browser.