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

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