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

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

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